Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added configuration to enable/disable Clear Shopping Cart action in storefront #28594

Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
0ee9280
Created config used for showing/hiding clear cart button on the shopp…
Neos2007 Apr 21, 2020
077a2a5
config-clear-cart-action: Added translation for clear shopping cart b…
Neos2007 Jun 1, 2020
4cf999c
magento/partners-magento2b2b#108: Clear Shopping Cart - Added admin c…
Jun 5, 2020
53a22be
magento/magento2#108: Clear Shopping Cart - Implemented Clear Shoppin…
Jun 5, 2020
6d31101
Merge branch '108_clear-shopping-cart-button-configuration' of github…
Jun 5, 2020
70e3c15
magento/magento2#108: Clear Shopping Cart - Refactor doc for enable_c…
Jun 5, 2020
05470d0
magento/magento2#108: Clear Shopping Cart - Remove unnecessary empty …
Jun 5, 2020
e1fa935
magento/magento2#108: Clear Shopping Cart - Restore removed composer.…
Jun 8, 2020
2c4ee78
Merge branch 'pull-27917' into 108_clear-shopping-cart-button-configu…
Jun 9, 2020
7dad27c
magento/magento2#108: Clear Shopping Cart - Refactor to fix Static Te…
Jun 9, 2020
c1ba0e0
magento/magento2#108: Clear Shopping Cart - Refactor to fix expected …
Jun 9, 2020
0051ec9
magento/magento2#108: Clear Shopping Cart - Refactor _clearCartConfir…
Jun 9, 2020
e9c6dd1
magento/magento2#108: Clear Shopping Cart - Add RWD styling to cart a…
Jun 10, 2020
d57ff13
magento/magento2#108: Clear Shopping Cart - Refactor PHPdoc to fix Co…
Jun 10, 2020
ee29f5f
magento/magento2#108: Clear Shopping Cart - Added admin configuration…
Jun 24, 2020
888a9f3
magento/magento2#108: Clear Shopping Cart - Refactor initial changes …
Jun 24, 2020
b960859
magento/magento2#108: Clear Shopping Cart - Added file header copyright
Jun 24, 2020
e5724ef
Merge branch '2.4-develop' into 108_clear-shopping-cart-button-config…
danmooney2 Jul 7, 2020
e8a36e7
magento/magento2#108: Clear Shopping Cart - Refactor MFTF to include …
Jul 14, 2020
3a097b2
Merge branch '108_clear-shopping-cart-button-configuration' of github…
Jul 14, 2020
d8eeb97
magento/magento2#108: Clear Shopping Cart - Refactor MFTF to include …
Jul 14, 2020
c8c9b9b
Merge branch '2.4-develop' into 108_clear-shopping-cart-button-config…
danmooney2 Jul 14, 2020
35a469b
magento/magento2#108: Clear Shopping Cart - Updated MFTF for code rev…
Jul 20, 2020
09d6b10
Merge branch '108_clear-shopping-cart-button-configuration' of github…
Jul 20, 2020
adfea2a
magento/magento2#108: Clear Shopping Cart - Updated config scope to w…
Jul 20, 2020
b65a287
magento/magento2#108: Clear Shopping Cart - Added integration test fo…
Jul 21, 2020
2f55801
Merge branch '2.4-develop' into 108_clear-shopping-cart-button-config…
joanhe Jul 21, 2020
418c6e8
magento/magento2#108: Clear Shopping Cart - Refactor MFTF and PHP fil…
Jul 22, 2020
c5056cd
Merge branch '108_clear-shopping-cart-button-configuration' of github…
Jul 22, 2020
f6574e4
magento/magento2#108: Clear Shopping Cart - Refactor integration test…
Jul 23, 2020
893ac50
Merge branch '2.4-develop' into 108_clear-shopping-cart-button-config…
joctabio Jul 23, 2020
c08f84b
Merge branch '2.4-develop' into 108_clear-shopping-cart-button-config…
joanhe Jul 23, 2020
d7abed9
magento/magento2#108: Clear Shopping Cart - Update translation file f…
Jul 24, 2020
05e1e77
Merge branch '108_clear-shopping-cart-button-configuration' of github…
Jul 24, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->

