Skip to content

Commit 6ef62c8

Browse files
ENGCOM-7655: fixed validation for bundle checkbox options #27854
- Merge Pull Request #27854 from ProkopovVitaliy/magento2:fix-27489 - Merged commits: 1. bdeb934 2. e224442 3. 6c7a5d4 4. 8056d0e 5. 999fb8f 6. bf1722a 7. 628beb0 8. 698ec67 9. 90ee413 10. 1046d8f 11. 5a8eb63 12. f46bed1 13. f048e3a 14. 9a0e4df 15. 6b9bf69 16. 2fe9174 17. 382cac4 18. 00f3514 19. 497fce2 20. 9b11cbc 21. 82dd19e
2 parents dc14e50 + 82dd19e commit 6ef62c8

File tree

6 files changed

+149
-14
lines changed

6 files changed

+149
-14
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
9+
<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
11+
<actionGroup name="AssertStorefrontBundleValidationMessageActionGroup">
12+
<annotations>
13+
<description>Check error message in validation message box</description>
14+
</annotations>
15+
<arguments>
16+
<argument name="message" type="string"/>
17+
</arguments>
18+
19+
<waitForPageLoad stepKey="waitForPageLoad"/>
20+
<see selector="{{StorefrontBundledSection.validationMessageBox}}" userInput="{{message}}" stepKey="seeErrorHoldMessage"/>
21+
</actionGroup>
22+
</actionGroups>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
9+
<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
11+
<actionGroup name="AssertStorefrontBundleValidationMessagesCountActionGroup">
12+
<annotations>
13+
<description>Check if there's a validation message box on page and asserts the validation messages number</description>
14+
</annotations>
15+
16+
<waitForPageLoad stepKey="waitForPageLoad"/>
17+
<seeElement selector="{{StorefrontBundledSection.validationMessageBox}}" stepKey="seeErrorBox"/>
18+
<seeNumberOfElements selector="{{StorefrontBundledSection.validationMessageBox}}" userInput="1" stepKey="seeOneErrorBox"/>
19+
</actionGroup>
20+
</actionGroups>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
9+
<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
11+
<actionGroup name="StorefrontAddToTheCartButtonActionGroup">
12+
<annotations>
13+
<description>Clicks 'Add to Cart' on a Storefront Bundled Product page.</description>
14+
</annotations>
15+
16+
<waitForPageLoad stepKey="waitForPageLoad"/>
17+
<waitForElementVisible selector="{{StorefrontBundleProductActionSection.addToCartButton}}" stepKey="waitForAddToCartButton"/>
18+
<click selector="{{StorefrontBundleProductActionSection.addToCartButton}}" stepKey="clickOnAddToCartButton"/>
19+
</actionGroup>
20+
</actionGroups>

