From 21bc5c56d9212d755bdc6f77f3e82d966d5cd596 Mon Sep 17 00:00:00 2001 From: Amanmyrat Date: Sat, 23 Sep 2023 18:58:25 +0500 Subject: [PATCH] Fix search sorting --- .../Shop/src/Repositories/ProductRepository.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/Sarga/Shop/src/Repositories/ProductRepository.php b/packages/Sarga/Shop/src/Repositories/ProductRepository.php index 305812c..a1855e6 100644 --- a/packages/Sarga/Shop/src/Repositories/ProductRepository.php +++ b/packages/Sarga/Shop/src/Repositories/ProductRepository.php @@ -77,7 +77,6 @@ class ProductRepository extends WProductRepository { $channel = core()->getRequestedChannelCode(); - $params = request()->input(); $locale = core()->getRequestedLocaleCode(); if (config('scout.driver') == 'algolia') { @@ -114,6 +113,8 @@ class ProductRepository extends WProductRepository } else { $results = app(ProductFlatRepository::class)->scopeQuery(function ($query) use ($term, $channel, $locale) { + $params = request()->input(); + $query = $query->distinct() ->addSelect('product_flat.*') ->where('product_flat.channel', $channel) @@ -139,6 +140,16 @@ class ProductRepository extends WProductRepository } }); + /* added for api as per the documentation */ + if (isset($params['name'])) { + $query->where('product_flat.name', 'like', '%' . urldecode($params['name']) . '%'); + } + + /* added for api as per the documentation */ + if (isset($params['url_key'])) { + $query->where('product_flat.url_key', 'like', '%' . urldecode($params['url_key']) . '%'); + } + # sort direction $orderDirection = 'asc'; if (isset($params['order']) && in_array($params['order'], ['desc', 'asc'])) {