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

Created config used for showing/hiding clear cart button on the shopping cart view page. #27917

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
42 changes: 40 additions & 2 deletions app/code/Magento/Checkout/Block/Cart.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
namespace Magento\Checkout\Block;

use Magento\Customer\Model\Context;
use Magento\Store\Model\ScopeInterface;

/**
* Shopping cart block
Expand All @@ -14,6 +15,11 @@
*/
class Cart extends \Magento\Checkout\Block\Cart\AbstractCart
{
/**
* Config settings path to determine is clear cart action enabled
*/
public const XML_CONFIG_CLEAR_CART_ENABLED = 'checkout/cart/clear_cart_enabled';

/**
* @var \Magento\Catalog\Model\ResourceModel\Url
*/
Expand Down Expand Up @@ -68,7 +74,7 @@ protected function _construct()
}

/**
* prepare cart items URLs
* Prepare cart items URLs
*
* @return void
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
Expand Down Expand Up @@ -110,6 +116,8 @@ public function prepareItemUrls()
}

/**
* Checks is quote has error
*
* @codeCoverageIgnore
* @return bool
*/
Expand All @@ -119,6 +127,8 @@ public function hasError()
}

/**
* Returns quote items summary qty
*
* @codeCoverageIgnore
* @return int
*/
Expand All @@ -128,6 +138,8 @@ public function getItemsSummaryQty()
}

/**
* Checks is wishlist is active
*
* @codeCoverageIgnore
* @return bool
*/
Expand All @@ -137,7 +149,7 @@ public function isWishlistActive()
if ($isActive === null) {
$isActive = $this->_scopeConfig->getValue(
'wishlist/general/active',
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
ScopeInterface::SCOPE_STORE
) && $this->httpContext->getValue(
Context::CONTEXT_AUTH
);
Expand All @@ -147,6 +159,8 @@ public function isWishlistActive()
}

/**
* Returns checkout url
*
* @codeCoverageIgnore
* @return string
*/
Expand All @@ -156,6 +170,8 @@ public function getCheckoutUrl()
}

/**
* Returns continue shopping url
*
* @return string
*/
public function getContinueShoppingUrl()
Expand All @@ -172,6 +188,8 @@ public function getContinueShoppingUrl()
}

/**
* Checks is quote is virtual
*
* @return bool
* @codeCoverageIgnore
* @SuppressWarnings(PHPMD.BooleanGetMethodName)
Expand Down Expand Up @@ -227,6 +245,8 @@ public function getItems()
}

/**
* Returns quote items count
*
* @codeCoverageIgnore
* @return int
*/
Expand All @@ -245,4 +265,22 @@ public function getPagerHtml()
{
return $this->getChildHtml('pager');
}

/**
* Checks is clear cart action enabled
*
* @codeCoverageIgnore
* @return boolean
*/
public function isClearCartEnabled()
{
$isEnabled = $this->_getData('clear_cart_enabled');
if ($isEnabled === null) {
$isEnabled = $this->_scopeConfig->getValue(
self::XML_CONFIG_CLEAR_CART_ENABLED,
ScopeInterface::SCOPE_STORE
);
}
return $isEnabled;
}
}
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="AdminCheckoutClearCartEnabledActionGroup">
<annotations>
<description>Enable/disable showing clear shopping cart button on the cart page via checkout cart configuration.</description>
</annotations>
<arguments>
<argument name="value" type="string" defaultValue="Yes"/>
</arguments>
<scrollTo selector="{{AdminCheckoutConfigSection.clearCartEnabled}}" x="0" y="-100" stepKey="scrollToClearCartEnabled"/>
<uncheckOption selector="{{AdminCheckoutConfigSection.clearCartEnabledInherit}}" stepKey="uncheckUseSystem"/>
<selectOption selector="{{AdminCheckoutConfigSection.clearCartEnabled}}" userInput="{{value}}" stepKey="fillClearCartEnabled"/>
<click selector="{{AdminMainActionsSection.save}}" stepKey="clickSave"/>
<seeElement selector="{{AdminMessagesSection.success}}" stepKey="seeSuccessMessage"/>
</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>
<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="EnableClearCartButtonOnTheCartPage">
<data key="path">checkout/cart/clear_cart_enabled</data>
<data key="label">Display clear cart button on the cart page</data>
<data key="value">1</data>
</entity>
<entity name="DisableClearCartButtonOnTheCartPage">
<data key="path">checkout/cart/clear_cart_enabled</data>
<data key="label">Do not display clear cart button on the cart page</data>
<data key="value">0</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="clearCartEnabled" type="select" selector="#checkout_cart_clear_cart_enabled"/>
<element name="clearCartEnabledInherit" type="select" selector="#checkout_cart_clear_cart_enabled_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 -->
<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="StorefrontCheckRenderingClearCartButtonOnTheCartPageBasedOnStoresConfigurationTest">
<annotations>
<features value="Checkout"/>
<stories value="Shopping Cart"/>
<title value="Check rendering/not rendering clear cart button on the cart page based on checkout cart stores configuration"/>
<description value="Check rendering/not rendering clear 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 clear cart button on the cart page -->
<magentoCLI command="config:set {{DisableClearCartButtonOnTheCartPage.path}} {{DisableClearCartButtonOnTheCartPage.value}}" stepKey="disableClearCart"/>

<!-- 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="dontSeeClearCartButton"/>

<!-- 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 cart button -->
<actionGroup ref="AdminCheckoutClearCartEnabledActionGroup" stepKey="enableClearCartButton"/>

<!-- 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="SeeClearCartButton"/>
</test>
</tests>
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="clear_cart_enabled" translate="label" type="select" sortOrder="4" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
<label>Show "Clear Shopping Cart" button on the cart page</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>
<clear_cart_enabled>0</clear_cart_enabled>
</cart>
<cart_link>
<use_qty>1</use_qty>
Expand Down
3 changes: 2 additions & 1 deletion app/code/Magento/Checkout/i18n/en_US.csv
Original file line number Diff line number Diff line change
Expand Up @@ -182,4 +182,5 @@ Payment,Payment
"Items in Cart","Items in Cart"
"Close","Close"
"Show Cross-sell Items in the Shopping Cart","Show Cross-sell Items in the Shopping Cart"
"You added %1 to your <a href=""%2"">shopping cart</a>.","You added %1 to your <a href=""%2"">shopping cart</a>."
"You added %1 to your <a href=""%2"">shopping cart</a>.","You added %1 to your <a href=""%2"">shopping cart</a>."
"Show ""Clear Shopping Cart"" button on the cart page","Show ""Clear Shopping Cart"" button on the cart page"
26 changes: 14 additions & 12 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->isClearCartEnabled()): ?>
<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 Down
Original file line number Diff line number Diff line change
Expand Up @@ -1570,8 +1570,7 @@
margin-bottom: @indent__base;

.actions.main {
.continue,
.clear {
.continue {
display: none;
}
}
Expand Down