Skip to content

Commit dda9952

Browse files
author
Maksym Aposov
committed
MAGETWO-37004: Adding grouped product with quantity 0 to cart gets added with quantity of 1
1 parent f852aa4 commit dda9952

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

app/code/Magento/GroupedProduct/Model/Product/Type/Grouped.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ protected function _prepareProduct(\Magento\Framework\Object $buyRequest, $produ
378378

379379
foreach ($associatedProducts as $subProduct) {
380380
$qty = $productsInfo[$subProduct->getId()];
381-
if (!is_numeric($qty)) {
381+
if (!is_numeric($qty) || empty($qty)) {
382382
continue;
383383
}
384384

app/code/Magento/GroupedProduct/Test/Unit/Model/Product/Type/GroupedTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,4 +576,26 @@ public function testPrepareForCartAdvancedWithProductsStrictTrue()
576576
$this->_model->prepareForCartAdvanced($buyRequest, $this->product)
577577
);
578578
}
579+
580+
public function testPrepareForCartAdvancedZeroQty()
581+
{
582+
$expectedMsg = "Please specify the quantity of product(s).";
583+
$associatedId = 9384;
584+
$associatedProduct = $this->getMock('Magento\Catalog\Model\Product', [], [], '', false);
585+
$associatedProduct->expects($this->atLeastOnce())->method('getId')->will($this->returnValue($associatedId));
586+
587+
$buyRequest = new \Magento\Framework\Object();
588+
$buyRequest->setSuperGroup([$associatedId => 0]);
589+
590+
$cached = true;
591+
$this->product
592+
->expects($this->atLeastOnce())
593+
->method('hasData')
594+
->will($this->returnValue($cached));
595+
$this->product
596+
->expects($this->atLeastOnce())
597+
->method('getData')
598+
->will($this->returnValue([$associatedProduct]));
599+
$this->assertEquals($expectedMsg, $this->_model->prepareForCartAdvanced($buyRequest, $this->product));
600+
}
579601
}

0 commit comments

Comments
 (0)