Skip to content

Commit 6a33719

Browse files
authored
Merge pull request #5922 from magento-engcom/2.4-develop-temporary-one-prs
[Magento Community Engineering] Community Contributions - 2.4-develop expedited-1
2 parents 2219289 + f009c74 commit 6a33719

23 files changed

+550
-25
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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+
<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
9+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
10+
<actionGroup name="AdminOpenSalesCheckoutConfigPageActionGroup">
11+
<annotations>
12+
<description>Goes to the Store Configuration > Sales > Checkout configuration page in admin.</description>
13+
</annotations>
14+
<arguments>
15+
<argument name="tabGroupAnchor" type="string" defaultValue=""/>
16+
</arguments>
17+
<amOnPage url="{{AdminCheckoutConfigPage.url(tabGroupAnchor)}}" stepKey="openCheckoutConfigPage"/>
18+
<waitForPageLoad stepKey="waitForCheckoutConfigPageLoad"/>
19+
</actionGroup>
20+
</actionGroups>
21+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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="AdminSelectClearShoppingCartConfigurationActionGroup">
12+
<annotations>
13+
<description>Enable/Disable clear shopping cart store configuration using UI.</description>
14+
</annotations>
15+
<arguments>
16+
<argument name="value" type="string" defaultValue="{{EnableClearShoppingCart.textValue}}"/>
17+
</arguments>
18+
<waitForElementVisible selector="{{AdminCheckoutConfigSection.clearShoppingCartEnabledInherit}}" stepKey="waitForClearShoppingCartEnabledInherit" />
19+
<uncheckOption selector="{{AdminCheckoutConfigSection.clearShoppingCartEnabledInherit}}" stepKey="uncheckUseSystem" />
20+
<waitForElementVisible selector="{{AdminCheckoutConfigSection.clearShoppingCartEnabled}}" stepKey="waitForClearShoppingCartEnabled" />
21+
<selectOption selector="{{AdminCheckoutConfigSection.clearShoppingCartEnabled}}" userInput="{{value}}" stepKey="fillClearShoppingCartEnabled" />
22+
</actionGroup>
23+
</actionGroups>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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="StorefrontClearShoppingCartActionGroup">
12+
<annotations>
13+
<description>Clicks the Clear Shopping Cart button on the storefront on the shopping cart page and verifies shopping cart gets emptied.</description>
14+
</annotations>
15+
16+
<waitForElementVisible selector="{{CheckoutCartProductSection.emptyCartButton}}" stepKey="waitForEmptyCartButton"/>
17+
<click selector="{{CheckoutCartProductSection.emptyCartButton}}" stepKey="clickEmptyCartButton"/>
18+
<waitForElementVisible selector="{{CheckoutCartProductSection.modalMessage}}" stepKey="waitForModalMessage"/>
19+
<waitForText selector="{{CheckoutCartProductSection.modalMessage}}" userInput="Are you sure you want to remove all items from your shopping cart?" stepKey="waitForTextModalMessage"/>
20+
<waitForElementVisible selector="{{CheckoutCartProductSection.modalConfirmButton}}" stepKey="waitForModalConfirmButton"/>
21+
<click selector="{{CheckoutCartProductSection.modalConfirmButton}}" stepKey="clickModalConfirmButton"/>
22+
<waitForPageLoad stepKey="waitForPageLoad"/>
23+
<seeCurrentUrlEquals url="{{_ENV.MAGENTO_BASE_URL}}checkout/cart" stepKey="seeCurrentUrlEqualsCartPage"/>
24+
<waitForText selector="{{CheckoutCartMessageSection.emptyCartMessage}}" userInput="You have no items in your shopping cart." stepKey="waitForEmptyCartMessage"/>
25+
26+
</actionGroup>
27+
</actionGroups>

app/code/Magento/Checkout/Test/Mftf/Data/ConfigData.xml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,4 +100,17 @@
100100
<data key="label">Display number of items in cart</data>
101101
<data key="value">0</data>
102102
</entity>
103+
104+
<entity name="EnableClearShoppingCart">
105+
<data key="path">checkout/cart/enable_clear_shopping_cart</data>
106+
<data key="label">Display clear shopping cart button on the cart page</data>
107+
<data key="value">1</data>
108+
<data key="textValue">Yes</data>
109+
</entity>
110+
<entity name="DisableClearShoppingCart">
111+
<data key="path">checkout/cart/enable_clear_shopping_cart</data>
112+
<data key="label">Do not display clear shopping cart button on the cart page</data>
113+
<data key="value">0</data>
114+
<data key="textValue">No</data>
115+
</entity>
103116
</entities>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
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+
<pages xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:mftf:Page/etc/PageObject.xsd">
9+
<page name="AdminCheckoutConfigPage" url="admin/system_config/edit/section/checkout/{{tabLink}}" area="admin" parameterized="true" module="Magento_Checkout">
10+
<section name="AdminCheckoutConfigSection"/>
11+
</page>
12+
</pages>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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+
<sections xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:mftf:Page/etc/SectionObject.xsd">
9+
<section name="AdminCheckoutConfigSection">
10+
<element name="clearShoppingCartEnabled" type="select" selector="#checkout_cart_enable_clear_shopping_cart" timeout="30"/>
11+
<element name="clearShoppingCartEnabledInherit" type="select" selector="#checkout_cart_enable_clear_shopping_cart_inherit" timeout="30"/>
12+
</section>
13+
</sections>

