feat: implement import and export functionality for product categories and products
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exports;
|
||||
|
||||
use App\Models\ProductCategories;
|
||||
use Maatwebsite\Excel\Concerns\FromCollection;
|
||||
use Maatwebsite\Excel\Concerns\WithHeadings;
|
||||
use Maatwebsite\Excel\Concerns\WithMapping;
|
||||
|
||||
class ProductCategoriesExport implements FromCollection, WithHeadings, WithMapping
|
||||
{
|
||||
public function collection()
|
||||
{
|
||||
return ProductCategories::with('parent')->get();
|
||||
}
|
||||
|
||||
public function headings(): array
|
||||
{
|
||||
return [
|
||||
'ID',
|
||||
'Name',
|
||||
'Slug',
|
||||
'Parent Name',
|
||||
'Parent ID',
|
||||
'Type',
|
||||
'Is Active',
|
||||
'Sort Order',
|
||||
];
|
||||
}
|
||||
|
||||
public function map($category): array
|
||||
{
|
||||
return [
|
||||
$category->id,
|
||||
$category->name,
|
||||
$category->slug,
|
||||
$category->parent?->name,
|
||||
$category->parent_id,
|
||||
$category->type,
|
||||
$category->is_active ? 'Yes' : 'No',
|
||||
$category->sort_order,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exports;
|
||||
|
||||
use App\Models\Product;
|
||||
use Maatwebsite\Excel\Concerns\FromCollection;
|
||||
use Maatwebsite\Excel\Concerns\WithHeadings;
|
||||
use Maatwebsite\Excel\Concerns\WithMapping;
|
||||
|
||||
class ProductsExport implements FromCollection, WithHeadings, WithMapping
|
||||
{
|
||||
public function collection()
|
||||
{
|
||||
return Product::with('category', 'pricings')->get();
|
||||
}
|
||||
|
||||
public function headings(): array
|
||||
{
|
||||
return [
|
||||
'ID',
|
||||
'Name',
|
||||
'Slug',
|
||||
'Category',
|
||||
'Category ID',
|
||||
'Short Description',
|
||||
'Description',
|
||||
'Setup Fee',
|
||||
'Trial Days',
|
||||
'CPU',
|
||||
'RAM',
|
||||
'GPU',
|
||||
'Disk',
|
||||
'Bandwidth',
|
||||
'Stock',
|
||||
'Is Unlimited',
|
||||
'Is Active',
|
||||
'Sort Order',
|
||||
'Product Type',
|
||||
'Published At',
|
||||
'Monthly Price',
|
||||
'Sale Price',
|
||||
];
|
||||
}
|
||||
|
||||
public function map($product): array
|
||||
{
|
||||
return [
|
||||
$product->id,
|
||||
$product->name,
|
||||
$product->slug,
|
||||
$product->category?->name,
|
||||
$product->product_categories_id,
|
||||
$product->short_description,
|
||||
$product->description,
|
||||
$product->setup_fee,
|
||||
$product->trial_days,
|
||||
$product->cpu,
|
||||
$product->ram,
|
||||
$product->gpu,
|
||||
$product->disk,
|
||||
$product->bandwidth,
|
||||
$product->stock,
|
||||
$product->is_unlimited ? 'Yes' : 'No',
|
||||
$product->is_active ? 'Yes' : 'No',
|
||||
$product->sort_order,
|
||||
$product->product_type,
|
||||
$product->published_at?->format('Y-m-d'),
|
||||
$product->pricings->where('billing_cycle', 'monthly')->where('is_active', 1)->first()?->price ?? '',
|
||||
$product->pricings->where('billing_cycle', 'monthly')->where('is_active', 1)->first()?->price_sale ?? '',
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user