Skip to content

Commit

Permalink
Merge branch '2.4-develop' into 2.4-develop
Browse files Browse the repository at this point in the history
  • Loading branch information
in-session authored Mar 10, 2021
2 parents de5c558 + 1fa7fb1 commit 5188dcf
Show file tree
Hide file tree
Showing 40 changed files with 2,926 additions and 105 deletions.
16 changes: 16 additions & 0 deletions app/code/Magento/Bundle/Model/ResourceModel/Indexer/Price.php
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,10 @@ private function prepareBundlePriceByType($priceType, array $dimensions, $entity
['cwd' => $this->getTable('catalog_product_index_website')],
'pw.website_id = cwd.website_id',
[]
)->joinLeft(
['cgw' => $this->getTable('customer_group_excluded_website')],
'cg.customer_group_id = cgw.customer_group_id AND pw.website_id = cgw.website_id',
[]
);
$select->joinLeft(
['tp' => $this->getTable('catalog_product_index_tier_price')],
Expand Down Expand Up @@ -365,6 +369,9 @@ private function prepareBundlePriceByType($priceType, array $dimensions, $entity
$select->where('e.entity_id IN(?)', $entityIds);
}

// exclude websites that are limited for customer group
$select->where('cgw.website_id IS NULL');

/**
* Add additional external limitation
*/
Expand Down Expand Up @@ -714,6 +721,11 @@ private function prepareTierPriceIndex($dimensions, $entityIds)
['pw' => $this->getTable('store_website')],
'tp.website_id = 0 OR tp.website_id = pw.website_id',
['website_id']
)->joinLeft(
// customer group website limitations
['cgw' => $this->getTable('customer_group_excluded_website')],
'cg.customer_group_id = cgw.customer_group_id AND pw.website_id = cgw.website_id',
[]
)->where(
'pw.website_id != 0'
)->where(
Expand All @@ -728,6 +740,10 @@ private function prepareTierPriceIndex($dimensions, $entityIds)
if (!empty($entityIds)) {
$select->where('e.entity_id IN(?)', $entityIds);
}

// exclude websites that are limited for customer group
$select->where('cgw.website_id IS NULL');

foreach ($dimensions as $dimension) {
if (!isset($this->dimensionToFieldMapper[$dimension->getName()])) {
throw new \LogicException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,11 @@ public function getQuery(array $dimensions, string $productType, array $entityId
['cwd' => $this->getTable('catalog_product_index_website')],
'pw.website_id = cwd.website_id',
[]
)->joinLeft(
// customer group website limitations
['cgw' => $this->getTable('customer_group_excluded_website')],
'cg.customer_group_id = cgw.customer_group_id AND pw.website_id = cgw.website_id',
[]
)->joinLeft(
// we need this only for BCC in case someone expects table `tp` to be present in query
['tp' => $this->getTable('catalog_product_index_tier_price')],
Expand Down Expand Up @@ -227,6 +232,9 @@ public function getQuery(array $dimensions, string $productType, array $entityId
$select->where('e.entity_id IN(?)', $entityIds);
}

// exclude websites that are limited for customer group
$select->where('cgw.website_id IS NULL');

/**
* throw event for backward compatibility
*/
Expand Down
41 changes: 25 additions & 16 deletions app/code/Magento/CatalogRule/Model/Indexer/ReindexRuleProduct.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@ public function execute(Rule $rule, $batchCount, $useAdditionalTable = false)
$actionStop = $rule->getStopRulesProcessing();
$fromTimeInAdminTz = $this->parseDateByWebsiteTz((string)$rule->getFromDate(), self::ADMIN_WEBSITE_ID);
$toTimeInAdminTz = $this->parseDateByWebsiteTz((string)$rule->getToDate(), self::ADMIN_WEBSITE_ID);
$excludedWebsites = [];
$ruleExtensionAttributes = $rule->getExtensionAttributes();
if ($ruleExtensionAttributes && $ruleExtensionAttributes->getExcludeWebsiteIds()) {
$excludedWebsites = $ruleExtensionAttributes->getExcludeWebsiteIds();
}

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

foreach ($customerGroupIds as $customerGroupId) {
$rows[] = [
'rule_id' => $ruleId,
'from_time' => $fromTime,
'to_time' => $toTime,
'website_id' => $websiteId,
'customer_group_id' => $customerGroupId,
'product_id' => $productId,
'action_operator' => $actionOperator,
'action_amount' => $actionAmount,
'action_stop' => $actionStop,
'sort_order' => $sortOrder,
];

if (count($rows) == $batchCount) {
$connection->insertMultiple($indexTable, $rows);
$rows = [];
if (!array_key_exists($customerGroupId, $excludedWebsites)
|| !in_array((int)$websiteId, array_values($excludedWebsites[$customerGroupId]), true)
) {
$rows[] = [
'rule_id' => $ruleId,
'from_time' => $fromTime,
'to_time' => $toTime,
'website_id' => $websiteId,
'customer_group_id' => $customerGroupId,
'product_id' => $productId,
'action_operator' => $actionOperator,
'action_amount' => $actionAmount,
'action_stop' => $actionStop,
'sort_order' => $sortOrder,
];

if (count($rows) === $batchCount) {
$connection->insertMultiple($indexTable, $rows);
$rows = [];
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
*/
namespace Magento\CatalogRule\Model\ResourceModel\Rule;

use Magento\Framework\Serialize\Serializer\Json;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\Serialize\Serializer\Json;

class Collection extends \Magento\Rule\Model\ResourceModel\Rule\Collection\AbstractCollection
{
Expand All @@ -22,6 +22,16 @@ class Collection extends \Magento\Rule\Model\ResourceModel\Rule\Collection\Abstr
*/
protected $serializer;

/**
* @var string
*/
protected $_eventPrefix = 'catalog_rule_collection';

/**
* @var string
*/
protected $_eventObject = 'catalog_rule';

/**
* Collection constructor.
* @param \Magento\Framework\Data\Collection\EntityFactoryInterface $entityFactory
Expand Down
Loading

0 comments on commit 5188dcf

Please sign in to comment.