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',
'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';
]);
-
parent::setFields();
}
}
$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;
continue;
}
$detail = new PageItem();
- $category->initFromEntity($product);
+ $detail->initFromEntity($product);
$detail->setTitle($product->name);
$detail->setHref($product->getSlugOrTitleAttribute());
$detail->setId('product/' . $product->id);