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

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>

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

Lines changed: 14 additions & 12 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->isClearCartEnabled()): ?>
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=""

app/design/frontend/Magento/luma/web/css/source/_extends.less

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1570,8 +1570,7 @@
15701570
margin-bottom: @indent__base;
15711571

15721572
.actions.main {
1573-
.continue,
1574-
.clear {
1573+
.continue {
15751574
display: none;
15761575
}
15771576
}

0 commit comments

Comments
 (0)