Skip to content

Commit 0ee9280

Browse files
committed
Created config used for showing/hiding clear cart button on the shopping cart view page. Modified styles in the luma theme which hide clear cart buton. Created functional test for testing showing/hiding clear cart button on the cart page.
1 parent 97f9b00 commit 0ee9280

File tree

12 files changed

+212
-16
lines changed

12 files changed

+212
-16
lines changed

app/code/Magento/Checkout/Block/Cart.php

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
namespace Magento\Checkout\Block;
77

88
use Magento\Customer\Model\Context;
9+
use Magento\Store\Model\ScopeInterface;
910

1011
/**
1112
* Shopping cart block
@@ -14,6 +15,11 @@
1415
*/
1516
class Cart extends \Magento\Checkout\Block\Cart\AbstractCart
1617
{
18+
/**
19+
* Config settings path to determine is clear cart action enabled
20+
*/
21+
public const XML_CONFIG_CLEAR_CART_ENABLED = 'checkout/cart/clear_cart_enabled';
22+
1723
/**
1824
* @var \Magento\Catalog\Model\ResourceModel\Url
1925
*/
@@ -68,7 +74,7 @@ protected function _construct()
6874
}
6975

7076
/**
71-
* prepare cart items URLs
77+
* Prepare cart items URLs
7278
*
7379
* @return void
7480
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
@@ -110,6 +116,8 @@ public function prepareItemUrls()
110116
}
111117

112118
/**
119+
* Checks is quote has error
120+
*
113121
* @codeCoverageIgnore
114122
* @return bool
115123
*/
@@ -119,6 +127,8 @@ public function hasError()
119127
}
120128

121129
/**
130+
* Returns quote items summary qty
131+
*
122132
* @codeCoverageIgnore
123133
* @return int
124134
*/
@@ -128,6 +138,8 @@ public function getItemsSummaryQty()
128138
}
129139

130140
/**
141+
* Checks is wishlist is active
142+
*
131143
* @codeCoverageIgnore
132144
* @return bool
133145
*/
@@ -137,7 +149,7 @@ public function isWishlistActive()
137149
if ($isActive === null) {
138150
$isActive = $this->_scopeConfig->getValue(
139151
'wishlist/general/active',
140-
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
152+
ScopeInterface::SCOPE_STORE
141153
) && $this->httpContext->getValue(
142154
Context::CONTEXT_AUTH
143155
);
@@ -147,6 +159,8 @@ public function isWishlistActive()
147159
}
148160

149161
/**
162+
* Returns checkout url
163+
*
150164
* @codeCoverageIgnore
151165
* @return string
152166
*/
@@ -156,6 +170,8 @@ public function getCheckoutUrl()
156170
}
157171

158172
/**
173+
* Returns continue shopping url
174+
*
159175
* @return string
160176
*/
161177
public function getContinueShoppingUrl()
@@ -172,6 +188,8 @@ public function getContinueShoppingUrl()
172188
}
173189

