use App\Models\Product;
use App\Models\ProductType;
+use Cubist\Backpack\app\Magic\Menu\PageItem;
class Category extends Base
{
public function setData(&$data)
{
parent::setData($data);
- $cat=$data['page']->get('category');
+ $cat = $data['page']->get('category');
$productType = ProductType::find($cat);
$data['filters'] = $filters ? $filters['filters'] : []; // To be used by Vue component
$data['filter_results'] = $filters ? $filters['results'] : [];
}
+
+ public function setMenuChildren($menu)
+ {
+ $products = Product::whereVariant($menu->getVariant())->get();
+ $data = $menu->getPageData();
+ $cat = $data->get('category');
+ $filter = $menu->getPageData()->get('filter', '');
+ foreach ($products as $product) {
+ if ($product->product_type != $cat) {
+ continue;
+ }
+ if (!$product->online) {
+ continue;
+ }
+
+ $canonical = $href = $product->getSlugOrTitleAttribute();
+ if ($filter !== '') {
+ $href = $cat . '-' . $href;
+ }
+
+ $detail = new PageItem();
+ $detail->setLocale($menu->getLocale());
+ $detail->initFromEntity($product);
+ $detail->setTitle($product->name);
+ $detail->setCanonical($canonical);
+ $detail->setHref($href);
+ $detail->setId('product/' . $product->id);
+ $detail->setController(['controller' => 'ProductController', 'action' => 'productDetails', 'params' => ['id' => $product->id]]);
+ $detail->hideInAllMenus();
+ $menu->addChild($detail);
+ }
+ }
}
@endphp
<div data-product-id="{{$id}}" class="product-grid-item bg-grey-200">
{{-- Image holder --}}
- <a href="{{ $product->getEntity()->URL }}">
+ <a href="{{ $product->getEntity()->getURLAttribute() }}" class="">
<div class="product-img-holder">
<div class="product-img">
<img src="{{$product->getEntity()->image}}"
There shoulln't be any space between closing of a and opening of div
{{-- Product details --}}
--><div class="product-content p-4">
- <h3><a class="text-navy" href="{{ $product->getEntity()->URL }}">{{ $product->get('reference') }}</a>
+ <h3><a class="text-navy" href="{{ $product->getEntity()->getURLAttribute() }}">{{ $product->get('reference') }}</a>
</h3>
<div class="product-highlights text-sm">
{{$product->get('name')}}
@endif
<div class="links mt-4">
<div class="link">
- <a href="{{ $product->getEntity()->URL }}">
+ <a href="{{ $product->getEntity()->getURLAttribute() }}">
{{ __('En savoir plus') }}
</a>
</div>