app/code/Magento/Bundle/Test/Mftf/Section/StorefrontBundledSection.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,6 @@
3838
<element name="currencyTrigger" type="select" selector="#switcher-currency-trigger" timeout="30"/>
3939
<element name="currency" type="select" selector="//a[text()='{{arg}}']" parameterized="true"/>
4040
<element name="multiSelectOption" type="select" selector="//div[@class='field option required']//select"/>
41+
<element name="validationMessageBox" type="block" selector="#validation-message-box"/>
4142
</section>
4243
</sections>
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
9+
<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
11+
<test name="StorefrontBundleCheckBoxOptionValidationTest">
12+
<annotations>
13+
<features value="Bundle"/>
14+
<stories value="Bundle product validation before add to cart"/>
15+
<title value="Customer should be able to see only one validation message for checkbox option group"/>
16+
<description value="Customer should be able to see only one validation message for checkbox option group"/>
17+
<testCaseId value="MC-35133"/>
18+
<severity value="MINOR"/>
19+
<group value="Bundle"/>
20+
</annotations>
21+
<before>
22+
<createData entity="ApiProductWithDescription" stepKey="simpleProduct1" before="bundleProduct"/>
23+
<createData entity="ApiProductWithDescription" stepKey="simpleProduct2" after="simpleProduct1"/>
24+
<createData entity="ApiBundleProduct" stepKey="bundleProduct"/>
25+
<createData entity="CheckboxOption" stepKey="checkboxBundleOption">
26+
<requiredEntity createDataKey="bundleProduct"/>
27+
</createData>
28+
<createData entity="ApiBundleLink" stepKey="createBundleLink1">
29+
<requiredEntity createDataKey="bundleProduct"/>
30+
<requiredEntity createDataKey="checkboxBundleOption"/>
31+
<requiredEntity createDataKey="simpleProduct1"/>
32+
<field key="qty">2</field>
33+
</createData>
34+
<createData entity="ApiBundleLink" stepKey="createBundleLink2">
35+
<requiredEntity createDataKey="bundleProduct"/>
36+
<requiredEntity createDataKey="checkboxBundleOption"/>
37+
<requiredEntity createDataKey="simpleProduct2"/>
38+
<field key="qty">4</field>
39+
</createData>
40+
<magentoCron stepKey="runCronIndex" groups="index"/>
41+
</before>
42+
<after>
43+
<deleteData createDataKey="bundleProduct" stepKey="deleteBundleProduct"/>
44+
<deleteData createDataKey="simpleProduct1" stepKey="deleteSimpleProduct1"/>
45+
<deleteData createDataKey="simpleProduct2" stepKey="deleteSimpleProduct2"/>
46+
</after>
47+
<actionGroup ref="StorefrontOpenProductPageActionGroup" stepKey="openProductStorefront">
48+
<argument name="productUrl" value="$$bundleProduct.custom_attributes[url_key]$$"/>
49+
</actionGroup>
50+
<actionGroup ref="StorefrontSelectCustomizeAndAddToTheCartButtonActionGroup" stepKey="customizeBundleProduct"/>
51+
<actionGroup ref="StorefrontAddToTheCartButtonActionGroup" stepKey="addToCartBundleProduct"/>
52+
<actionGroup ref="AssertStorefrontBundleValidationMessagesCountActionGroup" stepKey="assertBundleValidationCount"/>
53+
<actionGroup ref="AssertStorefrontBundleValidationMessageActionGroup" stepKey="assertBundleValidationMessage">
54+
<argument name="message" value="Please select one of the options."/>
55+
</actionGroup>
56+
</test>
57+
</tests>

