10 use Magento\CatalogRule\Model\ResourceModel\Rule\CollectionFactory as RuleCollectionFactory;
108 private $productPriceCalculator;
113 private $reindexRuleProduct;
118 private $reindexRuleGroupWebsite;
123 private $ruleProductsSelectBuilder;
128 private $reindexRuleProductPrice;
133 private $pricesPersistor;
138 private $activeTableSwitcher;
143 private $tableSwapper;
148 private $productLoader;
191 TableSwapper $tableSwapper =
null 194 $this->connection =
$resource->getConnection();
206 ProductPriceCalculator::class
209 ReindexRuleProduct::class
212 ReindexRuleGroupWebsite::class
215 RuleProductsSelectBuilder::class
218 ReindexRuleProductPrice::class
221 RuleProductPricesPersistor::class
229 $this->tableSwapper = $tableSwapper ??
259 throw new \Magento\Framework\Exception\LocalizedException(
260 __(
"Catalog rule indexing failed. See details in exception log.")
275 $products = $this->productLoader->getProducts($ids);
296 throw new \Magento\Framework\Exception\LocalizedException(
297 __(
"Catalog rule indexing failed. See details in exception log.")
310 $this->reindexRuleProduct->execute(
$rule, $this->batchCount,
true);
313 $this->reindexRuleProductPrice->execute($this->batchCount,
null,
true);
314 $this->reindexRuleGroupWebsite->execute(
true);
316 $this->tableSwapper->swapIndexTables(
318 $this->
getTable(
'catalogrule_product'),
319 $this->
getTable(
'catalogrule_product_price'),
320 $this->
getTable(
'catalogrule_group_website')
333 $query = $this->connection->deleteFromSelect(
336 ->from($this->resource->getTableName(
'catalogrule_product'),
'product_id')
339 $this->resource->getTableName(
'catalogrule_product')
341 $this->connection->query(
$query);
343 $query = $this->connection->deleteFromSelect(
344 $this->connection->select()
345 ->from($this->resource->getTableName(
'catalogrule_product_price'),
'product_id')
348 $this->resource->getTableName(
'catalogrule_product_price')
350 $this->connection->query(
$query);
363 $productEntityId =
$product->getId();
370 $this->connection->delete(
371 $this->resource->getTableName(
'catalogrule_product'),
373 $this->connection->quoteInto(
'rule_id = ?',
$ruleId),
374 $this->connection->quoteInto(
'product_id = ?', $productEntityId)
378 $customerGroupIds =
$rule->getCustomerGroupIds();
379 $fromTime = strtotime(
$rule->getFromDate());
380 $toTime = strtotime(
$rule->getToDate());
381 $toTime = $toTime ? $toTime + self::SECONDS_IN_DAY - 1 : 0;
382 $sortOrder = (int)
$rule->getSortOrder();
383 $actionOperator =
$rule->getSimpleAction();
384 $actionAmount =
$rule->getDiscountAmount();
385 $actionStop =
$rule->getStopRulesProcessing();
390 foreach ($customerGroupIds as $customerGroupId) {
393 'from_time' => $fromTime,
394 'to_time' => $toTime,
396 'customer_group_id' => $customerGroupId,
397 'product_id' => $productEntityId,
398 'action_operator' => $actionOperator,
399 'action_amount' => $actionAmount,
400 'action_stop' => $actionStop,
401 'sort_order' => $sortOrder,
404 if (count($rows) == $this->batchCount) {
405 $this->connection->insertMultiple($this->
getTable(
'catalogrule_product'), $rows);
412 $this->connection->insertMultiple($this->resource->getTableName(
'catalogrule_product'), $rows);
418 $this->reindexRuleProductPrice->execute($this->batchCount,
$product);
419 $this->reindexRuleGroupWebsite->execute();
430 return $this->resource->getTableName(
$tableName);
442 if (
$rule->getProductsFilter()) {
443 $this->connection->delete(
444 $this->
getTable(
'catalogrule_product'),
448 $this->connection->delete(
449 $this->
getTable(
'catalogrule_product'),
450 $this->connection->quoteInto(
'rule_id=?',
$ruleId)
454 $this->reindexRuleProduct->execute(
$rule, $this->batchCount);
468 $this->reindexRuleProductPrice->execute($this->batchCount,
$product);
469 $this->reindexRuleGroupWebsite->execute();
482 $this->reindexRuleGroupWebsite->execute();
493 $this->connection->delete($this->
getTable(
'catalogrule_product_price'));
531 $this->pricesPersistor->execute($arrData);
542 return $this->ruleCollectionFactory->create()->addFieldToFilter(
'is_active', 1);
552 return $this->ruleCollectionFactory->create();
561 if (!isset($this->loadedProducts[
$productId])) {
573 $this->logger->critical($e);
__construct(RuleCollectionFactory $ruleCollectionFactory, PriceCurrencyInterface $priceCurrency, \Magento\Framework\App\ResourceConnection $resource, \Magento\Store\Model\StoreManagerInterface $storeManager, \Psr\Log\LoggerInterface $logger, \Magento\Eav\Model\Config $eavConfig, \Magento\Framework\Stdlib\DateTime $dateFormat, \Magento\Framework\Stdlib\DateTime\DateTime $dateTime, \Magento\Catalog\Model\ProductFactory $productFactory, $batchCount=1000, ProductPriceCalculator $productPriceCalculator=null, ReindexRuleProduct $reindexRuleProduct=null, ReindexRuleGroupWebsite $reindexRuleGroupWebsite=null, RuleProductsSelectBuilder $ruleProductsSelectBuilder=null, ReindexRuleProductPrice $reindexRuleProductPrice=null, RuleProductPricesPersistor $pricesPersistor=null, \Magento\Catalog\Model\ResourceModel\Indexer\ActiveTableSwitcher $activeTableSwitcher=null, ProductLoader $productLoader=null, TableSwapper $tableSwapper=null)
updateCatalogRuleGroupWebsiteData()
$_catalogRuleGroupWebsiteColumnsList
calcRuleProductPrice($ruleData, $productData=null)
saveRuleProductPrices($arrData)
applyAllRules(Product $product=null)
updateRuleProductData(Rule $rule)
applyRule(Rule $rule, $product)
getRuleProductsStmt($websiteId, Product $product=null)