Skip to content

Commit e62c675

Browse files
authored
Merge pull request #5045 from magento-arcticfoxes/MC-22813
[arcticfoxes] MC-22813: Changing Quantity and Adding to cart throws exception
2 parents 36ea828 + 414dad5 commit e62c675

File tree

2 files changed

+48
-9
lines changed
  • app/code/Magento/ConfigurableProduct

2 files changed

+48
-9
lines changed

app/code/Magento/ConfigurableProduct/Plugin/SalesRule/Model/Rule/Condition/Product.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,10 @@ private function getProductToValidate(
5656
$attrCode = $subject->getAttribute();
5757

5858
/* Check for attributes which are not available for configurable products */
59-
if ($product->getTypeId() == Configurable::TYPE_CODE && !$product->hasData($attrCode)) {
59+
if ($product->getTypeId() == Configurable::TYPE_CODE &&
60+
!$product->hasData($attrCode) &&
61+
count($model->getChildren())
62+
) {
6063
/** @var \Magento\Catalog\Model\AbstractModel $childProduct */
6164
$childProduct = current($model->getChildren())->getProduct();
6265
if ($childProduct->hasData($attrCode)) {

app/code/Magento/ConfigurableProduct/Test/Unit/Plugin/SalesRule/Model/Rule/Condition/ProductTest.php

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -176,14 +176,16 @@ private function createProductMock(): \PHPUnit_Framework_MockObject_MockObject
176176
{
177177
$productMock = $this->getMockBuilder(\Magento\Catalog\Model\Product::class)
178178
->disableOriginalConstructor()
179-
->setMethods([
180-
'getAttribute',
181-
'getId',
182-
'setQuoteItemQty',
183-
'setQuoteItemPrice',
184-
'getTypeId',
185-
'hasData',
186-
])
179+
->setMethods(
180+
[
181+
'getAttribute',
182+
'getId',
183+
'setQuoteItemQty',
184+
'setQuoteItemPrice',
185+
'getTypeId',
186+
'hasData',
187+
]
188+
)
187189
->getMock();
188190
$productMock
189191
->expects($this->any())
@@ -223,4 +225,38 @@ public function testChildIsNotUsedForValidation()
223225

224226
$this->validatorPlugin->beforeValidate($this->validator, $item);
225227
}
228+
229+
/**
230+
* Test for Configurable product in invalid state with no children does not raise error
231+
*/
232+
public function testChildIsNotUsedForValidationWhenConfigurableProductIsMissingChildren()
233+
{
234+
$configurableProductMock = $this->createProductMock();
235+
$configurableProductMock
236+
->expects($this->any())
237+
->method('getTypeId')
238+
->willReturn(Configurable::TYPE_CODE);
239+
240+
$configurableProductMock
241+
->expects($this->any())
242+
->method('hasData')
243+
->with($this->equalTo('special_price'))
244+
->willReturn(false);
245+
246+
/* @var AbstractItem|\PHPUnit_Framework_MockObject_MockObject $item */
247+
$item = $this->getMockBuilder(AbstractItem::class)
248+
->disableOriginalConstructor()
249+
->setMethods(['setProduct', 'getProduct', 'getChildren'])
250+
->getMockForAbstractClass();
251+
$item->expects($this->any())
252+
->method('getProduct')
253+
->willReturn($configurableProductMock);
254+
$item->expects($this->any())
255+
->method('getChildren')
256+
->willReturn([]);
257+
258+
$this->validator->setAttribute('special_price');
259+
260+
$this->validatorPlugin->beforeValidate($this->validator, $item);
261+
}
226262
}

0 commit comments

Comments
 (0)