Skip to content

Commit 1046d9b

Browse files
committed
Merge remote-tracking branch 'l3/ACP2E-2464' into Tier4-PR-Delivery-11-18-23
2 parents 9a56605 + 40dd1c8 commit 1046d9b

File tree

2 files changed

+39
-9
lines changed

2 files changed

+39
-9
lines changed

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

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,19 @@ public function afterValidate(Rule $rule, $validateResult, DataObject $product)
4949
{
5050
if (!$validateResult && ($configurableProducts = $this->configurable->getParentIdsByChild($product->getId()))) {
5151
foreach ($configurableProducts as $configurableProductId) {
52-
$configurableProduct = $this->productRepository->getById(
53-
$configurableProductId,
54-
false,
55-
$product->getStoreId()
56-
);
57-
$validateResult = $rule->getConditions()->validate($configurableProduct);
58-
// If any of configurable product is valid for current rule, then their sub-product must be valid too
59-
if ($validateResult) {
60-
break;
52+
try {
53+
$configurableProduct = $this->productRepository->getById(
54+
$configurableProductId,
55+
false,
56+
$product->getStoreId()
57+
);
58+
$validateResult = $rule->getConditions()->validate($configurableProduct);
59+
//If any of configurable product is valid for current rule, then their sub-product must be valid too
60+
if ($validateResult) {
61+
break;
62+
}
63+
} catch (\Exception $e) {
64+
continue;
6165
}
6266
}
6367
}

app/code/Magento/CatalogRuleConfigurable/Test/Unit/Plugin/CatalogRule/Model/Rule/ValidationTest.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,32 @@ protected function setUp(): void
6666
);
6767
}
6868

69+
/**
70+
* @return void
71+
*/
72+
public function testAfterValidateConfigurableProductException(): void
73+
{
74+
$validationResult = false;
75+
$parentsIds = [2];
76+
$productId = 1;
77+
78+
$this->productMock->expects($this->once())
79+
->method('getId')
80+
->willReturn($productId);
81+
$this->configurableMock->expects($this->once())
82+
->method('getParentIdsByChild')
83+
->with($productId)
84+
->willReturn($parentsIds);
85+
$this->productRepositoryMock->expects($this->once())
86+
->method('getById')
87+
->willThrowException(new \Exception('Faulty configurable product'));
88+
89+
$this->assertSame(
90+
$validationResult,
91+
$this->validation->afterValidate($this->ruleMock, $validationResult, $this->productMock)
92+
);
93+
}
94+
6995
/**
7096
* @param $parentsIds
7197
* @param $validationResult

0 commit comments

Comments
 (0)