From 5b05cf75f446771c2f1d0fa34b3546c4df52646d Mon Sep 17 00:00:00 2001 From: rahul shukla Date: Wed, 27 Jan 2021 14:58:54 +0530 Subject: [PATCH] Issue #3572 fixes according to comment --- .../Webkul/Product/src/Type/AbstractType.php | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/packages/Webkul/Product/src/Type/AbstractType.php b/packages/Webkul/Product/src/Type/AbstractType.php index 5caf7c2aa..083c38c57 100644 --- a/packages/Webkul/Product/src/Type/AbstractType.php +++ b/packages/Webkul/Product/src/Type/AbstractType.php @@ -932,8 +932,23 @@ abstract class AbstractType public function getCustomerGroupPricingOffers() { $offerLines = []; $haveOffers = true; + $customerGroupId = null; - $customerGroupPrices = $this->product->customer_group_prices()->get()->sortBy('qty')->values()->all(); + if (Cart::getCurrentCustomer()->check()) { + $customerGroupId = Cart::getCurrentCustomer()->user()->customer_group_id; + } else { + $customerGroupRepository = app('Webkul\Customer\Repositories\CustomerGroupRepository'); + + if ($customerGuestGroup = $customerGroupRepository->findOneByField('code', 'guest')) { + $customerGroupId = $customerGuestGroup->id; + } + } + + $customerGroupPrices = $this->product->customer_group_prices()->where(function ($query) use ($customerGroupId) { + $query->where('customer_group_id', $customerGroupId) + ->orWhereNull('customer_group_id'); + } + )->groupBy('qty')->get()->sortBy('qty')->values()->all(); if ($this->haveSpecialPrice()) { $rulePrice = app('Webkul\CatalogRule\Helpers\CatalogRuleProductPrice')->getRulePrice($this->product);