namespace App\Models;
use Cubist\Backpack\app\Magic\Models\CubistMagicModel;
+use Illuminate\Support\Str;
class Product extends CubistMagicModel
{
$this->addField(['name' => 'name',
'label' => 'Product name',
'type' => 'Text',
- 'column' => true]);
+ 'column' => true,
+ 'tab' => 'General']);
$this->addField(['name' => 'reference',
'label' => 'SKU',
'type' => 'Text',
'column' => true,
'unique' => true,
- 'translatable' => false]);
+ 'translatable' => false,
+ 'tab' => 'General']);
$this->addField(['name' => 'product_type',
'label' => 'Type de produit',
'type' => 'SelectFromModel',
- 'model' => 'App\Models\ProductType']);
+ 'model' => 'App\Models\ProductType',
+ 'column' => true,
+ 'tab' => 'General']);
+
+ $specifications = Specification::all();
+ foreach ($specifications as $spec) {
+ $params = ['tab' => 'Specifications',
+ 'name' => 's_' . Str::snake($spec->name),
+ 'label' => $spec->name,
+ 'fake' => true,
+ 'store_in' => 'specifications',
+ ];
+
+ if ($spec->type == 'numeric') {
+ $params['type'] = 'Number';
+ } else {
+ $params['type'] = 'SelectFromArray';
+ $options = [];
+ if (is_string($spec->options)) {
+ $decoded = json_decode($spec->options);
+ }
+ foreach ($decoded as $option) {
+ $options[] = $option->name;
+ }
+ $params['options'] = $options;
+ }
+ $this->addField($params);
+ }
+
$this->addField(['name' => 'slug',
'type' => 'Slug',
'label' => 'Slug',
- 'column' => true]);
+ 'column' => true,
+ 'tab' => 'General']);
$this->addField(['name' => 'online',
'type' => 'Checkbox',
'label' => 'Online',
- 'column' => true]);
+ 'column' => true,
+ 'tab' => 'General']);
$this->addField(['name' => 'public',
'type' => 'Checkbox',
'label' => 'Public',
- 'column' => true]);
+ 'column' => true,
+ 'tab' => 'General']);
$this->addField(['name' => 'supplier',
'label' => 'Supplier',
'type' => 'Text',
- 'translatable' => false]);
+ 'translatable' => false,
+ 'tab' => 'Supplier']);
$this->addField(['name' => 'supplier_reference',
'label' => 'Supplier reference',
'type' => 'Text',
- 'translatable' => false]);
+ 'translatable' => false,
+ 'tab' => 'Supplier']);
$this->addField(['name' => 'highlights',
'label' => 'Product highlights',
- 'type' => 'Markdown']);
+ 'type' => 'Markdown',
+ 'tab' => 'Texts']);
$this->addField(['name' => 'descriptions',
'label' => 'Description',
- 'type' => 'Markdown']);
+ 'type' => 'Markdown',
+ 'tab' => 'Texts']);
$this->addField(['name' => 'images',
'label' => 'Product pictures',
- 'type' => 'Images']);
+ 'type' => 'Images',
+ 'tab' => 'Media']);
$this->addField(['name' => 'dimensions',
'label' => 'Dimensions',
- 'type' => 'Markdown']);
+ 'type' => 'Markdown',
+ 'tab' => 'Texts']);
$this->addField(['name' => 'options',
'label' => 'Options',
- 'type' => 'Markdown']);
+ 'type' => 'Markdown',
+ 'tab' => 'Texts']);
$this->addField(['name' => 'accessories',
'label' => 'Accessories',
- 'type' => 'Markdown']);
+ 'type' => 'Markdown',
+ 'tab' => 'Texts']);
}
}
'type' => 'Text',
'column' => true]);
+ $this->addField(['name' => 'type',
+ 'label' => 'Product family',
+ 'type' => 'SelectFromArray',
+ 'options' => ['captor' => 'Captor', 'system' => 'System'],
+ 'column' => true,
+ ]
+ );
+
+ $this->addField(['name' => 'featured_on_home',
+ 'label' => 'Featured on homepage',
+ 'type' => 'Checkbox',
+ 'column' => true,
+ 'default' => 1]);
+
$this->addField(['name' => 'specifications',
'label' => 'Specifications',
'type' => 'SelectFromModelMultiple',
'model' => "App\Models\Specification",
]);
}
+
+ public function specifications()
+ {
+ return $this->relationship('specifications');
+ }
}
'middleware' => ['web', config('backpack.base.middleware_key', 'admin')],
'namespace' => 'App\Http\Controllers\Admin',
], function () { // custom admin routes
- CRUD::resource('category', 'CategoryCrudController');
+ CRUD::resource('catalog_category', 'CategoryCrudController');
CRUD::resource('product', 'ProductCrudController');
CRUD::resource('producttype', 'ProductTypeCrudController');
CRUD::resource('specification', 'SpecificationCrudController');