174190
/**
191+
* Checks is quote is virtual
192+
*
175193
* @return bool
176194
* @codeCoverageIgnore
177195
* @SuppressWarnings(PHPMD.BooleanGetMethodName)
@@ -227,6 +245,8 @@ public function getItems()
227245
}
228246

229247
/**
248+
* Returns quote items count
249+
*
230250
* @codeCoverageIgnore
231251
* @return int
232252
*/
@@ -245,4 +265,22 @@ public function getPagerHtml()
245265
{
246266
return $this->getChildHtml('pager');
247267
}
268+
269+
/**
270+
* Checks is clear cart action enabled
271+
*
272+
* @codeCoverageIgnore
273+
* @return boolean
274+
*/
275+
public function isClearCartEnabled()
276+
{
277+
$isEnabled = $this->_getData('clear_cart_enabled');
278+
if ($isEnabled === null) {
279+
$isEnabled = $this->_scopeConfig->getValue(
280+
self::XML_CONFIG_CLEAR_CART_ENABLED,
281+
ScopeInterface::SCOPE_STORE
282+
);
283+
}
284+
return $isEnabled;
285+
}
248286
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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="AdminCheckoutClearCartEnabledActionGroup">
12+
<annotations>
13+
<description>Enable/disable showing clear shopping cart button on the cart page via checkout cart configuration.</description>
14+
</annotations>
15+
<arguments>
16+
<argument name="value" type="string" defaultValue="Yes"/>
17+
</arguments>
18+
<scrollTo selector="{{AdminCheckoutConfigSection.clearCartEnabled}}" x="0" y="-100" stepKey="scrollToClearCartEnabled"/>
19+
<uncheckOption selector="{{AdminCheckoutConfigSection.clearCartEnabledInherit}}" stepKey="uncheckUseSystem"/>
20+
<selectOption selector="{{AdminCheckoutConfigSection.clearCartEnabled}}" userInput="{{value}}" stepKey="fillClearCartEnabled"/>
21+
<click selector="{{AdminMainActionsSection.save}}" stepKey="clickSave"/>
22+
<seeElement selector="{{AdminMessagesSection.success}}" stepKey="seeSuccessMessage"/>
23+
</actionGroup>
24+
</actionGroups>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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+
<arguments>
12+
<argument name="tabGroupAnchor" type="string" defaultValue=""/>
13+
</arguments>
14+
<amOnPage url="{{AdminCheckoutConfigPage.url(tabGroupAnchor)}}" stepKey="openCheckoutConfigPage"/>
15+
<waitForPageLoad stepKey="waitForCheckoutConfigPageLoad"/>
16+
</actionGroup>
17+
</actionGroups>
18+

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,4 +100,15 @@
100100
<data key="label">Display number of items in cart</data>
101101
<data key="value">0</data>
102102
</entity>
103+
104+
<entity name="EnableClearCartButtonOnTheCartPage">
105+
<data key="path">checkout/cart/clear_cart_enabled</data>
106+
<data key="label">Display clear cart button on the cart page</data>
107+
<data key="value">1</data>
108+
</entity>
109+
<entity name="DisableClearCartButtonOnTheCartPage">
110+
<data key="path">checkout/cart/clear_cart_enabled</data>
111+
<data key="label">Do not display clear cart button on the cart page</data>
112+
<data key="value">0</data>
113+
</entity>
103114
</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="clearCartEnabled" type="select" selector="#checkout_cart_clear_cart_enabled"/>
11+
<element name="clearCartEnabledInherit" type="select" selector="#checkout_cart_clear_cart_enabled_inherit"/>
12+
</section>
13+
</sections>

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
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" selector="#empty_cart_button" type="button"/>
5152
<!-- Required attention section -->
5253
<element name="removeProductBySku" type="button" selector="//div[contains(., '{{sku}}')]/ancestor::tbody//button" parameterized="true" timeout="30"/>
5354
<element name="failedItemBySku" type="block" selector="//div[contains(.,'{{sku}}')]/ancestor::tbody" parameterized="true" timeout="30"/>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
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="StorefrontCheckRenderingClearCartButtonOnTheCartPageBasedOnStoresConfigurationTest">
11+
<annotations>
12+
<features value="Checkout"/>
13+
<stories value="Shopping Cart"/>
14+
<title value="Check rendering/not rendering clear cart button on the cart page based on checkout cart stores configuration"/>
15+
<description value="Check rendering/not rendering clear cart button on the cart page based on checkout cart stores configuration"/>
16+
<severity value="MAJOR"/>
17+
<group value="shoppingCart"/>
18+
</annotations>
19+
20+
<before>
21+
<!-- Create simple product -->
22+
<createData entity="SimpleProduct2" stepKey="createProduct"/>
23+
</before>
24+
<after>
25+
<!-- Delete simple product -->
26+
<deleteData createDataKey="createProduct" stepKey="deleteProduct"/>
27+
28+
<!-- Disable rendering clear cart button on the cart page -->
29+
<magentoCLI command="config:set {{DisableClearCartButtonOnTheCartPage.path}} {{DisableClearCartButtonOnTheCartPage.value}}" stepKey="disableClearCart"/>
30+
31+
<!-- Log out -->
32+
<actionGroup ref="AdminLogoutActionGroup" stepKey="logout"/>
33+
</after>
34+
<!-- Add product to cart -->
35+
<actionGroup ref="OpenStoreFrontProductPageActionGroup" stepKey="openProductPage">
36+
<argument name="productUrlKey" value="$$createProduct.custom_attributes[url_key]$$"/>
37+
</actionGroup>
38+
<actionGroup ref="StorefrontAddProductToCartActionGroup" stepKey="addProductToCart">
39+
<argument name="product" value="$$createProduct$$"/>
40+
<argument name="productCount" value="1"/>
41+
</actionGroup>
42+
43+
<!-- Navigate to cart page -->
44+
<actionGroup ref="StorefrontOpenCartFromMinicartActionGroup" stepKey="openShoppingCart"/>
45+
<waitForPageLoad stepKey="waitForShoppingCartLoad" />
46+
47+
<!-- Assert that empty cart button is not rendered on the cart page -->
48+
<dontSeeElement selector="{{CheckoutCartProductSection.emptyCartButton}}" stepKey="dontSeeClearCartButton"/>
49+
50+
<!-- Open new browser's window and login as Admin -->
51+
<openNewTab stepKey="openNewTab"/>
52+
<actionGroup ref="AdminLoginActionGroup" stepKey="loginAsAdmin"/>
53+
54+
<!-- Navigate to checkout cart configuration -->
55+
<actionGroup ref="AdminOpenSalesCheckoutConfigPageActionGroup" stepKey="openCheckoutCartConfig">
56+
<argument name="tabGroupAnchor" value="#checkout_cart-link"/>
57+
</actionGroup>
58+
59+
<!-- Enable clear cart button -->
60+
<actionGroup ref="AdminCheckoutClearCartEnabledActionGroup" stepKey="enableClearCartButton"/>
61+
62+
<!-- Flush cache -->
63+
<magentoCLI command="cache:flush" stepKey="cacheFlush"/>
64+
65+
<!-- Back to the Cart page and refresh the page -->
66+
<switchToPreviousTab stepKey="switchToPreviousTab"/>
67+
<reloadPage stepKey="refreshPage"/>
68+
<waitForPageLoad stepKey="waitPageReload"/>
69+
70+
<!-- Assert that empty cart button is rendered on the cart page -->
71+
<seeElement selector="{{CheckoutCartProductSection.emptyCartButton}}" stepKey="SeeClearCartButton"/>
72+
</test>
73+
</tests>

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="clear_cart_enabled" translate="label" type="select" sortOrder="4" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
52+
<label>Show "Clear Shopping Cart" button on the cart page</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+
<clear_cart_enabled>0</clear_cart_enabled>
2223
</cart>
2324
<cart_link>
2425
<use_qty>1</use_qty>

0 commit comments

Comments
 (0)