From 3f5f33ecf54a330db9f1d0cfce3b6cb88d2d2fa5 Mon Sep 17 00:00:00 2001 From: merdan Date: Fri, 15 Apr 2022 15:48:17 +0500 Subject: [PATCH] sort fixing --- .../Sarga/Shop/src/Repositories/ProductRepository.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/Sarga/Shop/src/Repositories/ProductRepository.php b/packages/Sarga/Shop/src/Repositories/ProductRepository.php index 4d4c53024..ad33a69a3 100644 --- a/packages/Sarga/Shop/src/Repositories/ProductRepository.php +++ b/packages/Sarga/Shop/src/Repositories/ProductRepository.php @@ -343,7 +343,7 @@ class ProductRepository extends WProductRepository $orderDirection = ! empty($sortOptions) ? $sortOptions[1] : 'asc'; } - DB::connection()->enableQueryLog(); + if (isset($params['sort'])) { $qb = $this->checkSortAttributeAndGenerateQuery($qb, $params['sort'], $orderDirection); } else { @@ -352,7 +352,7 @@ class ProductRepository extends WProductRepository $qb = $this->checkSortAttributeAndGenerateQuery($qb, $sortOptions[0], $orderDirection); } } - Log::info(DB::getQueryLog()); + if ($priceFilter = request('price')) { $priceRange = explode(',', $priceFilter); @@ -394,7 +394,7 @@ class ProductRepository extends WProductRepository }); } } - Log::info(DB::getQueryLog()); + $attributeFilters = $this->attributeRepository ->getProductDefaultAttributes(array_keys( request()->except(['price']) @@ -439,8 +439,10 @@ class ProductRepository extends WProductRepository $qb->groupBy('variants.id'); $qb->havingRaw('COUNT(*) = ' . count($attributeFilters)); } - Log::info(DB::getQueryLog()); + + Log::info($qb->toSql()); return $qb->groupBy('product_flat.id'); + }); # apply scope query so we can fetch the raw sql and perform a count