app/code/Magento/Checkout/Test/Mftf/Section/CheckoutCartProductSection.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@
4848
<element name="checkoutCartProductPrice" type="text" selector="//td[@class='col price']//span[@class='price']"/>
4949
<element name="checkoutCartSubtotal" type="text" selector="//td[@class='col subtotal']//span[@class='price']"/>
5050
<element name="emptyCart" selector=".cart-empty" type="text"/>
51+
<element name="emptyCartButton" type="button" selector="#empty_cart_button" timeout="30"/>
52+
<element name="modalMessage" type="text" selector=".modal-popup.confirm._show .modal-content" timeout="30"/>
53+
<element name="modalConfirmButton" type="button" selector=".modal-popup.confirm._show .action-accept" timeout="30"/>
5154
<!-- Required attention section -->
5255
<element name="removeProductBySku" type="button" selector="//div[contains(., '{{sku}}')]/ancestor::tbody//button" parameterized="true" timeout="30"/>
5356
<element name="failedItemBySku" type="block" selector="//div[contains(.,'{{sku}}')]/ancestor::tbody" parameterized="true" timeout="30"/>
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
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+
<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
9+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
10+
<test name="ClearShoppingCartEnableDisableConfigurationTest">
11+
<annotations>
12+
<features value="Checkout"/>
13+
<stories value="Shopping Cart"/>
14+
<title value="Enable and Disable Clear Shopping Cart Configuration"/>
15+
<description value="Verify that disabling the clear shopping cart store configuration will remove the clear shopping cart configuration button from the storefront's shopping cart page. Verify that enabling the configuration will add the button to the page and that the button functions as expected"/>
16+
<group value="shoppingCart"/>
17+
<severity value="MAJOR"/>
18+
</annotations>
19+
<before>
20+
<!-- Create simple products and category -->
21+
<createData entity="_defaultCategory" stepKey="createCategory"/>
22+
<createData entity="SimpleProduct" stepKey="createProduct1">
23+
<requiredEntity createDataKey="createCategory"/>
24+
</createData>
25+
<createData entity="SimpleProduct" stepKey="createProduct2">
26+
<requiredEntity createDataKey="createCategory"/>
27+
</createData>
28+
29+
<actionGroup ref="AdminLoginActionGroup" stepKey="loginAsAdmin"/>
30+
</before>
31+
<after>
32+
<deleteData createDataKey="createCategory" stepKey="deleteCategory"/>
33+
<deleteData createDataKey="createProduct1" stepKey="deleteProduct1"/>
34+
<deleteData createDataKey="createProduct2" stepKey="deleteProduct2"/>
35+
36+
<!-- Disable clear shopping cart -->
37+
<magentoCLI command="config:set {{DisableClearShoppingCart.path}} {{DisableClearShoppingCart.value}}" stepKey="disableClearShoppingCart"/>
38+
<actionGroup ref="AdminLogoutActionGroup" stepKey="logout"/>
39+
</after>
40+
41+
<!-- Navigate to sales checkout cart configuration -->
42+
<actionGroup ref="AdminOpenSalesCheckoutConfigPageActionGroup" stepKey="openSalesCheckoutCartConfig1">
43+
<argument name="tabGroupAnchor" value="#checkout_cart-link"/>
44+
</actionGroup>
45+
46+
<!-- Enable clear shopping cart button -->
47+
<actionGroup ref="AdminSelectClearShoppingCartConfigurationActionGroup" stepKey="enableClearShoppingCartButton"/>
48+
<actionGroup ref="SaveStoreConfigurationActionGroup" stepKey="saveStoreConfiguration1"/>
49+
50+
<!-- Open product 1 and add to cart -->
51+
<actionGroup ref="StorefrontOpenProductEntityPageActionGroup" stepKey="openProduct1Page1">
52+
<argument name="product" value="$$createProduct1$$"/>
53+
</actionGroup>
54+
<actionGroup ref="StorefrontAddToTheCartActionGroup" stepKey="product1AddToCart"/>
55+
56+
<!-- Open product 2 and add to cart -->
57+
<actionGroup ref="StorefrontOpenProductEntityPageActionGroup" stepKey="openProduct2Page">
58+
<argument name="product" value="$$createProduct2$$"/>
59+
</actionGroup>
60+
<actionGroup ref="StorefrontAddToTheCartActionGroup" stepKey="product2AddToCart"/>
61+
62+
<!-- Go to shopping cart page -->
63+
<actionGroup ref="StorefrontCartPageOpenActionGroup" stepKey="openShoppingCartPage1"/>
64+
65+
<!-- Clear shopping cart -->
66+
<actionGroup ref="StorefrontClearShoppingCartActionGroup" stepKey="clearShoppingCart"/>
67+
<actionGroup ref="AssertMiniCartEmptyActionGroup" stepKey="assertMiniCartEmpty"/>
68+
69+
<!-- Return to Admin to disable clear shopping cart -->
70+
<actionGroup ref="AdminOpenSalesCheckoutConfigPageActionGroup" stepKey="openSalesCheckoutCartConfig2"/>
71+
<actionGroup ref="AdminSelectClearShoppingCartConfigurationActionGroup" stepKey="disableClearShoppingCartButton">
72+
<argument name="value" value="{{DisableClearShoppingCart.textValue}}"/>
73+
</actionGroup>
74+
<actionGroup ref="SaveStoreConfigurationActionGroup" stepKey="saveStoreConfiguration2"/>
75+
76+
<!-- Open product 1 page and add to cart -->
77+
<actionGroup ref="StorefrontOpenProductEntityPageActionGroup" stepKey="openProduct1Page2">
78+
<argument name="product" value="$$createProduct1$$"/>
79+
</actionGroup>
80+
<actionGroup ref="StorefrontAddToTheCartActionGroup" stepKey="product1AddToCart2"/>
81+
82+
<!-- Go to shopping cart and assert clear shopping cart button is not rendered in UI -->
83+
<actionGroup ref="StorefrontCartPageOpenActionGroup" stepKey="openShoppingCartPage2"/>
84+
<dontSeeElementInDOM selector="{{CheckoutCartProductSection.emptyCartButton}}" stepKey="dontSeeElementEmptyCartButton"/>
85+
</test>
86+
</tests>
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Checkout\ViewModel;
8+
9+
use Magento\Framework\App\Config\ScopeConfigInterface;
10+
use Magento\Framework\View\Element\Block\ArgumentInterface;
11+
use Magento\Framework\View\Element\Context;
12+
use Magento\Store\Model\ScopeInterface;
13+
14+
/**
15+
* Cart form view model.
16+
*/
17+
class Cart implements ArgumentInterface
18+
{
19+
/**
20+
* Config settings path to enable clear shopping cart button
21+
*/
22+
private const XPATH_CONFIG_ENABLE_CLEAR_SHOPPING_CART = 'checkout/cart/enable_clear_shopping_cart';
23+
24+
/**
25+
* @var ScopeConfigInterface
26+
*/
27+
private $_scopeConfig;
28+
29+
/**
30+
* Constructor
31+
*
32+
* @param Context $context
33+
*/
34+
public function __construct(
35+
Context $context
36+
) {
37+
$this->_scopeConfig = $context->getScopeConfig();
38+
}
39+
40+
/**
41+
* Check if clear shopping cart button is enabled
42+
*
43+
* @return bool
44+
*/
45+
public function isClearShoppingCartEnabled()
46+
{
47+
return (bool)$this->_scopeConfig->getValue(
48+
self::XPATH_CONFIG_ENABLE_CLEAR_SHOPPING_CART,
49+
ScopeInterface::SCOPE_WEBSITE
50+
);
51+
}
52+
}

