From: Vincent Vanwaelscappel Date: Thu, 23 Nov 2023 09:38:39 +0000 (+0100) Subject: wait #6498 @0.5 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=0da7f1ef67bdff39639e3fa5baceef261dea5f51;p=pmi.git wait #6498 @0.5 --- diff --git a/app/Models/Product.php b/app/Models/Product.php index f0d51b0..ebc673e 100644 --- a/app/Models/Product.php +++ b/app/Models/Product.php @@ -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 = []) { diff --git a/app/Templates/Category.php b/app/Templates/Category.php index ec81885..d91f6b8 100644 --- a/app/Templates/Category.php +++ b/app/Templates/Category.php @@ -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; diff --git a/composer.json b/composer.json index 7670a24..62a00f2 100644 --- a/composer.json +++ b/composer.json @@ -30,7 +30,7 @@ "composer/installers": true }, "platform": { - "php": "7.4" + "php": "8.0" } }, "extra": { diff --git a/resources/views/pages/category.blade.php b/resources/views/pages/category.blade.php index 99e1cff..4631514 100644 --- a/resources/views/pages/category.blade.php +++ b/resources/views/pages/category.blade.php @@ -25,7 +25,7 @@ {{-- Product Grid --}} @foreach($products as $id => $product) - @include('partials.product-link', ['id' => $id, 'product' => $product]) + {!!$product->renderLink()!!} @endforeach