]> _ Git - pmi.git/commitdiff
wip #3520 @2
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 31 Mar 2020 14:09:27 +0000 (16:09 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 31 Mar 2020 14:09:27 +0000 (16:09 +0200)
app/Templates/Category.php
app/Templates/CategoryGroup.php [deleted file]
app/Templates/News.php
resources/styles/components/navigation.styl
resources/views/pages/category.blade.php [new file with mode: 0644]

index c8d697058916bb91d0265bc4766c45cbfb74a287..0890481abd0fefc54597345a24705f73e634abea 100644 (file)
@@ -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 (file)
index daa8e47..0000000
+++ /dev/null
@@ -1,31 +0,0 @@
-<?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]);
-    }
-}
index faace5618ffc739390a14f58509a3b1a4f376a44..672ece9cfadbf8f491fe657bd16a086b7d8891df 100644 (file)
@@ -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');
index 13c2b4fc927e61b5007e412290cfb60a6d45f846..e4bcb4b8acf9a10bfbdce79572f6389cab2e77ca 100644 (file)
@@ -9,6 +9,7 @@
   @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
 
diff --git a/resources/views/pages/category.blade.php b/resources/views/pages/category.blade.php
new file mode 100644 (file)
index 0000000..d2142c2
--- /dev/null
@@ -0,0 +1,39 @@
+
+
+@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