Fix search sorting

This commit is contained in:
Amanmyrat 2023-09-23 18:58:25 +05:00
parent 154403d06f
commit 21bc5c56d9
1 changed files with 12 additions and 1 deletions

View File

@ -77,7 +77,6 @@ class ProductRepository extends WProductRepository
{ {
$channel = core()->getRequestedChannelCode(); $channel = core()->getRequestedChannelCode();
$params = request()->input();
$locale = core()->getRequestedLocaleCode(); $locale = core()->getRequestedLocaleCode();
if (config('scout.driver') == 'algolia') { if (config('scout.driver') == 'algolia') {
@ -114,6 +113,8 @@ class ProductRepository extends WProductRepository
} else { } else {
$results = app(ProductFlatRepository::class)->scopeQuery(function ($query) use ($term, $channel, $locale) { $results = app(ProductFlatRepository::class)->scopeQuery(function ($query) use ($term, $channel, $locale) {
$params = request()->input();
$query = $query->distinct() $query = $query->distinct()
->addSelect('product_flat.*') ->addSelect('product_flat.*')
->where('product_flat.channel', $channel) ->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 # sort direction
$orderDirection = 'asc'; $orderDirection = 'asc';
if (isset($params['order']) && in_array($params['order'], ['desc', 'asc'])) { if (isset($params['order']) && in_array($params['order'], ['desc', 'asc'])) {