]> _ Git - pmi.git/commitdiff
wip #2810 @5
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 13 Jun 2019 16:43:41 +0000 (18:43 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 13 Jun 2019 16:43:41 +0000 (18:43 +0200)
app/Models/Product.php
app/Models/Producttype.php
app/Models/Specification.php
update

index 850cae8f10c2efd5723c791c45ad0be16245a8bb..034711bb2a6a931d5673bc5d3fa131ff867c15bd 100644 (file)
@@ -34,71 +34,11 @@ class Product extends CubistMagicModel
         $this->addField(['name' => 'product_type',
             'label' => 'Type de produit',
             'type' => 'SelectFromModel',
-            'model' => 'App\Models\ProductType',
+            'optionsmodel' => 'App\Models\ProductType',
             'column' => true,
             'tab' => 'Spécifications']);
 
-        $specifications = Specification::all();
-        $types = ProductType::all();
-        foreach ($specifications as $spec) {
-            $in = [];
-            foreach ($types as $type) {
-                foreach ($type->specifications as $rel_specification) {
-                    if ($spec->id == $rel_specification->id) {
-                        $in[] = $type->id;
-                        break;
-                    }
-                }
-                foreach ($type->filters as $rel_specification) {
-                    if ($spec->id == $rel_specification->id) {
-                        $in[] = $type->id;
-                        break;
-                    }
-                }
-                $in = array_unique($in);
-            }
-            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'] = 'Table';
-                $params['entity_singular'] = 'valeur';
-                $params['columns'] = ['value' => 'Value'];
-            } 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->addSpecifications();
 
         $this->addField(['name' => 'slug',
             'type' => 'Slug',
@@ -172,4 +112,75 @@ class Product extends CubistMagicModel
             'tab' => 'Textes']);
 
     }
+
+    public function addSpecifications()
+    {
+
+        $specifications = Specification::all();
+        $types = ProductType::all();
+        foreach ($specifications as $spec) {
+            $in = [];
+            foreach ($types as $type) {
+                $lists = [$type->specifications, $type->filters];
+                foreach ($lists as $list) {
+                    if (!is_array($list)) {
+                        continue;
+                    }
+                    foreach ($list as $rel_specification) {
+                        if ($spec->id == $rel_specification) {
+                            if (!in_array($type->getIdValue(), $in)) {
+                                $in[] = $type->getIdValue();
+                            }
+                            break;
+                        }
+                    }
+                }
+                $in = array_unique($in);
+            }
+            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'] = 'Table';
+                $params['entity_singular'] = 'valeur';
+                $params['columns'] = ['value' => 'Value'];
+            } else {
+                $params['type'] = 'SelectFromArray';
+                $options = [];
+                if (is_string($spec->options)) {
+                    $decoded = json_decode($spec->options);
+                }
+                if (is_array($decoded)) {
+                    foreach ($decoded as $option) {
+                        $options[] = $option->name;
+                    }
+
+                }
+                $params['options'] = $options;
+            }
+            $this->addField($params);
+        }
+
+    }
 }
index 5834b9f9af30650dc06c8f658dbb7d5371b4ff2e..4838b426cc9c360fbaeec5e893c240cb015cfc4b 100644 (file)
@@ -38,23 +38,17 @@ class ProductType extends CubistMagicModel
 
         $this->addField(['name' => 'specifications',
             'label' => 'Spécifications',
-            'type' => 'SelectFromModelMultiple',
-            'model' => "App\Models\Specification",
+            'type' => 'SelectFromModel',
+            'optionsmodel' => "App\Models\Specification",
+            'order' => true,
+            'multiple' => true,
         ]);
 
         $this->addField(['name' => 'filters',
             'label' => 'Spécifications utilisées comme filtre',
-            'type' => 'SelectFromModelMultiple',
-            'model' => 'App\Models\Specification']);
-    }
-
-    public function specifications()
-    {
-        return $this->relationship('specifications');
-    }
-
-    public function filters()
-    {
-        return $this->relationship('filters');
+            'type' => 'SelectFromModel',
+            'optionsmodel' => 'App\Models\Specification',
+            'order' => true,
+            'multiple' => true]);
     }
 }
index 95f3b35684bd7b5a853f187e7000927b23fab6b8..d1317f498bd2756eef2242893ff0117e18cc03ab 100644 (file)
@@ -36,7 +36,7 @@ class Specification extends CubistMagicModel
         $this->addField(['name' => 'options',
             'label' => 'Options',
             'type' => 'Table',
-            'entity_singular' => 'option', // used on the "Add X" button
+            'entity_singular' => 'option',
             'columns' => [
                 'name' => 'Name',
             ],
@@ -65,15 +65,4 @@ class Specification extends CubistMagicModel
             'column'=>true,
         ]);
     }
-
-    public function product_type_filters()
-    {
-        return $this->belongsToMany('App\Models\ProductType', 'catalog_product_types_filters_rel_btm');
-    }
-
-    public function product_type_specifications()
-    {
-        return $this->belongsToMany('App\Models\ProductType', 'catalog_product_types_specifications_rel_btm');
-    }
-
 }
diff --git a/update b/update
index 2f3550958adbd094fca120b2f6d4c581db1d252b..e20cbd6fe7703a35e3b2f6337cc74b98c045b337 100644 (file)
--- a/update
+++ b/update
@@ -3,7 +3,7 @@
 echo `composer update -v --no-progress --profile --prefer-dist`;
 #`php artisan vendor:publish --provider="CubistBackpackServiceProvider"`;
 // Database migrations
-`php artisan vendor:publish --tag=migrations`;
-`php artisan migrate`;
+//`php artisan vendor:publish --tag=migrations`;
+//`php artisan migrate`;
 #`composer dump-autoload`;
 `php artisan cubist:magic:generate`;