Skip to content

Commit 4cf999c

Browse files
author
John Carlo Octabio
committed
magento/partners-magento2b2b#108: Clear Shopping Cart - Added admin configuration for display of clear shopping cart button
1 parent 63a6786 commit 4cf999c

File tree

7 files changed

+42
-10864
lines changed

7 files changed

+42
-10864
lines changed

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ class Grid extends \Magento\Checkout\Block\Cart
2222
*/
2323
const XPATH_CONFIG_NUMBER_ITEMS_TO_DISPLAY_PAGER = 'checkout/cart/number_items_to_display_pager';
2424

25+
/**
26+
* Default display setting for clear shopping cart button
27+
*/
28+
const XPATH_CONFIG_ENABLE_CLEAR_SHOPPING_CART = 'checkout/cart/enable_clear_shopping_cart';
29+
2530
/**
2631
* @var \Magento\Quote\Model\ResourceModel\Quote\Item\Collection
2732
*/
@@ -174,4 +179,17 @@ private function isPagerDisplayedOnPage()
174179
}
175180
return $this->isPagerDisplayed;
176181
}
182+
183+
/**
184+
* Check if clear shopping cart button is enabled
185+
*
186+
* @return bool
187+
*/
188+
public function isClearShoppingCartEnabled()
189+
{
190+
return (bool) $this->_scopeConfig->getValue(
191+
self::XPATH_CONFIG_ENABLE_CLEAR_SHOPPING_CART,
192+
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
193+
);
194+
}
177195
}

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" showInStore="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: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ 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"
156157
"Number of Items to Display Pager","Number of Items to Display Pager"
157158
"My Cart Link","My Cart Link"
158159
"Display Cart Summary","Display Cart Summary"

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

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,16 @@
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->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=""

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1570,10 +1570,16 @@
15701570
margin-bottom: @indent__base;
15711571

15721572
.actions.main {
1573-
.continue,
1574-
.clear {
1573+
.continue {
15751574
display: none;
15761575
}
1576+
1577+
.clear {
1578+
.lib-button-as-link(
1579+
@_margin: 0 @indent__base 0 0
1580+
);
1581+
font-weight: @font-weight__regular;
1582+
}
15771583
}
15781584
}
15791585
}

0 commit comments

Comments
 (0)