filter fix

This commit is contained in:
merdan 2022-04-15 12:47:17 +05:00
parent ae0d7df821
commit 4d6ca3deac
1 changed files with 12 additions and 10 deletions

View File

@ -157,12 +157,12 @@ class ProductRepository extends WProductRepository
if ($priceFilter = request('price')) {
$priceRange = explode(',', $priceFilter);
if (count($priceRange) > 0) {
if (count($priceRange) > 0) {
$customerGroupId = null;
if (Cart::getCurrentCustomer()->check()) {
$customerGroupId = Cart::getCurrentCustomer()->user()->customer_group_id;
if (auth()->guard()->check()) {
$customerGroupId = auth()->guard()->user()->customer_group_id;
} else {
$customerGuestGroup = app('Webkul\Customer\Repositories\CustomerGroupRepository')->getCustomerGuestGroup();
@ -171,24 +171,26 @@ class ProductRepository extends WProductRepository
}
}
$this->variantJoin($qb);
$qb
->leftJoin('catalog_rule_product_prices', 'catalog_rule_product_prices.product_id', '=', 'variants.product_id')
->leftJoin('product_customer_group_prices', 'product_customer_group_prices.product_id', '=', 'variants.product_id')
->where(function ($qb) use ($priceRange, $customerGroupId) {
$qb->where(function ($qb) use ($priceRange){
$qb->where(function ($qb) use ($priceRange) {
$qb
->where('variants.min_price', '>=', core()->convertToBasePrice($priceRange[0]))
->where('variants.min_price', '<=', core()->convertToBasePrice(end($priceRange)));
->where('variants.min_price', '>=', core()->convertToBasePrice($priceRange[0]))
->where('variants.min_price', '<=', core()->convertToBasePrice(end($priceRange)));
})
->orWhere(function ($qb) use ($priceRange) {
$qb
->where('catalog_rule_product_prices.price', '>=', core()->convertToBasePrice($priceRange[0]))
->where('catalog_rule_product_prices.price', '<=', core()->convertToBasePrice(end($priceRange)));
->where('catalog_rule_product_prices.price', '>=', core()->convertToBasePrice($priceRange[0]))
->where('catalog_rule_product_prices.price', '<=', core()->convertToBasePrice(end($priceRange)));
})
->orWhere(function ($qb) use ($priceRange, $customerGroupId) {
$qb
->where('product_customer_group_prices.value', '>=', core()->convertToBasePrice($priceRange[0]))
->where('product_customer_group_prices.value', '<=', core()->convertToBasePrice(end($priceRange)))
->where('product_customer_group_prices.value', '>=', core()->convertToBasePrice($priceRange[0]))
->where('product_customer_group_prices.value', '<=', core()->convertToBasePrice(end($priceRange)))
->where('product_customer_group_prices.customer_group_id', '=', $customerGroupId);
});
});