Skip to content

Commit

Permalink
ENGCOM-7877: Added configuration to enable/disable Clear Shopping Car…
Browse files Browse the repository at this point in the history
…t action in storefront #28594

 - Merge Pull Request #28594 from joctabio/magento2:108_clear-shopping-cart-button-configuration
 - Merged commits:
   1. 0ee9280
   2. 077a2a5
   3. 4cf999c
   4. 53a22be
   5. 6d31101
   6. 70e3c15
   7. 05470d0
   8. e1fa935
   9. 2c4ee78
   10. 7dad27c
   11. c1ba0e0
   12. 0051ec9
   13. e9c6dd1
   14. d57ff13
   15. ee29f5f
   16. 888a9f3
   17. b960859
   18. e5724ef
   19. e8a36e7
   20. 3a097b2
   21. d8eeb97
   22. c8c9b9b
   23. 35a469b
   24. 09d6b10
   25. adfea2a
   26. b65a287
   27. 2f55801
   28. 418c6e8
   29. c5056cd
   30. f6574e4
   31. 893ac50
   32. c08f84b
   33. d7abed9
   34. 05e1e77
  • Loading branch information
magento-engcom-team committed Jul 24, 2020
2 parents 3008324 + 05e1e77 commit 4b54f3d
Show file tree
Hide file tree
Showing 18 changed files with 454 additions and 25 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?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">
<annotations>
<description>Goes to the Store Configuration > Sales > Checkout configuration page in admin.</description>
</annotations>
<arguments>
<argument name="tabGroupAnchor" type="string" defaultValue=""/>
</arguments>
<amOnPage url="{{AdminCheckoutConfigPage.url(tabGroupAnchor)}}" stepKey="openCheckoutConfigPage"/>
<waitForPageLoad stepKey="waitForCheckoutConfigPageLoad"/>
</actionGroup>
</actionGroups>

Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?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="AdminSelectClearShoppingCartConfigurationActionGroup">
<annotations>
<description>Enable/Disable clear shopping cart store configuration using UI.</description>
</annotations>
<arguments>
<argument name="value" type="string" defaultValue="{{EnableClearShoppingCart.textValue}}"/>
</arguments>
<waitForElementVisible selector="{{AdminCheckoutConfigSection.clearShoppingCartEnabledInherit}}" stepKey="waitForClearShoppingCartEnabledInherit" />
<uncheckOption selector="{{AdminCheckoutConfigSection.clearShoppingCartEnabledInherit}}" stepKey="uncheckUseSystem" />
<waitForElementVisible selector="{{AdminCheckoutConfigSection.clearShoppingCartEnabled}}" stepKey="waitForClearShoppingCartEnabled" />
<selectOption selector="{{AdminCheckoutConfigSection.clearShoppingCartEnabled}}" userInput="{{value}}" stepKey="fillClearShoppingCartEnabled" />
</actionGroup>
</actionGroups>
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?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="StorefrontClearShoppingCartActionGroup">
<annotations>
<description>Clicks the Clear Shopping Cart button on the storefront on the shopping cart page and verifies shopping cart gets emptied.</description>
</annotations>

<waitForElementVisible selector="{{CheckoutCartProductSection.emptyCartButton}}" stepKey="waitForEmptyCartButton"/>
<click selector="{{CheckoutCartProductSection.emptyCartButton}}" stepKey="clickEmptyCartButton"/>
<waitForElementVisible selector="{{CheckoutCartProductSection.modalMessage}}" stepKey="waitForModalMessage"/>
<waitForText selector="{{CheckoutCartProductSection.modalMessage}}" userInput="Are you sure you want to remove all items from your shopping cart?" stepKey="waitForTextModalMessage"/>
<waitForElementVisible selector="{{CheckoutCartProductSection.modalConfirmButton}}" stepKey="waitForModalConfirmButton"/>
<click selector="{{CheckoutCartProductSection.modalConfirmButton}}" stepKey="clickModalConfirmButton"/>
<waitForPageLoad stepKey="waitForPageLoad"/>
<seeCurrentUrlEquals url="{{_ENV.MAGENTO_BASE_URL}}checkout/cart" stepKey="seeCurrentUrlEqualsCartPage"/>
<waitForText selector="{{CheckoutCartMessageSection.emptyCartMessage}}" userInput="You have no items in your shopping cart." stepKey="waitForEmptyCartMessage"/>

</actionGroup>
</actionGroups>
13 changes: 13 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,17 @@
<data key="label">Display number of items in cart</data>
<data key="value">0</data>
</entity>