<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
<actionGroup name="AdminCheckoutClearShoppingCartEnabledActionGroup">
dhaecker marked this conversation as resolved.
Show resolved Hide resolved
<annotations>
<description>Enable/disable display of clear shopping cart button on the cart page via checkout cart configuration.</description>
dhaecker marked this conversation as resolved.
Show resolved Hide resolved
</annotations>
<arguments>
<argument name="value" type="string" defaultValue="Yes"/>
dhaecker marked this conversation as resolved.
Show resolved Hide resolved
</arguments>
<scrollTo selector="{{AdminCheckoutConfigSection.clearShoppingCartEnabled}}" x="0" y="-100" stepKey="scrollToClearShoppingCartEnabled"/>
dhaecker marked this conversation as resolved.
Show resolved Hide resolved
<uncheckOption selector="{{AdminCheckoutConfigSection.clearShoppingCartEnabledInherit}}" stepKey="uncheckUseSystem"/>
dhaecker marked this conversation as resolved.
Show resolved Hide resolved
<selectOption selector="{{AdminCheckoutConfigSection.clearShoppingCartEnabled}}" userInput="{{value}}" stepKey="fillClearShoppingCartEnabled"/>
dhaecker marked this conversation as resolved.
Show resolved Hide resolved
<click selector="{{AdminMainActionsSection.save}}" stepKey="clickSave"/>
dhaecker marked this conversation as resolved.
Show resolved Hide resolved
<seeElement selector="{{AdminMessagesSection.success}}" stepKey="seeSuccessMessage"/>
dhaecker marked this conversation as resolved.
Show resolved Hide resolved
</actionGroup>
</actionGroups>
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
<actionGroup name="AdminOpenSalesCheckoutConfigPageActionGroup">
<arguments>
dhaecker marked this conversation as resolved.
Show resolved Hide resolved
<argument name="tabGroupAnchor" type="string" defaultValue=""/>
</arguments>
<amOnPage url="{{AdminCheckoutConfigPage.url(tabGroupAnchor)}}" stepKey="openCheckoutConfigPage"/>
<waitForPageLoad stepKey="waitForCheckoutConfigPageLoad"/>
</actionGroup>
</actionGroups>

11 changes: 11 additions & 0 deletions app/code/Magento/Checkout/Test/Mftf/Data/ConfigData.xml
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,15 @@
<data key="label">Display number of items in cart</data>
<data key="value">0</data>
</entity>

<entity name="EnableClearShoppingCartButtonOnTheCartPage">
<data key="path">checkout/cart/enable_clear_shopping_cart</data>
<data key="label">Display clear shopping cart button on the cart page</data>
<data key="value">1</data>
dhaecker marked this conversation as resolved.
Show resolved Hide resolved
</entity>
<entity name="DisableClearShoppingCartButtonOnTheCartPage">
<data key="path">checkout/cart/enable_clear_shopping_cart</data>
<data key="label">Do not display clear shopping cart button on the cart page</data>
<data key="value">0</data>
dhaecker marked this conversation as resolved.
Show resolved Hide resolved
</entity>
</entities>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<pages xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:mftf:Page/etc/PageObject.xsd">
<page name="AdminCheckoutConfigPage" url="admin/system_config/edit/section/checkout/{{tabLink}}" area="admin" parameterized="true" module="Magento_Checkout">
<section name="AdminCheckoutConfigSection"/>
</page>
</pages>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<sections xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:mftf:Page/etc/SectionObject.xsd">
<section name="AdminCheckoutConfigSection">
<element name="clearShoppingCartEnabled" type="select" selector="#checkout_cart_enable_clear_shopping_cart"/>
dhaecker marked this conversation as resolved.
Show resolved Hide resolved
<element name="clearShoppingCartEnabledInherit" type="select" selector="#checkout_cart_enable_clear_shopping_cart_inherit"/>
</section>
</sections>
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
<element name="checkoutCartProductPrice" type="text" selector="//td[@class='col price']//span[@class='price']"/>
<element name="checkoutCartSubtotal" type="text" selector="//td[@class='col subtotal']//span[@class='price']"/>
<element name="emptyCart" selector=".cart-empty" type="text"/>
<element name="emptyCartButton" selector="#empty_cart_button" type="button"/>
<!-- Required attention section -->
dhaecker marked this conversation as resolved.
Show resolved Hide resolved
<element name="removeProductBySku" type="button" selector="//div[contains(., '{{sku}}')]/ancestor::tbody//button" parameterized="true" timeout="30"/>
<element name="failedItemBySku" type="block" selector="//div[contains(.,'{{sku}}')]/ancestor::tbody" parameterized="true" timeout="30"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
<test name="StorefrontCheckRenderingClearShoppingCartButtonOnTheCartPageBasedOnStoresConfigurationTest">
<annotations>
<features value="Checkout"/>
<stories value="Shopping Cart"/>
<title value="Check display render of clear shopping cart button on the cart page based on checkout cart stores configuration"/>
<description value="Check display render of clear shopping cart button on the cart page based on checkout cart stores configuration"/>
<severity value="MAJOR"/>
<group value="shoppingCart"/>
</annotations>

