Skip to content

Commit dd820e5

Browse files
committed
AC-1116: "Minimum Qty Allowed in Shopping Cart" for simple product bug when adding product more than once
1 parent 96faea7 commit dd820e5

File tree

7 files changed

+28
-33
lines changed

7 files changed

+28
-33
lines changed

app/code/Magento/Bundle/Test/Mftf/Test/StorefrontCustomerSelectAndSetBundleOptionsTest.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,23 +105,23 @@
105105
<selectOption selector="{{StorefrontBundledSection.dropDownOptionOneProducts('Option One')}}" userInput="$$simpleProduct1.name$$ +$$$simpleProduct1.price$$.00" stepKey="selectOption0Product0"/>
106106
<seeOptionIsSelected selector="{{StorefrontBundledSection.dropDownOptionOneProducts('Option One')}}" userInput="$$simpleProduct1.name$$ +$$$simpleProduct1.price$$.00" stepKey="checkOption0Product0"/>
107107
<fillField selector="{{StorefrontBundledSection.dropDownOptionOneQuantity('Option One')}}" userInput="3" stepKey="fillQuantity00"/>
108-
<seeInField selector="{{StorefrontBundledSection.dropDownOptionOneQuantity('Option One')}}" userInput="3" stepKey="checkQuantity00"/>
108+
<seeInField selector="{{StorefrontBundledSection.dropDownOptionOneQuantity('Option One')}}" userInput="03" stepKey="checkQuantity00"/>
109109

110110
<selectOption selector="{{StorefrontBundledSection.dropDownOptionOneProducts('Option One')}}" userInput="$$simpleProduct2.name$$ +$$$simpleProduct2.price$$.00" stepKey="selectOption0Product1"/>
111111
<seeOptionIsSelected selector="{{StorefrontBundledSection.dropDownOptionOneProducts('Option One')}}" userInput="$$simpleProduct2.name$$ +$$$simpleProduct2.price$$.00" stepKey="checkOption0Product1"/>
112112
<fillField selector="{{StorefrontBundledSection.dropDownOptionOneQuantity('Option One')}}" userInput="3" stepKey="fillQuantity01"/>
113-
<seeInField selector="{{StorefrontBundledSection.dropDownOptionOneQuantity('Option One')}}" userInput="3" stepKey="checkQuantity01"/>
113+
<seeInField selector="{{StorefrontBundledSection.dropDownOptionOneQuantity('Option One')}}" userInput="03" stepKey="checkQuantity01"/>
114114

115115
<!--"Radio Buttons" type option-->
116116
<checkOption selector="{{StorefrontBundledSection.radioButtonOptionTwoProducts('Option Two', '1')}}" stepKey="selectOption1Product0"/>
117117
<seeCheckboxIsChecked selector="{{StorefrontBundledSection.radioButtonOptionTwoProducts('Option Two', '1')}}" stepKey="checkOption1Product0"/>
118118
<fillField selector="{{StorefrontBundledSection.radioButtonOptionTwoQuantity('Option Two')}}" userInput="3" stepKey="fillQuantity10"/>
119-
<seeInField selector="{{StorefrontBundledSection.radioButtonOptionTwoQuantity('Option Two')}}" userInput="3" stepKey="checkQuantity10"/>
119+
<seeInField selector="{{StorefrontBundledSection.radioButtonOptionTwoQuantity('Option Two')}}" userInput="03" stepKey="checkQuantity10"/>
120120

121121
<checkOption selector="{{StorefrontBundledSection.radioButtonOptionTwoProducts('Option Two', '2')}}" stepKey="selectOption1Product1"/>
122122
<seeCheckboxIsChecked selector="{{StorefrontBundledSection.radioButtonOptionTwoProducts('Option Two', '2')}}" stepKey="checkOption1Product1"/>
123123
<fillField selector="{{StorefrontBundledSection.radioButtonOptionTwoQuantity('Option Two')}}" userInput="3" stepKey="fillQuantity11"/>
124-
<seeInField selector="{{StorefrontBundledSection.radioButtonOptionTwoQuantity('Option Two')}}" userInput="3" stepKey="checkQuantity11"/>
124+
<seeInField selector="{{StorefrontBundledSection.radioButtonOptionTwoQuantity('Option Two')}}" userInput="03" stepKey="checkQuantity11"/>
125125

126126
<!--"Checkbox" type option-->
127127
<!--This option does not support user defined quantities-->

