]> _ Git - pmi.git/commitdiff
wip #2889 @3
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 16 Jul 2019 13:48:07 +0000 (15:48 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 16 Jul 2019 13:48:07 +0000 (15:48 +0200)
app/Models/Product.php
app/Templates/Catalog.php

index d8face926f11c69db803b5b0f03554abb5a5da94..14ae328f37456201189986df6054a553d0355be5 100644 (file)
@@ -12,6 +12,7 @@ class Product extends CubistMagicModel
 {
     protected static $_specifications = null;
     protected static $_productTypes = null;
+    protected static $_specificationFields = null;
 
     protected $table = 'catalog_products';
 
@@ -146,76 +147,80 @@ class Product extends CubistMagicModel
     {
         self::_getRelatedEntities();
 
-        foreach (self::$_specifications as $spec) {
-            $in = [];
-            foreach (self::$_productTypes as $type) {
-                $lists = [$type->specifications, $type->filters];
-                foreach ($lists as $list) {
-                    if (!is_array($list)) {
-                        continue;
-                    }
-                    foreach ($list as $order => $rel_specification) {
-                        if ($spec->id == $rel_specification) {
-                            if (!in_array($type->getIdValue(), $in)) {
-                                $in[] = ['id' => $type->getIdValue(), 'order' => $order];
+        if (null === self::$_specificationFields) {
+            foreach (self::$_specifications as $spec) {
+                $in = [];
+                foreach (self::$_productTypes as $type) {
+                    $lists = [$type->specifications, $type->filters];
+                    foreach ($lists as $list) {
+                        if (!is_array($list)) {
+                            continue;
+                        }
+                        foreach ($list as $order => $rel_specification) {
+                            if ($spec->id == $rel_specification) {
+                                if (!in_array($type->getIdValue(), $in)) {
+                                    $in[] = ['id' => $type->getIdValue(), 'order' => $order];
+                                }
+                                break;
                             }
-                            break;
                         }
                     }
                 }
-            }
-            if (!count($in)) {
-                continue;
-            }
-            $params = ['tab' => 'Spécifications',
-                'name' => 's_' . Str::snake($spec->name),
-                'label' => $spec->name,
-                'fake' => true,
-                'store_in' => 'specifications',
-                'when' => ['product_type' => $in],
-            ];
-
-            if ($spec->prefix) {
-                $params['prefix'] = $spec->prefix;
-            }
-            if ($spec->unit) {
-                $params['suffix'] = $spec->unit;
-            }
+                if (!count($in)) {
+                    continue;
+                }
+                $params = ['tab' => 'Spécifications',
+                    'name' => 's_' . Str::snake($spec->name),
+                    'label' => $spec->name,
+                    'fake' => true,
+                    'store_in' => 'specifications',
+                    'when' => ['product_type' => $in],
+                ];
+
+                if ($spec->prefix) {
+                    $params['prefix'] = $spec->prefix;
+                }
+                if ($spec->unit) {
+                    $params['suffix'] = $spec->unit;
+                }
 
-            if ($spec->type == 'numeric') {
-                $params['type'] = 'Number';
-            } else if ($spec->type == 'range') {
-                $params['type'] = 'Range';
-            } else if ($spec->type == 'text') {
-                $params['type'] = 'Text';
-            } else if ($spec->type == 'numeric_list') {
-                $params['type'] = 'Tags';
+                if ($spec->type == 'numeric') {
+                    $params['type'] = 'Number';
+                } else if ($spec->type == 'range') {
+                    $params['type'] = 'Range';
+                } else if ($spec->type == 'text') {
+                    $params['type'] = 'Text';
+                } else if ($spec->type == 'numeric_list') {
+                    $params['type'] = 'Tags';
 //                $params['entity_singular'] = 'valeur';
 //                $params['columns'] = ['value' => 'Value'];
-            } else {
-                $params['type'] = 'SelectFromArray';
-                $options = [];
-                if (is_string($spec->options)) {
-                    $decoded = [];
-                    if ($spec->options) {
-                        $decoded = json_decode($spec->options);
-                    }
                 } else {
-                    $decoded = $spec->options;
-                }
-                if (is_array($decoded)) {
-                    foreach ($decoded as $option) {
-                        if (isset($option->fr)) {
-                            $options[] = $option->fr;
+                    $params['type'] = 'SelectFromArray';
+                    $options = [];
+                    if (is_string($spec->options)) {
+                        $decoded = [];
+                        if ($spec->options) {
+                            $decoded = json_decode($spec->options);
                         }
+                    } else {
+                        $decoded = $spec->options;
                     }
+                    if (is_array($decoded)) {
+                        foreach ($decoded as $option) {
+                            if (isset($option->fr)) {
+                                $options[] = $option->fr;
+                            }
+                        }
 
+                    }
+                    $params['options'] = $options;
                 }
-                $params['options'] = $options;
+                self::$_specificationFields[] = $params;
             }
-            $this->addField($params);
         }
-
+        foreach (self::$_specificationFields as $specificationField) {
+            $this->addField($specificationField);
+        }
     }
 
     public function getDocuments()
index 9ea5bfd017cd1483434ed3f4bd42658e0650efc2..e83d88148ac0856efb8e05ab4e18c3eb0b743984 100644 (file)
@@ -20,12 +20,20 @@ class Catalog extends TemplateAbstract
 
     public function setMenuChildren($menu)
     {
+        \Barryvdh\Debugbar\Facade::startMeasure('nav_catalog', 'Make Products sub navigation');
         parent::setMenuChildren($menu);
 
         $families = ['captor' => __('Capteurs'), 'system' => __('Systèmes de mesure')];
 
+        \Barryvdh\Debugbar\Facade::startMeasure('nav_catalog_models', 'Request catalog models');
+        \Barryvdh\Debugbar\Facade::startMeasure('nav_catalog_models_types', 'Request catalog models (types)');
         $productTypes = ProductType::all();
+        \Barryvdh\Debugbar\Facade::stopMeasure('nav_catalog_models_types');
+        \Barryvdh\Debugbar\Facade::startMeasure('nav_catalog_models_products', 'Request catalog models (products)');
         $products = Product::all();
+        \Barryvdh\Debugbar\Facade::stopMeasure('nav_catalog_models_products');
+        \Barryvdh\Debugbar\Facade::stopMeasure('nav_catalog_models');
+
         $menu->setType('mega');
 
         foreach ($families as $key => $family) {
@@ -58,6 +66,7 @@ class Catalog extends TemplateAbstract
                 }
             }
         }
+        \Barryvdh\Debugbar\Facade::stopMeasure('nav_catalog');
     }
 
 }