<before>
<!-- Create simple product -->
<createData entity="SimpleProduct2" stepKey="createProduct"/>
</before>
<after>
<!-- Delete simple product -->
<deleteData createDataKey="createProduct" stepKey="deleteProduct"/>

<!-- Disable rendering of clear shopping cart button on the cart page -->
<magentoCLI command="config:set {{DisableClearShoppingCartButtonOnTheCartPage.path}} {{DisableClearShoppingCartButtonOnTheCartPage.value}}" stepKey="disableClearShoppingCart"/>

<!-- Log out -->
<actionGroup ref="AdminLogoutActionGroup" stepKey="logout"/>
</after>
<!-- Add product to cart -->
<actionGroup ref="OpenStoreFrontProductPageActionGroup" stepKey="openProductPage">
<argument name="productUrlKey" value="$$createProduct.custom_attributes[url_key]$$"/>
</actionGroup>
<actionGroup ref="StorefrontAddProductToCartActionGroup" stepKey="addProductToCart">
<argument name="product" value="$$createProduct$$"/>
<argument name="productCount" value="1"/>
</actionGroup>

<!-- Navigate to cart page -->
<actionGroup ref="StorefrontOpenCartFromMinicartActionGroup" stepKey="openShoppingCart"/>
<waitForPageLoad stepKey="waitForShoppingCartLoad" />

<!-- Assert that empty cart button is not rendered on the cart page -->
<dontSeeElement selector="{{CheckoutCartProductSection.emptyCartButton}}" stepKey="dontSeeClearShoppingCartButton"/>

<!-- Open new browser's window and login as Admin -->
<openNewTab stepKey="openNewTab"/>
<actionGroup ref="AdminLoginActionGroup" stepKey="loginAsAdmin"/>

<!-- Navigate to checkout cart configuration -->
<actionGroup ref="AdminOpenSalesCheckoutConfigPageActionGroup" stepKey="openCheckoutCartConfig">
<argument name="tabGroupAnchor" value="#checkout_cart-link"/>
</actionGroup>

<!-- Enable clear shopping cart button -->
<actionGroup ref="AdminCheckoutClearShoppingCartEnabledActionGroup" stepKey="enableClearShoppingCartButton"/>

<!-- Flush cache -->
<magentoCLI command="cache:flush" stepKey="cacheFlush"/>

<!-- Back to the Cart page and refresh the page -->
<switchToPreviousTab stepKey="switchToPreviousTab"/>
<reloadPage stepKey="refreshPage"/>
<waitForPageLoad stepKey="waitPageReload"/>

<!-- Assert that empty cart button is rendered on the cart page -->
<seeElement selector="{{CheckoutCartProductSection.emptyCartButton}}" stepKey="SeeClearShoppingCartButton"/>
joanhe marked this conversation as resolved.
Show resolved Hide resolved
</test>
</tests>
49 changes: 49 additions & 0 deletions app/code/Magento/Checkout/ViewModel/Cart.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\Checkout\ViewModel;