<entity name="EnableClearShoppingCart">
<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>
<data key="textValue">Yes</data>
</entity>
<entity name="DisableClearShoppingCart">
<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>
<data key="textValue">No</data>
</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" timeout="30"/>
<element name="clearShoppingCartEnabledInherit" type="select" selector="#checkout_cart_enable_clear_shopping_cart_inherit" timeout="30"/>
</section>
</sections>
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@
<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" type="button" selector="#empty_cart_button" timeout="30"/>
<element name="modalMessage" type="text" selector=".modal-popup.confirm._show .modal-content" timeout="30"/>
<element name="modalConfirmButton" type="button" selector=".modal-popup.confirm._show .action-accept" timeout="30"/>
<!-- Required attention section -->
<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,86 @@
<?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="ClearShoppingCartEnableDisableConfigurationTest">
<annotations>
<features value="Checkout"/>
<stories value="Shopping Cart"/>
<title value="Enable and Disable Clear Shopping Cart Configuration"/>
<description value="Verify that disabling the clear shopping cart store configuration will remove the clear shopping cart configuration button from the storefront's shopping cart page. Verify that enabling the configuration will add the button to the page and that the button functions as expected"/>
<group value="shoppingCart"/>
<severity value="MAJOR"/>
</annotations>
<before>
<!-- Create simple products and category -->
<createData entity="_defaultCategory" stepKey="createCategory"/>
<createData entity="SimpleProduct" stepKey="createProduct1">
<requiredEntity createDataKey="createCategory"/>
</createData>
<createData entity="SimpleProduct" stepKey="createProduct2">
<requiredEntity createDataKey="createCategory"/>
</createData>

<actionGroup ref="AdminLoginActionGroup" stepKey="loginAsAdmin"/>
</before>
<after>
<deleteData createDataKey="createCategory" stepKey="deleteCategory"/>
<deleteData createDataKey="createProduct1" stepKey="deleteProduct1"/>
<deleteData createDataKey="createProduct2" stepKey="deleteProduct2"/>

<!-- Disable clear shopping cart -->
<magentoCLI command="config:set {{DisableClearShoppingCart.path}} {{DisableClearShoppingCart.value}}" stepKey="disableClearShoppingCart"/>
<actionGroup ref="AdminLogoutActionGroup" stepKey="logout"/>
</after>

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

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

<!-- Open product 1 and add to cart -->
<actionGroup ref="StorefrontOpenProductEntityPageActionGroup" stepKey="openProduct1Page1">
<argument name="product" value="$$createProduct1$$"/>
</actionGroup>
<actionGroup ref="StorefrontAddToTheCartActionGroup" stepKey="product1AddToCart"/>

<!-- Open product 2 and add to cart -->
<actionGroup ref="StorefrontOpenProductEntityPageActionGroup" stepKey="openProduct2Page">
<argument name="product" value="$$createProduct2$$"/>
</actionGroup>
<actionGroup ref="StorefrontAddToTheCartActionGroup" stepKey="product2AddToCart"/>

<!-- Go to shopping cart page -->
<actionGroup ref="StorefrontCartPageOpenActionGroup" stepKey="openShoppingCartPage1"/>

<!-- Clear shopping cart -->
<actionGroup ref="StorefrontClearShoppingCartActionGroup" stepKey="clearShoppingCart"/>
<actionGroup ref="AssertMiniCartEmptyActionGroup" stepKey="assertMiniCartEmpty"/>

<!-- Return to Admin to disable clear shopping cart -->
<actionGroup ref="AdminOpenSalesCheckoutConfigPageActionGroup" stepKey="openSalesCheckoutCartConfig2"/>
<actionGroup ref="AdminSelectClearShoppingCartConfigurationActionGroup" stepKey="disableClearShoppingCartButton">
<argument name="value" value="{{DisableClearShoppingCart.textValue}}"/>
</actionGroup>
<actionGroup ref="SaveStoreConfigurationActionGroup" stepKey="saveStoreConfiguration2"/>

<!-- Open product 1 page and add to cart -->
<actionGroup ref="StorefrontOpenProductEntityPageActionGroup" stepKey="openProduct1Page2">
<argument name="product" value="$$createProduct1$$"/>
</actionGroup>
<actionGroup ref="StorefrontAddToTheCartActionGroup" stepKey="product1AddToCart2"/>

<!-- Go to shopping cart and assert clear shopping cart button is not rendered in UI -->
<actionGroup ref="StorefrontCartPageOpenActionGroup" stepKey="openShoppingCartPage2"/>
<dontSeeElementInDOM selector="{{CheckoutCartProductSection.emptyCartButton}}" stepKey="dontSeeElementEmptyCartButton"/>
</test>
</tests>
52 changes: 52 additions & 0 deletions app/code/Magento/Checkout/ViewModel/Cart.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?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;

/**
* Cart form view model.
*/
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()
{
return (bool)$this->_scopeConfig->getValue(
self::XPATH_CONFIG_ENABLE_CLEAR_SHOPPING_CART,
ScopeInterface::SCOPE_WEBSITE
);
}
}
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" canRestore="1">
<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?"
"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') ?>

Loading

0 comments on commit 4b54f3d

Please sign in to comment.