Skip to content

Commit ee29f5f

Browse files
author
John Carlo Octabio
committed
magento#108: Clear Shopping Cart - Added admin configuration for display of clear shopping cart button
1 parent d57ff13 commit ee29f5f

File tree

4 files changed

+50
-23
lines changed

4 files changed

+50
-23
lines changed

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

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,6 @@ 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-
* Config settings path to enable clear shopping cart button
27-
*/
28-
const XPATH_CONFIG_ENABLE_CLEAR_SHOPPING_CART = 'checkout/cart/enable_clear_shopping_cart';
29-
3025
/**
3126
* @var \Magento\Quote\Model\ResourceModel\Quote\Item\Collection
3227
*/
@@ -107,7 +102,7 @@ protected function _construct()
107102
}
108103

109104
/**
110-
* @inheritdoc
105+
* {@inheritdoc}
111106
*
112107
* @since 100.2.0
113108
*/
@@ -152,7 +147,7 @@ public function getItemsForGrid()
152147
}
153148

154149
/**
155-
* @inheritdoc
150+
* {@inheritdoc}
156151
*
157152
* @since 100.2.0
158153
*/
@@ -166,8 +161,7 @@ public function getItems()
166161

167162
/**
168163
* Verify if display pager on shopping cart
169-
*
170-
* Check if cart block has custom_items and items qty in the shopping cart<limit from stores configuration
164+
* If cart block has custom_items and items qty in the shopping cart<limit from stores configuration
171165
*
172166
* @return bool
173167
*/
@@ -182,17 +176,4 @@ private function isPagerDisplayedOnPage()
182176
}
183177
return $this->isPagerDisplayed;
184178
}
185-
186-
/**
187-
* Check if clear shopping cart button is enabled
188-
*
189-
* @return bool
190-
*/
191-
public function isClearShoppingCartEnabled()
192-
{
193-
return (bool)$this->_scopeConfig->getValue(
194-
self::XPATH_CONFIG_ENABLE_CLEAR_SHOPPING_CART,
195-
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
196-
);
197-
}
198179
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
namespace Magento\Checkout\ViewModel;
3+
4+
use Magento\Framework\App\Config\ScopeConfigInterface;
5+
use Magento\Framework\View\Element\Block\ArgumentInterface;
6+
use Magento\Framework\View\Element\Context;
7+
8+
class Cart implements ArgumentInterface
9+
{
10+
/**
11+
* Config settings path to enable clear shopping cart button
12+
*/
13+
private const XPATH_CONFIG_ENABLE_CLEAR_SHOPPING_CART = 'checkout/cart/enable_clear_shopping_cart';
14+
15+
/**
16+
* @var ScopeConfigInterface
17+
*/
18+
private $_scopeConfig;
19+
20+
/**
21+
* Constructor
22+
*
23+
* @param Context $context
24+
*/
25+
public function __construct(
26+
Context $context
27+
) {
28+
$this->_scopeConfig = $context->getScopeConfig();
29+
}
30+
31+
/**
32+
* Check if clear shopping cart button is enabled
33+
*
34+
* @return bool
35+
*/
36+
public function isClearShoppingCartEnabled()
37+
{
38+
return (bool) $this->_scopeConfig->getValue(
39+
self::XPATH_CONFIG_ENABLE_CLEAR_SHOPPING_CART,
40+
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
41+
);
42+
}
43+
}

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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
<span><?= $block->escapeHtml(__('Continue Shopping')) ?></span>
5757
</a>
5858
<?php endif; ?>
59-
<?php if ($block->isClearShoppingCartEnabled()): ?>
59+
<?php if ($block->getViewModel()->isClearShoppingCartEnabled()): ?>
6060
<button type="button"
6161
name="update_cart_action"
6262
data-cart-empty=""

0 commit comments

Comments
 (0)