app/code/Magento/Bundle/view/frontend/templates/catalog/product/view/type/bundle/option/checkbox.phtml

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,40 +8,55 @@
88
<?php /* @var $block \Magento\Bundle\Block\Catalog\Product\View\Type\Bundle\Option\Checkbox */ ?>
99
<?php $_option = $block->getOption() ?>
1010
<?php $_selections = $_option->getSelections() ?>
11+
<?php $inputClass = 'checkbox product bundle option bundle-option-' . $block->escapeHtmlAttr($_option->getId()) ?>
12+
<?php $inputId = 'bundle-option-' . $block->escapeHtmlAttr($_option->getId()) ?>
13+
<?php $inputName = 'bundle_option[' . $block->escapeHtmlAttr($_option->getId()) . ']' ?>
14+
<?php $dataValidation = 'data-validate="{\'validate-one-required-by-name\':\'input[name^=&quot;bundle_option[' .
15+
$block->escapeHtmlAttr($_option->getId()) . ']&quot;]:checked\'}"' ?>
16+
1117
<div class="field option <?= ($_option->getRequired()) ? ' required': '' ?>">
1218
<label class="label">
1319
<span><?= $block->escapeHtml($_option->getTitle()) ?></span>
1420
</label>
1521
<div class="control">
1622
<div class="nested options-list">
17-
<?php if ($block->showSingle()) : ?>
23+
<?php if ($block->showSingle()): ?>
1824
<?= /* @noEscape */ $block->getSelectionQtyTitlePrice($_selections[0]) ?>
1925
<?= /* @noEscape */ $block->getTierPriceRenderer()->renderTierPrice($_selections[0]) ?>
2026
<input type="hidden"
2127
class="bundle-option-<?= $block->escapeHtmlAttr($_option->getId()) ?> product bundle option"
2228
name="bundle_option[<?= $block->escapeHtml($_option->getId()) ?>]"
2329
value="<?= $block->escapeHtmlAttr($_selections[0]->getSelectionId()) ?>"/>
24-
<?php else :?>
25-
<?php foreach ($_selections as $_selection) : ?>
30+
<?php else: ?>
31+
<?php foreach ($_selections as $selection): ?>
32+
<?php $sectionId = $selection->getSelectionId() ?>
2633
<div class="field choice">
27-
<input class="bundle-option-<?= $block->escapeHtmlAttr($_option->getId()) ?> checkbox product bundle option change-container-classname"
28-
id="bundle-option-<?= $block->escapeHtmlAttr($_option->getId()) ?>-<?= $block->escapeHtmlAttr($_selection->getSelectionId()) ?>"
34+
<input class="<?=/* @noEscape */ $inputClass ?> change-container-classname"
35+
id="<?=/* @noEscape */ $inputId . '-' . $block->escapeHtmlAttr($sectionId)?>"
2936
type="checkbox"
30-
<?php if ($_option->getRequired()) { echo 'data-validate="{\'validate-one-required-by-name\':\'input[name^=&quot;bundle_option[' . $block->escapeHtmlAttr($_option->getId()) . ']&quot;]:checked\'}"'; } ?>
31-
name="bundle_option[<?= $block->escapeHtmlAttr($_option->getId()) ?>][<?= $block->escapeHtmlAttr($_selection->getId()) ?>]"
32-
data-selector="bundle_option[<?= $block->escapeHtmlAttr($_option->getId()) ?>][<?= $block->escapeHtmlAttr($_selection->getId()) ?>]"
33-
<?php if ($block->isSelected($_selection)) { echo ' checked="checked"'; } ?>
34-
<?php if (!$_selection->isSaleable()) { echo ' disabled="disabled"'; } ?>
35-
value="<?= $block->escapeHtmlAttr($_selection->getSelectionId()) ?>"/>
37+
<?php if ($_option->getRequired()): ?>
38+
<?= /* @noEscape */ $dataValidation ?>
39+
<?php endif;?>
40+
name="<?=/* @noEscape */ $inputName .'['. $block->escapeHtmlAttr($sectionId)?>]"
41+
data-selector="<?= /* @noEscape */ $inputName.'['.$block->escapeHtmlAttr($sectionId)?>]"
42+
<?php if ($block->isSelected($selection)): ?>
43+
<?= ' checked="checked"' ?>
44+
<?php endif; ?>
45+
<?php if (!$selection->isSaleable()): ?>
46+
<?= ' disabled="disabled"' ?>
47+
<?php endif; ?>
48+
value="<?= $block->escapeHtmlAttr($sectionId) ?>"
49+
data-errors-message-box="#validation-message-box"/>
3650
<label class="label"
37-
for="bundle-option-<?= $block->escapeHtmlAttr($_option->getId()) ?>-<?= $block->escapeHtmlAttr($_selection->getSelectionId()) ?>">
38-
<span><?= /* @noEscape */ $block->getSelectionQtyTitlePrice($_selection) ?></span>
51+
for="<?= /* @noEscape */ $inputId . '-' . $block->escapeHtmlAttr($sectionId) ?>">
52+
<span><?= /* @noEscape */ $block->getSelectionQtyTitlePrice($selection) ?></span>
3953
<br/>
40-
<?= /* @noEscape */ $block->getTierPriceRenderer()->renderTierPrice($_selection) ?>
54+
<?= /* @noEscape */ $block->getTierPriceRenderer()->renderTierPrice($selection) ?>
4155
</label>
4256
</div>
4357
<?php endforeach; ?>
4458
<div id="bundle-option-<?= $block->escapeHtmlAttr($_option->getId()) ?>-container"></div>
59+
<div id="validation-message-box"></div>
4560
<?php endif; ?>
4661
</div>
4762
</div>

0 commit comments

Comments
 (0)