namespace App\Templates;
+use App\Models\Product;
use App\Models\ProductType;
class Category extends Base
'label' => 'Filtres',
'tab' => 'Catégorie']);
}
+
+ public function setData(&$data)
+ {
+ parent::setData($data);
+ $cat=$data['page']->get('category');
+
+ $productType = ProductType::find($cat);
+
+ if (!$productType) {
+ $this->_404();
+ }
+ $data['product_type'] = $productType->getPageData();
+
+ $products = Product::with('media') // Eager load media to avoid N+1 query problem
+ ->whereVariant()
+ ->where('product_type', $cat)
+ ->where('online', 1)
+ ->where('public', 1)
+ ->orderBy('reference')
+ ->get();
+
+ $data['products'] = [];
+ foreach ($products as $item) {
+ $data['products'][$item->id] = $item->getPageData();
+ }
+
+ // Get available filters
+ $filters = Product::getFilteredProducts($cat);
+ $data['filters'] = $filters ? $filters['filters'] : []; // To be used by Vue component
+ $data['filter_results'] = $filters ? $filters['results'] : [];
+ }
}
+++ /dev/null
-<?php
-
-
-namespace App\Templates;
-
-
-use App\Models\Product;
-use App\Models\ProductType;
-use Cubist\Backpack\app\Magic\Menu\PageItem;
-use Cubist\Backpack\app\Template\FirstRedirection;
-
-class CategoryGroup extends FirstRedirection
-{
- public function getName()
- {
- return 'Groupe de catégories';
- }
-
- public function init()
- {
- parent::init();
-
- $this->addField(['name' => 'categories',
- 'type' => 'SelectFromModel',
- 'optionsmodel' => ProductType::class,
- 'label' => 'Categories',
- 'tab' => 'Catégories',
- 'allows_multiple' => true,
- 'order' => true]);
- }
-}
$i = 0;
foreach ($news as $newsItem) {
-
// Don't include offline items
if ($newsItem->getPageData()->get('status') != 1) {
continue;
}
- // exclude events
- if ($newsItem->getPageData()->get('type') == 'event') {
- continue;
- }
-
-
$item = new PageItem();
$item->initFromEntity($newsItem);
$item->setLocale($menu->getLocale());
$item->setController(['controller' => 'NewsController', 'action' => 'view', 'params' => ['id' => $newsItem->id]]);
// Only show 10 latest news in the menus
- if ($i <= 9) {
- $item->showInAllMenus();
+ // exclude events
+ if ($newsItem->getPageData()->get('type') == 'event') {
+ continue;
} else {
$item->hideInAllMenus();
+ if ($i <= 9) {
+ $item->showInAllMenus();
+ } else {
+ $item->hideInAllMenus();
+ }
+ $i++;
}
$menu->addChild($item);
- $i++;
+
}
Debugbar::stopMeasure('nav_news');
@apply flex mx-auto px-8
// Top level items
+
> li
@apply py-4
//position: relative
animation: submenu-fade-in 0.3s
// Top level links
+
> li > a
@apply text-inherit cursor-pointer
+ white-space nowrap
&:hover
@apply text-primary
// Submenus
- > li > ul // Only target 1st level of submenu items
+
+ > li ul
@apply bg-white text-base shadow-2xl
- display: none
- position: absolute
//top: 100%
//left: 0
+ position: absolute
+ display: none
margin-top: 1rem // Extra margin to replace top: 100% (see IE11 notes above)
padding: 1em 0
li
&:hover, &.active
- a
+ > a
+ @apply text-primary
+ transform: translateX(0)
+
+ &:before
+ transform: scaleX(1)
+
+
+ > li > ul // Only target 1st level of submenu items
+ max-width 450px
+
+ > li a span
+ max-width 350px
+ white-space nowrap
+ overflow hidden
+ text-overflow ellipsis
+
+ > li
+ position relative
+
+ &:hover, &.active
+ > a
@apply text-primary
transform: translateX(0)
&:before
transform: scaleX(1)
+ &:hover
+ > ul
+ display block
+
+ > ul
+ position absolute
+ left 100%
+ top: -32px
+ display none
+ max-width 450px
+
+ > li a span
+ display: block;
+ max-width 350px
+ white-space nowrap
+ overflow hidden
+ text-overflow ellipsis
+
// Submenu links
+
a
@apply text-navy flex items-center w-full py-2
white-space: nowrap
transform: translateX(-2em)
// Animated dash before link
+
&:before
content: ''
display: block
transform-origin: right
// Set transition for links - same for both elements
+
a, a:before
transition: transform 0.2s ease-out
--- /dev/null
+
+
+@extends('layouts/app')
+
+@section('content')
+ @intro(['padding' => 'pb-1v'])
+
+ <full-width class="bg-grey-100" padding="pt-1v pb-2v">
+
+ <content>
+
+ @if ($filters && $filter_results)
+ <products-filters v-cloak
+ :product-type="{{ $product_type->id }}"
+ :filter-data='@json($filters)'
+ :result-data='@json($filter_results)'
+ :translations='@json([
+ 'result' => __('résultat'),
+ 'results' => __('résultats'),
+ 'no_results' => __('Aucun produit ne correspond aux filtres sélectionnés')
+ ])'>
+ @endif
+
+ {{-- Product Grid --}}
+ <grid cols="auto" class="products-grid mt-6 sm:mt-2">
+ @foreach($products as $id => $product)
+ @include('partials.product-link', ['id' => $id, 'product' => $product])
+ @endforeach
+ </grid>
+
+ @if ($filters && $filter_results)
+ </products-filters>
+ @endif
+
+ </content>
+
+ </full-width>
+
+@endsection