]> _ Git - pmi.git/commitdiff
wait #6498 @0.5
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 23 Nov 2023 09:38:39 +0000 (10:38 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 23 Nov 2023 09:38:39 +0000 (10:38 +0100)
app/Models/Product.php
app/Templates/Category.php
composer.json
resources/views/pages/category.blade.php

index f0d51b00e928c8777e3933fd0235694e8809a97e..ebc673ee434bb5ea07803efca71d441f5aabb804 100644 (file)
@@ -6,8 +6,8 @@ use App\Http\Controllers\Admin\ProductBaseController;
 use Cubist\Backpack\app\Magic\Menu\Menu;
 use Cubist\Backpack\app\Magic\Models\CubistMagicPageModel;
 use Cubist\Backpack\app\Magic\Util;
+use Cubist\Backpack\Facades\App;
 use Cubist\Util\Json;
-use Illuminate\Support\Facades\App;
 use Illuminate\Support\Str;
 use Spatie\Image\Manipulations;
 use Spatie\MediaLibrary\Models\Media;
@@ -578,6 +578,14 @@ class Product extends CubistMagicPageModel
         }) : 0;
     }
 
+    public function renderLink()
+    {
+        $p = $this;
+        return \cache()->remember('product_details_' . $this->id . '_' . App::getLocale() . '_' . App::getVariant(), 3600, function () use ($p) {
+            return view('partials.product-link', ['id' => $p->id, 'product' => $p->getPageData()])->render();
+        });
+    }
+
 
     public static function getFilteredProducts($product_type, $filter_values = [])
     {
index ec8188530b63febdf1b5b8ed15261b7f54bb2f3d..d91f6b83e41ea60c28080b1adae9cf9c7eac0736 100644 (file)
@@ -53,8 +53,8 @@ class Category extends Base
         \Barryvdh\Debugbar\Facade::startMeasure('set cat data');
         $cat = $data['page']->get('category');
 
+        \Barryvdh\Debugbar\Facade::startMeasure('set cat data ' . $cat);
         $d = cache()->remember('cat_data_' . $cat . '_' . App::getVariant() . '_' . App::getLocale(), 3600, function () use ($cat) {
-
             $res = [];
             $productType = ProductType::find($cat);
             if (!$productType) {
@@ -62,16 +62,13 @@ class Category extends Base
             }
             $res['product_type'] = $productType->getPageData();
 
-            $products = Product::with('media') // Eager load media to avoid N+1 query problem
-            ->whereVariant()
+            $res['products'] = Product::whereVariant()
                 ->where('product_type', $cat)
                 ->where('online', 1)
                 ->where('public', 1)
                 ->orderBy('reference')
                 ->get();
 
-            $res['products'] = PageData::fromEntities($products);
-
             // Get available filters
             $filters = Product::getFilteredProducts($cat);
             $res['filters'] = $filters ? $filters['filters'] : []; // To be used by Vue component
@@ -81,6 +78,7 @@ class Category extends Base
         if (!$d) {
             $this->_404();
         }
+        \Barryvdh\Debugbar\Facade::stopMeasure('set cat data ' . $cat);
 
         foreach ($d as $k => $v) {
             $data[$k] = $v;
index 7670a24817d3d79d30f9823ceed658c03b2a1192..62a00f2a8c30600941c1c82f0df3376846621fe3 100644 (file)
@@ -30,7 +30,7 @@
             "composer/installers": true
         },
         "platform": {
-            "php": "7.4"
+            "php": "8.0"
         }
     },
     "extra": {
index 99e1cffa459e11f036529ab04c2822f123e6f67b..46315142ca3b96014a1e6c36cc86573db88d8749 100644 (file)
@@ -25,7 +25,7 @@
                     {{-- 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])
+                            {!!$product->renderLink()!!}
                         @endforeach
                     </grid>