From 49d7c46d52ad81fd4e10a4cf4d49a9db3a926e8c Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Mon, 17 Jun 2019 14:38:46 +0200 Subject: [PATCH] wip #2840 @1 --- app/Models/Product.php | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/app/Models/Product.php b/app/Models/Product.php index af9da9b..5add13e 100644 --- a/app/Models/Product.php +++ b/app/Models/Product.php @@ -7,6 +7,9 @@ use Illuminate\Support\Str; class Product extends CubistMagicModel { + protected static $_specifications = null; + protected static $_productTypes = null; + protected $table = 'catalog_products'; protected $_options = ['name' => 'product', @@ -109,18 +112,33 @@ class Product extends CubistMagicModel 'type' => 'Markdown', 'tab' => 'Textes']); +// $this->addField(['name' => 'related', +// 'label' => 'Produits associés', +// 'type' => 'SelectFromModel', +// 'optionsmodel' => 'App\Models\Product', +// 'multiple' => true, +// 'tab'=>'Produits associés' +// ]); + + $this->addSpecifications(); } + protected static function _getRelatedEntities() + { + if (null === self::$_specifications) { + self::$_specifications = Specification::all(); + self::$_productTypes = ProductType::all(); + } + } public function addSpecifications() { - $specifications = Specification::all(); - $types = ProductType::all(); + self::_getRelatedEntities(); - foreach ($specifications as $spec) { + foreach (self::$_specifications as $spec) { $in = []; - foreach ($types as $type) { + foreach (self::$_productTypes as $type) { $lists = [$type->specifications, $type->filters]; foreach ($lists as $list) { if (!is_array($list)) { -- 2.39.5