Skip to content

Commit b7fe1a6

Browse files
committed
ACP2E-1579: Catalog rule discount disappears after a product is saved from Admin
1 parent 19d56ed commit b7fe1a6

File tree

1 file changed

+15
-2
lines changed
  • app/code/Magento/CatalogRuleConfigurable/Plugin/CatalogRule/Model/Rule

1 file changed

+15
-2
lines changed

app/code/Magento/CatalogRuleConfigurable/Plugin/CatalogRule/Model/Rule/Validation.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*/
77
namespace Magento\CatalogRuleConfigurable\Plugin\CatalogRule\Model\Rule;
88

9+
use Magento\Catalog\Api\ProductRepositoryInterface;
910
use Magento\ConfigurableProduct\Model\Product\Type\Configurable;
1011
use Magento\CatalogRule\Model\Rule;
1112
use Magento\Framework\DataObject;
@@ -21,12 +22,19 @@ class Validation
2122
*/
2223
private $configurable;
2324

25+
/**
26+
* @var ProductRepositoryInterface
27+
*/
28+
private $productRepository;
29+
2430
/**
2531
* @param Configurable $configurableType
32+
* @param ProductRepositoryInterface $productRepository
2633
*/
27-
public function __construct(Configurable $configurableType)
34+
public function __construct(Configurable $configurableType, ProductRepositoryInterface $productRepository)
2835
{
2936
$this->configurable = $configurableType;
37+
$this->productRepository = $productRepository;
3038
}
3139

3240
/**
@@ -41,7 +49,12 @@ public function afterValidate(Rule $rule, $validateResult, DataObject $product)
4149
{
4250
if (!$validateResult && ($configurableProducts = $this->configurable->getParentIdsByChild($product->getId()))) {
4351
foreach ($configurableProducts as $configurableProductId) {
44-
$validateResult = $rule->getConditions()->validateByEntityId($configurableProductId);
52+
$configurableProduct = $this->productRepository->getById(
53+
$configurableProductId,
54+
false,
55+
$product->getStoreId()
56+
);
57+
$validateResult = $rule->getConditions()->validate($configurableProduct);
4558
// If any of configurable product is valid for current rule, then their sub-product must be valid too
4659
if ($validateResult) {
4760
break;

0 commit comments

Comments
 (0)