Skip to content

Commit 1fa7fb1

Browse files
authored
Merge pull request #6626 from magento-performance/MCP-218
[Performance] MCP-218: Customer Group Limitations by Websites
2 parents 6a63aac + b224af0 commit 1fa7fb1

File tree

40 files changed

+2926
-105
lines changed

40 files changed

+2926
-105
lines changed

app/code/Magento/Bundle/Model/ResourceModel/Indexer/Price.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,10 @@ private function prepareBundlePriceByType($priceType, array $dimensions, $entity
273273
['cwd' => $this->getTable('catalog_product_index_website')],
274274
'pw.website_id = cwd.website_id',
275275
[]
276+
)->joinLeft(
277+
['cgw' => $this->getTable('customer_group_excluded_website')],
278+
'cg.customer_group_id = cgw.customer_group_id AND pw.website_id = cgw.website_id',
279+
[]
276280
);
277281
$select->joinLeft(
278282
['tp' => $this->getTable('catalog_product_index_tier_price')],
@@ -365,6 +369,9 @@ private function prepareBundlePriceByType($priceType, array $dimensions, $entity
365369
$select->where('e.entity_id IN(?)', $entityIds);
366370
}
367371

372+
// exclude websites that are limited for customer group
373+
$select->where('cgw.website_id IS NULL');
374+
368375
/**
369376
* Add additional external limitation
370377
*/
@@ -714,6 +721,11 @@ private function prepareTierPriceIndex($dimensions, $entityIds)
714721
['pw' => $this->getTable('store_website')],
715722
'tp.website_id = 0 OR tp.website_id = pw.website_id',
716723
['website_id']
724+
)->joinLeft(
725+
// customer group website limitations
726+
['cgw' => $this->getTable('customer_group_excluded_website')],
727+
'cg.customer_group_id = cgw.customer_group_id AND pw.website_id = cgw.website_id',
728+
[]
717729
)->where(
718730
'pw.website_id != 0'
719731
)->where(
@@ -728,6 +740,10 @@ private function prepareTierPriceIndex($dimensions, $entityIds)
728740
if (!empty($entityIds)) {
729741
$select->where('e.entity_id IN(?)', $entityIds);
730742
}
743+
744+
// exclude websites that are limited for customer group
745+
$select->where('cgw.website_id IS NULL');
746+
731747
foreach ($dimensions as $dimension) {
732748
if (!isset($this->dimensionToFieldMapper[$dimension->getName()])) {
733749
throw new \LogicException(

app/code/Magento/Catalog/Model/ResourceModel/Product/Indexer/Price/Query/BaseFinalPrice.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,11 @@ public function getQuery(array $dimensions, string $productType, array $entityId
128128
['cwd' => $this->getTable('catalog_product_index_website')],
129129
'pw.website_id = cwd.website_id',
130130
[]
131+
)->joinLeft(
132+
// customer group website limitations
133+
['cgw' => $this->getTable('customer_group_excluded_website')],
134+
'cg.customer_group_id = cgw.customer_group_id AND pw.website_id = cgw.website_id',
135+
[]
131136
)->joinLeft(
132137
// we need this only for BCC in case someone expects table `tp` to be present in query
133138
['tp' => $this->getTable('catalog_product_index_tier_price')],
@@ -227,6 +232,9 @@ public function getQuery(array $dimensions, string $productType, array $entityId
227232
$select->where('e.entity_id IN(?)', $entityIds);
228233
}
229234

235+
// exclude websites that are limited for customer group
236+
$select->where('cgw.website_id IS NULL');
237+
230238
/**
231239
* throw event for backward compatibility
232240
*/

app/code/Magento/CatalogRule/Model/Indexer/ReindexRuleProduct.php

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,11 @@ public function execute(Rule $rule, $batchCount, $useAdditionalTable = false)
107107
$actionStop = $rule->getStopRulesProcessing();
108108
$fromTimeInAdminTz = $this->parseDateByWebsiteTz((string)$rule->getFromDate(), self::ADMIN_WEBSITE_ID);
109109
$toTimeInAdminTz = $this->parseDateByWebsiteTz((string)$rule->getToDate(), self::ADMIN_WEBSITE_ID);
110+
$excludedWebsites = [];
111+
$ruleExtensionAttributes = $rule->getExtensionAttributes();
112+
if ($ruleExtensionAttributes && $ruleExtensionAttributes->getExcludeWebsiteIds()) {
113+
$excludedWebsites = $ruleExtensionAttributes->getExcludeWebsiteIds();
114+
}
110115

111116
$rows = [];
112117
foreach ($websiteIds as $websiteId) {
@@ -124,22 +129,26 @@ public function execute(Rule $rule, $batchCount, $useAdditionalTable = false)
124129
}
125130

126131
foreach ($customerGroupIds as $customerGroupId) {
127-
$rows[] = [
128-
'rule_id' => $ruleId,
129-
'from_time' => $fromTime,
130-
'to_time' => $toTime,
131-
'website_id' => $websiteId,
132-
'customer_group_id' => $customerGroupId,
133-
'product_id' => $productId,
134-
'action_operator' => $actionOperator,
135-
'action_amount' => $actionAmount,
136-
'action_stop' => $actionStop,
137-
'sort_order' => $sortOrder,
138-
];
139-
140-
if (count($rows) == $batchCount) {
141-
$connection->insertMultiple($indexTable, $rows);
142-
$rows = [];
132+
if (!array_key_exists($customerGroupId, $excludedWebsites)
133+
|| !in_array((int)$websiteId, array_values($excludedWebsites[$customerGroupId]), true)
134+
) {
135+
$rows[] = [
136+
'rule_id' => $ruleId,
137+
'from_time' => $fromTime,
138+
'to_time' => $toTime,
139+
'website_id' => $websiteId,
140+
'customer_group_id' => $customerGroupId,
141+
'product_id' => $productId,
142+
'action_operator' => $actionOperator,
143+
'action_amount' => $actionAmount,
144+
'action_stop' => $actionStop,
145+
'sort_order' => $sortOrder,
146+
];
147+
148+
if (count($rows) === $batchCount) {
149+
$connection->insertMultiple($indexTable, $rows);
150+
$rows = [];
151+
}
143152
}
144153
}
145154
}

app/code/Magento/CatalogRule/Model/ResourceModel/Rule/Collection.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
*/
66
namespace Magento\CatalogRule\Model\ResourceModel\Rule;
77

8-
use Magento\Framework\Serialize\Serializer\Json;
98
use Magento\Framework\App\ObjectManager;
9+
use Magento\Framework\Serialize\Serializer\Json;
1010

1111
class Collection extends \Magento\Rule\Model\ResourceModel\Rule\Collection\AbstractCollection
1212
{
@@ -22,6 +22,16 @@ class Collection extends \Magento\Rule\Model\ResourceModel\Rule\Collection\Abstr
2222
*/
2323
protected $serializer;
2424

25+
/**
26+
* @var string
27+
*/
28+
protected $_eventPrefix = 'catalog_rule_collection';
29+
30+
/**
31+
* @var string
32+
*/
33+
protected $_eventObject = 'catalog_rule';
34+
2535
/**
2636
* Collection constructor.
2737
* @param \Magento\Framework\Data\Collection\EntityFactoryInterface $entityFactory

0 commit comments

Comments
 (0)