app/code/Magento/Checkout/etc/adminhtml/system.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@
4848
<label>Show Cross-sell Items in the Shopping Cart</label>
4949
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
5050
</field>
51+
<field id="enable_clear_shopping_cart" translate="label" type="select" sortOrder="20" showInDefault="1" showInWebsite="1" canRestore="1">
52+
<label>Enable Clear Shopping Cart</label>
53+
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
54+
</field>
5155
</group>
5256
<group id="cart_link" translate="label" sortOrder="3" showInDefault="1" showInWebsite="1">
5357
<label>My Cart Link</label>

app/code/Magento/Checkout/etc/config.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
<redirect_to_cart>0</redirect_to_cart>
2020
<number_items_to_display_pager>20</number_items_to_display_pager>
2121
<crosssell_enabled>1</crosssell_enabled>
22+
<enable_clear_shopping_cart>0</enable_clear_shopping_cart>
2223
</cart>
2324
<cart_link>
2425
<use_qty>1</use_qty>

app/code/Magento/Checkout/i18n/en_US.csv

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,8 @@ Shipping,Shipping
153153
"Maximum Number of Items to Display in Order Summary","Maximum Number of Items to Display in Order Summary"
154154
"Quote Lifetime (days)","Quote Lifetime (days)"
155155
"After Adding a Product Redirect to Shopping Cart","After Adding a Product Redirect to Shopping Cart"
156+
"Enable Clear Shopping Cart","Enable Clear Shopping Cart"
157+
"Are you sure you want to remove all items from your shopping cart?","Are you sure you want to remove all items from your shopping cart?"
156158
"Number of Items to Display Pager","Number of Items to Display Pager"
157159
"My Cart Link","My Cart Link"
158160
"Display Cart Summary","Display Cart Summary"

