Skip to content

Commit 2ae64f6

Browse files
committed
Fix for Indexer created for websites excluded in Customer groups
1 parent aa32513 commit 2ae64f6

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

Helper/ConfigHelper.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Magento\Framework\Serialize\SerializerInterface;
1212
use Magento\Store\Model\ScopeInterface;
1313
use Magento\Store\Model\StoreManagerInterface;
14+
use Magento\Customer\Api\GroupExcludedWebsiteRepositoryInterface;
1415

1516
class ConfigHelper
1617
{
@@ -175,6 +176,11 @@ class ConfigHelper
175176
*/
176177
protected $groupCollection;
177178

179+
/**
180+
* @var GroupExcludedWebsiteRepositoryInterface
181+
*/
182+
protected $groupExcludedWebsiteRepository;
183+
178184
/**
179185
* @param Magento\Framework\App\Config\ScopeConfigInterface $configInterface
180186
* @param StoreManagerInterface $storeManager
@@ -186,6 +192,7 @@ class ConfigHelper
186192
* @param Magento\Framework\Event\ManagerInterface $eventManager
187193
* @param SerializerInterface $serializer
188194
* @param GroupCollection $groupCollection
195+
* @param GroupExcludedWebsiteRepositoryInterface $groupExcludedWebsiteRepository
189196
*/
190197
public function __construct(
191198
Magento\Framework\App\Config\ScopeConfigInterface $configInterface,
@@ -197,7 +204,8 @@ public function __construct(
197204
Magento\Framework\App\ProductMetadataInterface $productMetadata,
198205
Magento\Framework\Event\ManagerInterface $eventManager,
199206
SerializerInterface $serializer,
200-
GroupCollection $groupCollection
207+
GroupCollection $groupCollection,
208+
GroupExcludedWebsiteRepositoryInterface $groupExcludedWebsiteRepository
201209
) {
202210
$this->configInterface = $configInterface;
203211
$this->currency = $currency;
@@ -209,6 +217,7 @@ public function __construct(
209217
$this->eventManager = $eventManager;
210218
$this->serializer = $serializer;
211219
$this->groupCollection = $groupCollection;
220+
$this->groupExcludedWebsiteRepository = $groupExcludedWebsiteRepository;
212221
}
213222

214223
/**
@@ -939,12 +948,17 @@ public function getSortingIndices($originalIndexName, $storeId = null, $currentC
939948
$indexName = false;
940949
$sortAttribute = false;
941950
if ($this->isCustomerGroupsEnabled($storeId) && $attr['attribute'] === 'price') {
951+
$websiteId = (int)$this->storeManager->getStore($storeId)->getWebsiteId();
942952
$groupCollection = $this->groupCollection;
943953
if (!is_null($currentCustomerGroupId)) {
944954
$groupCollection->addFilter('customer_group_id', $currentCustomerGroupId);
945955
}
946956
foreach ($groupCollection as $group) {
947957
$customerGroupId = (int)$group->getData('customer_group_id');
958+
$excludedWebsites = $this->groupExcludedWebsiteRepository->getCustomerGroupExcludedWebsites($customerGroupId);
959+
if (in_array($websiteId, $excludedWebsites)) {
960+
continue;
961+
}
948962
$groupIndexNameSuffix = 'group_' . $customerGroupId;
949963
$groupIndexName =
950964
$originalIndexName . '_' . $attr['attribute'] . '_' . $groupIndexNameSuffix . '_' . $attr['sort'];

Helper/Entity/Product/PriceManager/ProductWithoutChildren.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,17 @@ public function addPriceData($customData, Product $product, $subProducts): array
105105
if (!$this->areCustomersGroupsEnabled) {
106106
$this->groups->addFieldToFilter('main_table.customer_group_id', 0);
107107
} else {
108+
$excludedGroups = array();
108109
foreach ($this->groups as $group) {
109110
$groupId = (int)$group->getData('customer_group_id');
110111
$excludedWebsites = $this->groupExcludedWebsiteRepository->getCustomerGroupExcludedWebsites($groupId);
111112
if (in_array($product->getStore()->getWebsiteId(), $excludedWebsites)) {
112-
$group->delete();
113+
$excludedGroups[] = $groupId;
113114
}
114115
}
116+
if(count($excludedGroups) > 0) {
117+
$this->groups->addFieldToFilter('main_table.customer_group_id', ["nin" => $excludedGroups]);
118+
}
115119
}
116120
// price/price_with_tax => true/false
117121
foreach ($fields as $field => $withTax) {

0 commit comments

Comments
 (0)