diff --git a/app/code/Magento/GroupedProduct/Test/Mftf/ActionGroup/StorefrontValidateThreeGroupedProductQtyErrorMessageActionGroup.xml b/app/code/Magento/GroupedProduct/Test/Mftf/ActionGroup/StorefrontValidateThreeGroupedProductQtyErrorMessageActionGroup.xml new file mode 100644 index 0000000000000..10b90b6011c5f --- /dev/null +++ b/app/code/Magento/GroupedProduct/Test/Mftf/ActionGroup/StorefrontValidateThreeGroupedProductQtyErrorMessageActionGroup.xml @@ -0,0 +1,24 @@ + + + + + + + Validates Child Products Quantities Input Error Messages are displaying + + + + + + + + + + + diff --git a/app/code/Magento/GroupedProduct/Test/Mftf/Section/StorefrontProductInfoMainSection.xml b/app/code/Magento/GroupedProduct/Test/Mftf/Section/StorefrontProductInfoMainSection.xml index d5c0666e0b1a9..cb281b6fad61b 100644 --- a/app/code/Magento/GroupedProduct/Test/Mftf/Section/StorefrontProductInfoMainSection.xml +++ b/app/code/Magento/GroupedProduct/Test/Mftf/Section/StorefrontProductInfoMainSection.xml @@ -1,8 +1,8 @@ @@ -14,6 +14,7 @@ + diff --git a/app/code/Magento/GroupedProduct/Test/Mftf/Test/StoreFrontValidateGroupedProductQuantityInputErrorMessageTest.xml b/app/code/Magento/GroupedProduct/Test/Mftf/Test/StoreFrontValidateGroupedProductQuantityInputErrorMessageTest.xml new file mode 100644 index 0000000000000..3593315d7aba5 --- /dev/null +++ b/app/code/Magento/GroupedProduct/Test/Mftf/Test/StoreFrontValidateGroupedProductQuantityInputErrorMessageTest.xml @@ -0,0 +1,59 @@ + + + + + + + + + + <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> diff --git a/lib/web/mage/validation/validation.js b/lib/web/mage/validation/validation.js index 578d7968c4732..5f8a15ac75738 100644 --- a/lib/web/mage/validation/validation.js +++ b/lib/web/mage/validation/validation.js @@ -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; },