From 95be1bb32188a2b91f759fd7cf4fbae6adee9d85 Mon Sep 17 00:00:00 2001 From: Amanmyrat Date: Sat, 23 Sep 2023 18:52:35 +0500 Subject: [PATCH] Add search sorting --- .../src/Repositories/ProductRepository.php | 45 ------------------- 1 file changed, 45 deletions(-) diff --git a/packages/Sarga/Shop/src/Repositories/ProductRepository.php b/packages/Sarga/Shop/src/Repositories/ProductRepository.php index cedd541..73c7697 100644 --- a/packages/Sarga/Shop/src/Repositories/ProductRepository.php +++ b/packages/Sarga/Shop/src/Repositories/ProductRepository.php @@ -166,51 +166,6 @@ class ProductRepository extends WProductRepository } } - $attributeFilters = $this->attributeRepository - ->getProductDefaultAttributes(array_keys( - request()->except(['price']) - )); - - if (count($attributeFilters) > 0) { - $query->where(function ($filterQuery) use ($attributeFilters) { - - foreach ($attributeFilters as $attribute) { - $filterQuery->orWhere(function ($attributeQuery) use ($attribute) { - - $column = DB::getTablePrefix() . 'product_attribute_values.' . ProductAttributeValueProxy::modelClass()::$attributeTypeFields[$attribute->type]; - - $filterInputValues = explode(',', request()->get($attribute->code)); - - # define the attribute we are filtering - $attributeQuery = $attributeQuery->where('product_attribute_values.attribute_id', $attribute->id); - - # apply the filter values to the correct column for this type of attribute. - if ($attribute->type != 'price') { - - $attributeQuery->where(function ($attributeValueQuery) use ($column, $filterInputValues) { - foreach ($filterInputValues as $filterValue) { - if (! is_numeric($filterValue)) { - continue; - } - $attributeValueQuery->orWhereRaw("find_in_set(?, {$column})", [$filterValue]); - } - }); - - } else { - $attributeQuery->where($column, '>=', core()->convertToBasePrice(current($filterInputValues))) - ->where($column, '<=', core()->convertToBasePrice(end($filterInputValues))); - } - }); - } - - }); - - # this is key! if a product has been filtered down to the same number of attributes that we filtered on, - # we know that it has matched all of the requested filters. - $query->groupBy('variants.id'); - $query->havingRaw('COUNT(*) = ' . count($attributeFilters)); - } - return $query->groupBy('product_flat.id'); // ->orderBy('product_id', 'desc'); })->paginate($perPage);