From: Vincent Vanwaelscappel Date: Tue, 31 Mar 2020 14:09:27 +0000 (+0200) Subject: wip #3520 @2 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=d8b63701cd2d6ebab5df41b7e18ab74374feda31;p=pmi.git wip #3520 @2 --- diff --git a/app/Templates/Category.php b/app/Templates/Category.php index c8d6970..0890481 100644 --- a/app/Templates/Category.php +++ b/app/Templates/Category.php @@ -3,6 +3,7 @@ namespace App\Templates; +use App\Models\Product; use App\Models\ProductType; class Category extends Base @@ -36,4 +37,35 @@ 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'] : []; + } } diff --git a/app/Templates/CategoryGroup.php b/app/Templates/CategoryGroup.php deleted file mode 100644 index daa8e47..0000000 --- a/app/Templates/CategoryGroup.php +++ /dev/null @@ -1,31 +0,0 @@ -addField(['name' => 'categories', - 'type' => 'SelectFromModel', - 'optionsmodel' => ProductType::class, - 'label' => 'Categories', - 'tab' => 'Catégories', - 'allows_multiple' => true, - 'order' => true]); - } -} diff --git a/app/Templates/News.php b/app/Templates/News.php index faace56..672ece9 100644 --- a/app/Templates/News.php +++ b/app/Templates/News.php @@ -24,18 +24,11 @@ class News extends Base $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()); @@ -46,14 +39,21 @@ class News extends Base $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'); diff --git a/resources/styles/components/navigation.styl b/resources/styles/components/navigation.styl index 13c2b4f..e4bcb4b 100644 --- a/resources/styles/components/navigation.styl +++ b/resources/styles/components/navigation.styl @@ -9,6 +9,7 @@ @apply flex mx-auto px-8 // Top level items + > li @apply py-4 //position: relative @@ -29,33 +30,76 @@ 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 @@ -64,6 +108,7 @@ transform: translateX(-2em) // Animated dash before link + &:before content: '' display: block @@ -75,6 +120,7 @@ transform-origin: right // Set transition for links - same for both elements + a, a:before transition: transform 0.2s ease-out diff --git a/resources/views/pages/category.blade.php b/resources/views/pages/category.blade.php new file mode 100644 index 0000000..d2142c2 --- /dev/null +++ b/resources/views/pages/category.blade.php @@ -0,0 +1,39 @@ + + +@extends('layouts/app') + +@section('content') + @intro(['padding' => 'pb-1v']) + + + + + + @if ($filters && $filter_results) + __('résultat'), + 'results' => __('résultats'), + 'no_results' => __('Aucun produit ne correspond aux filtres sélectionnés') + ])'> + @endif + + {{-- Product Grid --}} + + @foreach($products as $id => $product) + @include('partials.product-link', ['id' => $id, 'product' => $product]) + @endforeach + + + @if ($filters && $filter_results) + + @endif + + + + + +@endsection