use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\View\Element\Block\ArgumentInterface;
use Magento\Framework\View\Element\Context;
use Magento\Store\Model\ScopeInterface;

class Cart implements ArgumentInterface
{
/**
* Config settings path to enable clear shopping cart button
*/
private const XPATH_CONFIG_ENABLE_CLEAR_SHOPPING_CART = 'checkout/cart/enable_clear_shopping_cart';

/**
* @var ScopeConfigInterface
*/
private $_scopeConfig;

/**
* Constructor
*
* @param Context $context
*/
public function __construct(
Context $context
) {
$this->_scopeConfig = $context->getScopeConfig();
}

/**
* Check if clear shopping cart button is enabled
*
* @return bool
*/
public function isClearShoppingCartEnabled()
joanhe marked this conversation as resolved.
Show resolved Hide resolved
{
return (bool) $this->_scopeConfig->getValue(
self::XPATH_CONFIG_ENABLE_CLEAR_SHOPPING_CART,
ScopeInterface::SCOPE_STORE
joanhe marked this conversation as resolved.
Show resolved Hide resolved
);
}
}
4 changes: 4 additions & 0 deletions app/code/Magento/Checkout/etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@
<label>Show Cross-sell Items in the Shopping Cart</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
<field id="enable_clear_shopping_cart" translate="label" type="select" sortOrder="20" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
joanhe marked this conversation as resolved.
Show resolved Hide resolved
<label>Enable Clear Shopping Cart</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
</group>
<group id="cart_link" translate="label" sortOrder="3" showInDefault="1" showInWebsite="1">
<label>My Cart Link</label>
Expand Down
1 change: 1 addition & 0 deletions app/code/Magento/Checkout/etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<redirect_to_cart>0</redirect_to_cart>
<number_items_to_display_pager>20</number_items_to_display_pager>
<crosssell_enabled>1</crosssell_enabled>
<enable_clear_shopping_cart>0</enable_clear_shopping_cart>
</cart>
<cart_link>
<use_qty>1</use_qty>
Expand Down
2 changes: 2 additions & 0 deletions app/code/Magento/Checkout/i18n/en_US.csv
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ Shipping,Shipping
"Maximum Number of Items to Display in Order Summary","Maximum Number of Items to Display in Order Summary"
"Quote Lifetime (days)","Quote Lifetime (days)"
"After Adding a Product Redirect to Shopping Cart","After Adding a Product Redirect to Shopping Cart"
"Enable Clear Shopping Cart","Enable Clear Shopping Cart"
"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?"
joanhe marked this conversation as resolved.
Show resolved Hide resolved
"Number of Items to Display Pager","Number of Items to Display Pager"
"My Cart Link","My Cart Link"
"Display Cart Summary","Display Cart Summary"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,9 @@
</block>
</container>
<block class="Magento\Checkout\Block\Cart\Grid" name="checkout.cart.form" as="cart-items" template="Magento_Checkout::cart/form.phtml" after="cart.summary">
<arguments>
<argument name="view_model" xsi:type="object">Magento\Checkout\ViewModel\Cart</argument>
</arguments>
<block class="Magento\Framework\View\Element\RendererList" name="checkout.cart.item.renderers" as="renderer.list"/>
<block class="Magento\Framework\View\Element\Text\ListText" name="checkout.cart.order.actions"/>
</block>
Expand Down
27 changes: 14 additions & 13 deletions app/code/Magento/Checkout/view/frontend/templates/cart/form.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
class="form form-cart">
<?= $block->getBlockHtml('formkey') ?>
<div class="cart table-wrapper<?= $mergedCells == 2 ? ' detailed' : '' ?>">
<?php if ($block->getPagerHtml()) :?>
<?php if ($block->getPagerHtml()): ?>
<div class="cart-products-toolbar cart-products-toolbar-top toolbar"
data-attribute="cart-products-toolbar-top"><?= $block->getPagerHtml() ?>
</div>
Expand All @@ -38,32 +38,34 @@
<th class="col subtotal" scope="col"><span><?= $block->escapeHtml(__('Subtotal')) ?></span></th>
</tr>
</thead>
<?php foreach ($block->getItems() as $_item) :?>
<?php foreach ($block->getItems() as $_item): ?>
<?= $block->getItemHtml($_item) ?>
<?php endforeach ?>
</table>
<?php if ($block->getPagerHtml()) :?>
<?php if ($block->getPagerHtml()): ?>
<div class="cart-products-toolbar cart-products-toolbar-bottom toolbar"
data-attribute="cart-products-toolbar-bottom"><?= $block->getPagerHtml() ?>
</div>
<?php endif ?>
</div>
<div class="cart main actions">
<?php if ($block->getContinueShoppingUrl()) :?>
<?php if ($block->getContinueShoppingUrl()): ?>
<a class="action continue"
href="<?= $block->escapeUrl($block->getContinueShoppingUrl()) ?>"
title="<?= $block->escapeHtml(__('Continue Shopping')) ?>">
<span><?= $block->escapeHtml(__('Continue Shopping')) ?></span>
</a>
<?php endif; ?>
<button type="button"
name="update_cart_action"
data-cart-empty=""
value="empty_cart"
title="<?= $block->escapeHtml(__('Clear Shopping Cart')) ?>"
class="action clear" id="empty_cart_button">
<span><?= $block->escapeHtml(__('Clear Shopping Cart')) ?></span>
</button>
<?php if ($block->getViewModel()->isClearShoppingCartEnabled()): ?>
<button type="button"
name="update_cart_action"
data-cart-empty=""
value="empty_cart"
title="<?= $block->escapeHtml(__('Clear Shopping Cart')) ?>"
class="action clear" id="empty_cart_button">
<span><?= $block->escapeHtml(__('Clear Shopping Cart')) ?></span>
</button>
<?php endif ?>
<button type="submit"
name="update_cart_action"
data-cart-item-update=""
Expand All @@ -77,4 +79,3 @@
</form>
<?= $block->getChildHtml('checkout.cart.order.actions') ?>
<?= $block->getChildHtml('shopping.cart.table.after') ?>

