]> _ Git - pmi.git/commitdiff
wip #2967 @2
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 30 Aug 2019 14:44:50 +0000 (16:44 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 30 Aug 2019 14:44:50 +0000 (16:44 +0200)
app/Models/Producttype.php
app/Templates/Catalog.php

index b3917e0e6d1041cd4c0572fe174c0daa4c004e79..15c3c831260628f02bf559171c6afe57a403166b 100644 (file)
@@ -3,9 +3,15 @@
 namespace App\Models;
 
 use Cubist\Backpack\app\Magic\Models\CubistMagicPageModel;
+use Illuminate\Support\Str;
 
 class ProductType extends CubistMagicPageModel
 {
+    /**
+     * @var array
+     */
+    protected $_slugFields = ['slug', 'name'];
+
     protected $table = 'catalog_product_types';
 
     protected $_options = ['name' => 'product type',
@@ -14,6 +20,24 @@ class ProductType extends CubistMagicPageModel
         'plural' => 'types de produit'
     ];
 
+    public function getSlugOrTitleAttribute()
+    {
+        foreach ($this->_slugFields as $item) {
+            $components = explode('+', $item);
+
+            $slug = [];
+            foreach ($components as $component) {
+                if (isset($this->$component) && $this->$component != '') {
+                    $slug[] = $this->$component;
+                }
+            }
+            if (count($slug) > 0) {
+                $res = Str::slug(implode('-', $slug));
+                return $res;
+            }
+        }
+    }
+
     public function setFields()
     {
         $tab = 'Type de produit';
@@ -60,7 +84,6 @@ class ProductType extends CubistMagicPageModel
         ]);
 
 
-
         parent::setFields();
     }
 }
index 4cffafc7b8029ec08e1bddcecae22a2f07e4a3cf..66b34ff065f34a493fd21264cfd16220216db8e1 100644 (file)
@@ -51,7 +51,7 @@ class Catalog extends TemplateAbstract
                 $category->initFromEntity($productType);
                 $category->setTitle($productType->name);
                 $category->setHref($productType->getSlugOrTitleAttribute());
-                $category->setId('product_type_' . $productType->id);
+                $category->setId('product_type/' . $productType->id);
                 $category->setController(['controller' => 'ProductController', 'action' => 'productList', 'params' => ['id' => $productType->id]]);
 
                 $count = 0;
@@ -63,7 +63,7 @@ class Catalog extends TemplateAbstract
                         continue;
                     }
                     $detail = new PageItem();
-                    $category->initFromEntity($product);
+                    $detail->initFromEntity($product);
                     $detail->setTitle($product->name);
                     $detail->setHref($product->getSlugOrTitleAttribute());
                     $detail->setId('product/' . $product->id);