app/code/Magento/Bundle/Test/Mftf/Test/StorefrontValidateQuantityBundleProductsTest.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@
8080
<!--"Drop-down" type option-->
8181
<selectOption selector="{{StorefrontBundledSection.dropDownOptionOneProducts('Option One')}}" userInput="$$createProduct1.name$$ +$$$createProduct1.price$$.00" stepKey="selectOption0Product0"/>
8282
<seeOptionIsSelected selector="{{StorefrontBundledSection.dropDownOptionOneProducts('Option One')}}" userInput="$$createProduct1.name$$ +$$$createProduct1.price$$.00" stepKey="checkOption0Product0"/>
83+
<fillField selector="{{StorefrontBundledSection.dropDownOptionOneQuantity('Option One')}}" userInput="-" stepKey="emptyDropdownQuantity"/>
8384
<fillField selector="{{StorefrontBundledSection.dropDownOptionOneQuantity('Option One')}}" userInput="-1" stepKey="fillQuantity00"/>
8485
<seeInField selector="{{StorefrontBundledSection.dropDownOptionOneQuantity('Option One')}}" userInput="-1" stepKey="checkQuantity00"/>
8586
<click selector="{{StorefrontBundledSection.addToCartConfigured}}" stepKey="clickAddToCartDropDown"/>
@@ -88,6 +89,7 @@
8889
<!--"Radio Buttons" type option-->
8990
<checkOption selector="{{StorefrontBundledSection.radioButtonOptionTwoProducts('Option Two', '1')}}" stepKey="selectOption1Product0"/>
9091
<seeCheckboxIsChecked selector="{{StorefrontBundledSection.radioButtonOptionTwoProducts('Option Two', '1')}}" stepKey="checkOption1Product0"/>
92+
<fillField selector="{{StorefrontBundledSection.radioButtonOptionTwoQuantity('Option Two')}}" userInput="-" stepKey="emptyRadioQuantity"/>
9193
<fillField selector="{{StorefrontBundledSection.radioButtonOptionTwoQuantity('Option Two')}}" userInput="-1" stepKey="fillQuantity10"/>
9294
<seeInField selector="{{StorefrontBundledSection.radioButtonOptionTwoQuantity('Option Two')}}" userInput="-1" stepKey="checkQuantity10"/>
9395
<click selector="{{StorefrontBundledSection.addToCartConfigured}}" stepKey="clickAddToCartRadioButton"/>

app/code/Magento/Bundle/ViewModel/ValidateQuantity.php

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
use Magento\Framework\Serialize\Serializer\Json;
1111
use Magento\Framework\View\Element\Block\ArgumentInterface;
12-
use Magento\Catalog\Block\Product\View as ProductView;
1312

1413
/**
1514
* ViewModel for Bundle Option Block
@@ -21,27 +20,24 @@ class ValidateQuantity implements ArgumentInterface
2120
*/
2221
private $serializer;
2322

24-
/**
25-
* @var ProductView
26-
*/
27-
private $productView;
28-
2923
/**
3024
* @param Json $serializer
31-
* @param ProductView $productView
3225
*/
3326
public function __construct(
34-
Json $serializer,
35-
ProductView $productView
27+
Json $serializer
3628
) {
3729
$this->serializer = $serializer;
38-
$this->productView = $productView;
3930
}
4031

32+
/**
33+
* Returns quantity validator.
34+
*
35+
* @return string
36+
*/
4137
public function getQuantityValidators(): string
4238
{
43-
return $this->serializer->serialize(
44-
$this->productView->getQuantityValidators()
45-
);
39+
$validators['validate-item-quantity'] = [];
40+
41+
return $this->serializer->serialize($validators);
4642
}
4743
}

