Skip to content

Commit b0d347f

Browse files
author
Michael Logvin
committed
MAGETWO-42676: Catalog Price Rules are not applied to product after edit the product
1 parent 24abff1 commit b0d347f

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

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

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -213,14 +213,16 @@ protected function cleanByIds($productIds)
213213
{
214214
$this->connection->deleteFromSelect(
215215
$this->connection
216-
->select($this->resource->getTableName('catalogrule_product'), 'product_id')
216+
->select()
217+
->from($this->resource->getTableName('catalogrule_product'), 'product_id')
217218
->distinct()
218219
->where('product_id IN (?)', $productIds),
219220
$this->resource->getTableName('catalogrule_product')
220221
);
221222

222223
$this->connection->deleteFromSelect(
223-
$this->connection->select($this->resource->getTableName('catalogrule_product_price'), 'product_id')
224+
$this->connection->select()
225+
->from($this->resource->getTableName('catalogrule_product_price'), 'product_id')
224226
->distinct()
225227
->where('product_id IN (?)', $productIds),
226228
$this->resource->getTableName('catalogrule_product_price')
@@ -240,6 +242,10 @@ protected function applyRule(Rule $rule, $product)
240242
$productId = $product->getId();
241243
$websiteIds = array_intersect($product->getWebsiteIds(), $rule->getWebsiteIds());
242244

245+
if (!$rule->validate($product)) {
246+
return $this;
247+
}
248+
243249
$this->connection->delete(
244250
$this->resource->getTableName('catalogrule_product'),
245251
[
@@ -248,14 +254,6 @@ protected function applyRule(Rule $rule, $product)
248254
]
249255
);
250256

251-
if (!$rule->validate($product)) {
252-
$this->connection->delete(
253-
$this->resource->getTableName('catalogrule_product_price'),
254-
[$this->connection->quoteInto('product_id = ?', $productId)]
255-
);
256-
return $this;
257-
}
258-
259257
$customerGroupIds = $rule->getCustomerGroupIds();
260258
$fromTime = strtotime($rule->getFromDate());
261259
$toTime = strtotime($rule->getToDate());

0 commit comments

Comments
 (0)