17 private $storeManager;
22 private $ruleProductsSelectBuilder;
27 private $productPriceCalculator;
37 private $pricesPersistor;
54 $this->ruleProductsSelectBuilder = $ruleProductsSelectBuilder;
55 $this->productPriceCalculator = $productPriceCalculator;
57 $this->pricesPersistor = $pricesPersistor;
72 $useAdditionalTable =
false 74 $fromDate = mktime(0, 0, 0, date(
'm'), date(
'd') - 1);
75 $toDate = mktime(0, 0, 0, date(
'm'), date(
'd') + 1);
81 foreach ($this->storeManager->getWebsites() as
$website) {
82 $productsStmt = $this->ruleProductsSelectBuilder->build(
$website->getId(),
$product, $useAdditionalTable);
87 while (
$ruleData = $productsStmt->fetch()) {
89 $productKey = $ruleProductId .
95 if ($prevKey && $prevKey != $productKey) {
97 if (count($dayPrices) > $batchCount) {
98 $this->pricesPersistor->execute($dayPrices, $useAdditionalTable);
113 $priceKey = $time .
'_' . $productKey;
115 if (isset($stopFlags[$priceKey])) {
119 if (!isset($dayPrices[$priceKey])) {
120 $dayPrices[$priceKey] = [
121 'rule_date' => $time,
123 'customer_group_id' =>
$ruleData[
'customer_group_id'],
124 'product_id' => $ruleProductId,
125 'rule_price' => $this->productPriceCalculator->calculate(
$ruleData),
126 'latest_start_date' =>
$ruleData[
'from_time'],
127 'earliest_end_date' =>
$ruleData[
'to_time'],
130 $dayPrices[$priceKey][
'rule_price'] = $this->productPriceCalculator->calculate(
132 $dayPrices[$priceKey]
134 $dayPrices[$priceKey][
'latest_start_date'] = max(
135 $dayPrices[$priceKey][
'latest_start_date'],
138 $dayPrices[$priceKey][
'earliest_end_date'] = min(
139 $dayPrices[$priceKey][
'earliest_end_date'],
145 $stopFlags[$priceKey] =
true;
150 $prevKey = $productKey;
152 $this->pricesPersistor->execute($dayPrices, $useAdditionalTable);
161 private function roundTime($timeStamp)
163 if (is_numeric($timeStamp) && $timeStamp != 0) {
164 $timeStamp = $this->dateTime->timestamp($this->dateTime->date(
'Y-m-d 00:00:00', $timeStamp));
execute( $batchCount, \Magento\Catalog\Model\Product $product=null, $useAdditionalTable=false)
__construct(\Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\CatalogRule\Model\Indexer\RuleProductsSelectBuilder $ruleProductsSelectBuilder, \Magento\CatalogRule\Model\Indexer\ProductPriceCalculator $productPriceCalculator, \Magento\Framework\Stdlib\DateTime\DateTime $dateTime, \Magento\CatalogRule\Model\Indexer\RuleProductPricesPersistor $pricesPersistor)