Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AC-13325 Issue#39347 grouped product qty validation issue fix #39377

Open
wants to merge 8 commits into
base: 2.4-develop
Choose a base branch
from
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright 2011 Adobe
* All Rights Reserved.
*/
-->

<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
<actionGroup name="StorefrontValidateThreeGroupedProductQtyErrorMessageActionGroup">
<annotations>
<description>Validates Child Products Quantities Input Error Messages are displaying</description>
</annotations>
<arguments>
<argument name="firstProductIndex" type="string" defaultValue="1"/>
<argument name="secondProductIndex" type="string" defaultValue="2"/>
<argument name="thirdProductIndex" type="string" defaultValue="3"/>
</arguments>
<dontSeeElement selector="{{StorefrontProductInfoMainSection.groupedProductsAssociatedProductQuantityMageError(firstProductIndex)}}" stepKey="checkingInputValidationErrorMessageForFirstProduct"/>
<seeElement selector="{{StorefrontProductInfoMainSection.groupedProductsAssociatedProductQuantityMageError(secondProductIndex)}}" stepKey="checkingInputValidationErrorMessageForSecondProduct"/>
<dontSeeElement selector="{{StorefrontProductInfoMainSection.groupedProductsAssociatedProductQuantityMageError(thirdProductIndex)}}" stepKey="checkingInputValidationErrorMessageForThirdProduct"/>
</actionGroup>
</actionGroups>
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
* Copyright 2011 Adobe
* All Rights Reserved.
*/
-->

Expand All @@ -14,6 +14,7 @@
<element name="groupedProductsAssociatedProductName" type="text" parameterized="true" selector="#super-product-table tbody tr:nth-of-type({{index}}) .product-item-name"/>
<element name="groupedProductsAssociatedProductPrice" type="text" parameterized="true" selector="#super-product-table tbody tr:nth-of-type({{index}}) .price"/>
<element name="groupedProductsAssociatedProductQuantity" type="input" parameterized="true" selector="#super-product-table tbody tr:nth-of-type({{index}}) input.qty"/>
<element name="groupedProductsAssociatedProductQuantityMageError" type="input" parameterized="true" selector="#super-product-table tr:nth-of-type({{index}}) input.mage-error"/>
<element name="groupedProductOptions" type="input" selector="//td//strong[text()='{{productName}}']" parameterized="true"/>
</section>
</sections>
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright 2011 Adobe
* All Rights Reserved.
*/
-->

<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
<test name="StoreFrontValidateGroupedProductQuantityInputErrorMessageTest">
<annotations>
<features value="GroupedProduct"/>
<stories value="Verify grouped product qty validation message in Storefront"/>
<title value="Grouped product qty validation should be displayed only on invalid qty textbox"/>
<description value="Grouped product qty validation should be displayed only on invalid qty textbox"/>
<testCaseId value="AC-13325"/>
<severity value="MAJOR"/>
<group value="GroupedProduct"/>
</annotations>
<before>
<createData entity="ApiProductWithDescription" stepKey="simple1"/>
<createData entity="ApiProductWithDescription" stepKey="simple2"/>
<createData entity="ApiProductWithDescription" stepKey="simple3"/>
<createData entity="ApiGroupedProduct" stepKey="product"/>
<createData entity="OneSimpleProductLink" stepKey="addProductOne">
<requiredEntity createDataKey="product"/>
<requiredEntity createDataKey="simple1"/>
</createData>
<updateData entity="OneMoreSimpleProductLink" createDataKey="addProductOne" stepKey="addProductTwo">
<requiredEntity createDataKey="product"/>
<requiredEntity createDataKey="simple2"/>
</updateData>
<updateData entity="OneMoreSimpleProductLink" createDataKey="addProductOne" stepKey="addProductThree">
<requiredEntity createDataKey="product"/>
<requiredEntity createDataKey="simple3"/>
</updateData>
<actionGroup ref="CliIndexerReindexActionGroup" stepKey="runIndex">
<argument name="indices" value=""/>
</actionGroup>
</before>
<after>
<deleteData createDataKey="simple1" stepKey="deleteSimple1"/>
<deleteData createDataKey="simple2" stepKey="deleteSimple2"/>
<deleteData createDataKey="simple3" stepKey="deleteSimple3"/>
<deleteData createDataKey="product" stepKey="deleteGroupedProduct"/>
</after>
<actionGroup ref="StorefrontAddThreeGroupedProductToTheCartActionGroup" stepKey="enterSimpleProductsQty">
<argument name="urlKey" value="$$product.custom_attributes[url_key]$$" />
<argument name="product1" value="$simple1.name$"/>
<argument name="product2" value="$simple2.name$"/>
<argument name="product3" value="$simple3.name$"/>
<argument name="qty1" value="10"/>
<argument name="qty2" value="-10"/>
<argument name="qty3" value="5"/>
</actionGroup>
<actionGroup ref="StorefrontValidateThreeGroupedProductQtyErrorMessageActionGroup" stepKey="verifyQtyInputErrorMessage" />
</test>
</tests>
26 changes: 10 additions & 16 deletions lib/web/mage/validation/validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,19 @@ define([
'validate-grouped-qty': [
function (value, element, params) {
var result = false,
total = 0;
total = 0,
valInt;

$(params).find('input[data-validate*="validate-grouped-qty"]').each(function (i, e) {
var val = $(e).val(),
valInt;
if (value && value.length > 0) {
result = true;
valInt = parseFloat(value) || 0;

if (val && val.length > 0) {
result = true;
valInt = parseFloat(val) || 0;

if (valInt >= 0) {
total += valInt;
} else {
result = false;

return result;
}
if (valInt >= 0) {
total += valInt;
} else {
return false;
}
});
}

return result && total > 0;
},
Expand Down