app/code/Magento/Checkout/view/frontend/layout/checkout_cart_index.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,9 @@
181181
</block>
182182
</container>
183183
<block class="Magento\Checkout\Block\Cart\Grid" name="checkout.cart.form" as="cart-items" template="Magento_Checkout::cart/form.phtml" after="cart.summary">
184+
<arguments>
185+
<argument name="view_model" xsi:type="object">Magento\Checkout\ViewModel\Cart</argument>
186+
</arguments>
184187
<block class="Magento\Framework\View\Element\RendererList" name="checkout.cart.item.renderers" as="renderer.list"/>
185188
<block class="Magento\Framework\View\Element\Text\ListText" name="checkout.cart.order.actions"/>
186189
</block>

app/code/Magento/Checkout/view/frontend/templates/cart/form.phtml

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
class="form form-cart">
2121
<?= $block->getBlockHtml('formkey') ?>
2222
<div class="cart table-wrapper<?= $mergedCells == 2 ? ' detailed' : '' ?>">
23-
<?php if ($block->getPagerHtml()) :?>
23+
<?php if ($block->getPagerHtml()): ?>
2424
<div class="cart-products-toolbar cart-products-toolbar-top toolbar"
2525
data-attribute="cart-products-toolbar-top"><?= $block->getPagerHtml() ?>
2626
</div>
@@ -38,32 +38,34 @@
3838
<th class="col subtotal" scope="col"><span><?= $block->escapeHtml(__('Subtotal')) ?></span></th>
3939
</tr>
4040
</thead>
41-
<?php foreach ($block->getItems() as $_item) :?>
41+
<?php foreach ($block->getItems() as $_item): ?>
4242
<?= $block->getItemHtml($_item) ?>
4343
<?php endforeach ?>
4444
</table>
45-
<?php if ($block->getPagerHtml()) :?>
45+
<?php if ($block->getPagerHtml()): ?>
4646
<div class="cart-products-toolbar cart-products-toolbar-bottom toolbar"
4747
data-attribute="cart-products-toolbar-bottom"><?= $block->getPagerHtml() ?>
4848
</div>
4949
<?php endif ?>
5050
</div>
5151
<div class="cart main actions">
52-
<?php if ($block->getContinueShoppingUrl()) :?>
52+
<?php if ($block->getContinueShoppingUrl()): ?>
5353
<a class="action continue"
5454
href="<?= $block->escapeUrl($block->getContinueShoppingUrl()) ?>"
5555
title="<?= $block->escapeHtml(__('Continue Shopping')) ?>">
5656
<span><?= $block->escapeHtml(__('Continue Shopping')) ?></span>
5757
</a>
5858
<?php endif; ?>
59-
<button type="button"
60-
name="update_cart_action"
61-
data-cart-empty=""
62-
value="empty_cart"
63-
title="<?= $block->escapeHtml(__('Clear Shopping Cart')) ?>"
64-
class="action clear" id="empty_cart_button">
65-
<span><?= $block->escapeHtml(__('Clear Shopping Cart')) ?></span>
66-
</button>
59+
<?php if ($block->getViewModel()->isClearShoppingCartEnabled()): ?>
60+
<button type="button"
61+
name="update_cart_action"
62+
data-cart-empty=""
63+
value="empty_cart"
64+
title="<?= $block->escapeHtml(__('Clear Shopping Cart')) ?>"
65+
class="action clear" id="empty_cart_button">
66+
<span><?= $block->escapeHtml(__('Clear Shopping Cart')) ?></span>
67+
</button>
68+
<?php endif ?>
6769
<button type="submit"
6870
name="update_cart_action"
6971
data-cart-item-update=""
@@ -77,4 +79,3 @@
7779
</form>
7880
<?= $block->getChildHtml('checkout.cart.order.actions') ?>
7981
<?= $block->getChildHtml('shopping.cart.table.after') ?>
80-

0 commit comments

Comments
 (0)