app/code/Magento/Bundle/view/base/web/js/price-bundle.js

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -387,15 +387,9 @@ define([
387387
function isValidQty(bundleOption) {
388388
var isValid = true,
389389
qtyElem = bundleOption.data('qtyField'),
390-
bundleOptionType = bundleOption.prop('type'),
391-
qtyValidator = qtyElem.data('validate') &&
392-
typeof qtyElem.data('validate')['validate-item-quantity'] === 'object' ?
393-
qtyElem.data('validate')['validate-item-quantity'] : null;
394-
395-
if (['radio', 'select-one'].includes(bundleOptionType) &&
396-
qtyValidator &&
397-
(qtyElem.val() < qtyValidator.minAllowed || qtyElem.val() > qtyValidator.maxAllowed)
398-
) {
390+
bundleOptionType = bundleOption.prop('type');
391+
392+
if (['radio', 'select-one'].includes(bundleOptionType) && qtyElem.val() < 0) {
399393
isValid = false;
400394
}
401395

app/code/Magento/Catalog/Test/Mftf/Test/AdminAddInStockProductToTheCartTest.xml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
</actionGroup>
5252
<comment userInput="Comment is added to preserve the step key for backward compatibility" stepKey="uncheckMiniQtyCheckBox"/>
5353
<actionGroup ref="AdminSetMinAllowedQtyForProductActionGroup" stepKey="fillMiniAllowedQty">
54-
<argument name="qty" value="1"/>
54+
<argument name="qty" value="4"/>
5555
</actionGroup>
5656
<comment userInput="Comment is added to preserve the step key for backward compatibility" stepKey="uncheckMaxQtyCheckBox"/>
5757
<actionGroup ref="AdminSetMaxAllowedQtyForProductActionGroup" stepKey="fillMaxAllowedQty">
@@ -107,16 +107,20 @@
107107
<!--Add Product to the cart-->
108108
<comment userInput="Comment is added to preserve the step key for backward compatibility" stepKey="fillProductQuantity"/>
109109
<actionGroup ref="StorefrontAddProductToCartWithQtyActionGroup" stepKey="addToCartFromStorefrontProductPage">
110+
<argument name="productQty" value="4"/>
111+
</actionGroup>
112+
<actionGroup ref="StorefrontAddProductToCartWithQtyActionGroup" stepKey="addAdditionalProductToCart">
110113
<argument name="productQty" value="1"/>
111114
</actionGroup>
112115
<comment userInput="Comment is added to preserve the step key for backward compatibility" stepKey="seeSuccessSaveMessage"/>
113-
<seeElement selector="{{StorefrontMinicartSection.quantity(1)}}" stepKey="seeAddedProductQuantityInCart"/>
116+
<seeElement selector="{{StorefrontMinicartSection.quantity(6)}}" stepKey="seeAddedProductQuantityInCart"/>
114117
<actionGroup ref="StorefrontClickOnMiniCartActionGroup" stepKey="clickOnMiniCart"/>
118+
<executeJS function="return {{SimpleProduct.price}} * 5" stepKey="expectedCartSubtotal"/>
115119
<actionGroup ref="AssertStorefrontMiniCartItemsActionGroup" stepKey="seeProductNameInMiniCart">
116120
<argument name="productName" value="{{SimpleProduct.name}}"/>
117121
<argument name="productPrice" value="{{SimpleProduct.price}}"/>
118-
<argument name="cartSubtotal" value="{{SimpleProduct.price}}" />
119-
<argument name="qty" value="1"/>
122+
<argument name="cartSubtotal" value="{$expectedCartSubtotal}" />
123+
<argument name="qty" value="5"/>
120124
</actionGroup>
121125
<comment userInput="Comment is added to preserve the step key for backward compatibility" stepKey="seeProductPriceInMiniCart"/>
122126
<comment userInput="Comment is added to preserve the step key for backward compatibility" stepKey="seeCheckOutButtonInMiniCart"/>

app/code/Magento/CatalogInventory/Block/Plugin/ProductView.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ public function __construct(
2424
}
2525

2626
/**
27+
* Adds quantities validator.
28+
*
2729
* @param \Magento\Catalog\Block\Product\View $block
2830
* @param array $validators
2931
* @return array
@@ -38,7 +40,6 @@ public function afterGetQuantityValidators(
3840
);
3941

4042
$params = [];
41-
$params['minAllowed'] = (float)$stockItem->getMinSaleQty();
4243
if ($stockItem->getMaxSaleQty()) {
4344
$params['maxAllowed'] = (float)$stockItem->getMaxSaleQty();
4445
}

app/code/Magento/CatalogInventory/Test/Unit/Block/Plugin/ProductViewTest.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ public function testAfterGetQuantityValidators()
5959
{
6060
$result = [
6161
'validate-item-quantity' => [
62-
'minAllowed' => 0.5,
6362
'maxAllowed' => 5.0,
6463
'qtyIncrements' => 3.0
6564
]
@@ -85,7 +84,6 @@ public function testAfterGetQuantityValidators()
8584
->method('getStockItem')
8685
->with('productId', 'websiteId')
8786
->willReturn($this->stockItem);
88-
$this->stockItem->expects($this->once())->method('getMinSaleQty')->willReturn(0.5);
8987
$this->stockItem->expects($this->any())->method('getMaxSaleQty')->willReturn(5);
9088
$this->stockItem->expects($this->any())->method('getQtyIncrements')->willReturn(3);
9189

0 commit comments

Comments
 (0)