48 changes: 39 additions & 9 deletions app/code/Magento/Checkout/view/frontend/web/js/shopping-cart.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@

define([
'jquery',
'jquery-ui-modules/widget'
], function ($) {
'Magento_Ui/js/modal/confirm',
'jquery-ui-modules/widget',
'mage/translate'
], function ($, confirm) {
'use strict';

$.widget('mage.shoppingCart', {
Expand All @@ -15,13 +17,7 @@ define([
var items, i, reload;

$(this.options.emptyCartButton).on('click', $.proxy(function () {
$(this.options.emptyCartButton).attr('name', 'update_cart_action_temp');
$(this.options.updateCartActionContainer)
.attr('name', 'update_cart_action').attr('value', 'empty_cart');

if ($(this.options.emptyCartButton).parents('form').length > 0) {
$(this.options.emptyCartButton).parents('form').submit();
}
this._confirmClearCart();
}, this));
items = $.find('[data-role="cart-item-qty"]');

Expand Down Expand Up @@ -61,6 +57,40 @@ define([
$('div.block.block-minicart').off('dropdowndialogclose');
}));
}, this));
},

/**
* Display confirmation modal for clearing the cart
* @private
*/
_confirmClearCart: function () {
var self = this;

confirm({
content: $.mage.__('Are you sure you want to remove all items from your shopping cart?'),
actions: {
/**
* Confirmation modal handler to execute clear cart action
*/
confirm: function () {
self.clearCart();
}
}
});
},

/**
* Prepares the form and submit to clear the cart
* @public
*/
clearCart: function () {
$(this.options.emptyCartButton).attr('name', 'update_cart_action_temp');
$(this.options.updateCartActionContainer)
.attr('name', 'update_cart_action').attr('value', 'empty_cart');

if ($(this.options.emptyCartButton).parents('form').length > 0) {
$(this.options.emptyCartButton).parents('form').submit();
}
}
});

Expand Down
Loading