]> _ Git - pmi.git/commitdiff
wip #2840 @1
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Mon, 17 Jun 2019 12:38:46 +0000 (14:38 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Mon, 17 Jun 2019 12:38:46 +0000 (14:38 +0200)
app/Models/Product.php

index af9da9bcccd2805068304c134bde3f28daf4ceea..5add13e73f3127c479b65b103fb004b82405057d 100644 (file)
@@ -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)) {