From: Vincent Vanwaelscappel Date: Thu, 6 Jun 2019 14:31:07 +0000 (+0200) Subject: wip #2810 @12 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=2ad8a771281031958cd200cd6f89d6a43677a46b;p=pmi.git wip #2810 @12 --- diff --git a/app/Http/Controllers/Admin/CategoryCrudController.php b/app/Http/Controllers/Admin/CategoryCrudController.php index f75455e..526898b 100644 --- a/app/Http/Controllers/Admin/CategoryCrudController.php +++ b/app/Http/Controllers/Admin/CategoryCrudController.php @@ -7,8 +7,9 @@ use Cubist\Backpack\app\Magic\Controllers\CubistMagicNestedController; class CategoryCrudController extends CubistMagicNestedController { protected $_modelNamespace = 'App\Models\Category'; - protected $_routeURL = 'category'; + protected $_routeURL = 'catalog_category'; protected $_singular = 'category'; protected $_plural = 'categories'; protected $_clonable = true; + protected $_bulk = true; } diff --git a/app/Http/Controllers/Admin/ProductCrudController.php b/app/Http/Controllers/Admin/ProductCrudController.php index 4926416..32de144 100644 --- a/app/Http/Controllers/Admin/ProductCrudController.php +++ b/app/Http/Controllers/Admin/ProductCrudController.php @@ -11,4 +11,5 @@ class ProductCrudController extends CubistMagicController protected $_singular = 'product'; protected $_plural = 'products'; protected $_clonable = true; + protected $_bulk = true; } diff --git a/app/Http/Controllers/Admin/ProductTypeCrudController.php b/app/Http/Controllers/Admin/ProductTypeCrudController.php index 5cde01c..67e2e60 100644 --- a/app/Http/Controllers/Admin/ProductTypeCrudController.php +++ b/app/Http/Controllers/Admin/ProductTypeCrudController.php @@ -11,4 +11,5 @@ class ProductTypeCrudController extends CubistMagicController protected $_singular = 'product type'; protected $_plural = 'product types'; protected $_clonable = true; + protected $_bulk = true; } diff --git a/app/Http/Controllers/Admin/SpecificationCrudController.php b/app/Http/Controllers/Admin/SpecificationCrudController.php index 3711188..263bb59 100644 --- a/app/Http/Controllers/Admin/SpecificationCrudController.php +++ b/app/Http/Controllers/Admin/SpecificationCrudController.php @@ -11,4 +11,5 @@ class SpecificationCrudController extends CubistMagicController protected $_singular = 'specification'; protected $_plural = 'specifications'; protected $_clonable = true; + protected $_bulk = true; } diff --git a/app/Http/Kernel.php b/app/Http/Kernel.php index 8c36286..415c2d1 100644 --- a/app/Http/Kernel.php +++ b/app/Http/Kernel.php @@ -17,7 +17,7 @@ class Kernel extends HttpKernel \App\Http\Middleware\CheckForMaintenanceMode::class, \Illuminate\Foundation\Http\Middleware\ValidatePostSize::class, \App\Http\Middleware\TrimStrings::class, - //\Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class, + \Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class, \App\Http\Middleware\TrustProxies::class, \Spatie\MissingPageRedirector\RedirectsMissingPages::class, ]; diff --git a/app/Models/Category.php b/app/Models/Category.php index 372fe12..0622bf2 100644 --- a/app/Models/Category.php +++ b/app/Models/Category.php @@ -9,7 +9,8 @@ class Category extends CubistMagicNestedModel protected $table = 'catalog_categories'; protected $_options = ['name' => 'category', - 'plural' => 'categories']; + 'plural' => 'categories', + 'route'=>'catalog_category']; public function setFields() { diff --git a/app/Models/Product.php b/app/Models/Product.php index 4661e4e..80993f5 100644 --- a/app/Models/Product.php +++ b/app/Models/Product.php @@ -3,6 +3,7 @@ namespace App\Models; use Cubist\Backpack\app\Magic\Models\CubistMagicModel; +use Illuminate\Support\Str; class Product extends CubistMagicModel { @@ -18,67 +19,108 @@ 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']); } } diff --git a/app/Models/Producttype.php b/app/Models/Producttype.php index 499a3c5..830d24a 100644 --- a/app/Models/Producttype.php +++ b/app/Models/Producttype.php @@ -19,10 +19,29 @@ class ProductType extends CubistMagicModel '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'); + } } diff --git a/app/Models/Specification.php b/app/Models/Specification.php index 39be656..0ee9a22 100644 --- a/app/Models/Specification.php +++ b/app/Models/Specification.php @@ -33,6 +33,13 @@ class Specification extends CubistMagicModel 'entity_singular' => 'option', // used on the "Add X" button 'columns' => [ 'name' => 'Name', - ],]); + ], + ]); } + + public function product_type() + { + return $this->belongsToMany('App\Models\ProductType', 'rel_btm_catalog_specifications_catalog_product_types'); + } + } diff --git a/resources/views/vendor/backpack/base/inc/sidebar_content.blade.php b/resources/views/vendor/backpack/base/inc/sidebar_content.blade.php index 5fde756..bfd2a90 100644 --- a/resources/views/vendor/backpack/base/inc/sidebar_content.blade.php +++ b/resources/views/vendor/backpack/base/inc/sidebar_content.blade.php @@ -28,7 +28,7 @@
  • Product types
  • Specifications
  • -
  • Categories
  • +
  • Categories
  • @endcan @can('backpack_maintenance') diff --git a/routes/backpack/custom.php b/routes/backpack/custom.php index b9d58b5..d12a933 100644 --- a/routes/backpack/custom.php +++ b/routes/backpack/custom.php @@ -4,7 +4,7 @@ Route::group([ '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');