diff --git a/app/code/Magento/Checkout/Block/Cart.php b/app/code/Magento/Checkout/Block/Cart.php index 7940c37917624..80c342803d154 100644 --- a/app/code/Magento/Checkout/Block/Cart.php +++ b/app/code/Magento/Checkout/Block/Cart.php @@ -6,6 +6,7 @@ namespace Magento\Checkout\Block; use Magento\Customer\Model\Context; +use Magento\Store\Model\ScopeInterface; /** * Shopping cart block @@ -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 */ @@ -68,7 +74,7 @@ protected function _construct() } /** - * prepare cart items URLs + * Prepare cart items URLs * * @return void * @SuppressWarnings(PHPMD.CyclomaticComplexity) @@ -110,6 +116,8 @@ public function prepareItemUrls() } /** + * Checks is quote has error + * * @codeCoverageIgnore * @return bool */ @@ -119,6 +127,8 @@ public function hasError() } /** + * Returns quote items summary qty + * * @codeCoverageIgnore * @return int */ @@ -128,6 +138,8 @@ public function getItemsSummaryQty() } /** + * Checks is wishlist is active + * * @codeCoverageIgnore * @return bool */ @@ -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 ); @@ -147,6 +159,8 @@ public function isWishlistActive() } /** + * Returns checkout url + * * @codeCoverageIgnore * @return string */ @@ -156,6 +170,8 @@ public function getCheckoutUrl() } /** + * Returns continue shopping url + * * @return string */ public function getContinueShoppingUrl() @@ -172,6 +188,8 @@ public function getContinueShoppingUrl() } /** + * Checks is quote is virtual + * * @return bool * @codeCoverageIgnore * @SuppressWarnings(PHPMD.BooleanGetMethodName) @@ -227,6 +245,8 @@ public function getItems() } /** + * Returns quote items count + * * @codeCoverageIgnore * @return int */ @@ -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; + } } diff --git a/app/code/Magento/Checkout/Test/Mftf/ActionGroup/AdminCheckoutClearCartEnabledActionGroup.xml b/app/code/Magento/Checkout/Test/Mftf/ActionGroup/AdminCheckoutClearCartEnabledActionGroup.xml new file mode 100644 index 0000000000000..81e021a180563 --- /dev/null +++ b/app/code/Magento/Checkout/Test/Mftf/ActionGroup/AdminCheckoutClearCartEnabledActionGroup.xml @@ -0,0 +1,24 @@ + + + + + + + Enable/disable showing clear shopping cart button on the cart page via checkout cart configuration. + + + + + + + + + + + diff --git a/app/code/Magento/Checkout/Test/Mftf/ActionGroup/AdminOpenSalesCheckoutConfigPageActionGroup.xml b/app/code/Magento/Checkout/Test/Mftf/ActionGroup/AdminOpenSalesCheckoutConfigPageActionGroup.xml new file mode 100644 index 0000000000000..cf1e2c51fb980 --- /dev/null +++ b/app/code/Magento/Checkout/Test/Mftf/ActionGroup/AdminOpenSalesCheckoutConfigPageActionGroup.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + diff --git a/app/code/Magento/Checkout/Test/Mftf/Data/ConfigData.xml b/app/code/Magento/Checkout/Test/Mftf/Data/ConfigData.xml index bb47a2fcc3070..7f06b188c4414 100644 --- a/app/code/Magento/Checkout/Test/Mftf/Data/ConfigData.xml +++ b/app/code/Magento/Checkout/Test/Mftf/Data/ConfigData.xml @@ -100,4 +100,15 @@ Display number of items in cart 0 + + + checkout/cart/clear_cart_enabled + Display clear cart button on the cart page + 1 + + + checkout/cart/clear_cart_enabled + Do not display clear cart button on the cart page + 0 + diff --git a/app/code/Magento/Checkout/Test/Mftf/Page/AdminCheckoutConfigPage.xml b/app/code/Magento/Checkout/Test/Mftf/Page/AdminCheckoutConfigPage.xml new file mode 100644 index 0000000000000..21d69a1ad93c7 --- /dev/null +++ b/app/code/Magento/Checkout/Test/Mftf/Page/AdminCheckoutConfigPage.xml @@ -0,0 +1,12 @@ + + + + +
+ + diff --git a/app/code/Magento/Checkout/Test/Mftf/Section/AdminCheckoutConfigSection.xml b/app/code/Magento/Checkout/Test/Mftf/Section/AdminCheckoutConfigSection.xml new file mode 100644 index 0000000000000..ea17672706fa2 --- /dev/null +++ b/app/code/Magento/Checkout/Test/Mftf/Section/AdminCheckoutConfigSection.xml @@ -0,0 +1,13 @@ + + + +
+ + +
+
diff --git a/app/code/Magento/Checkout/Test/Mftf/Section/CheckoutCartProductSection.xml b/app/code/Magento/Checkout/Test/Mftf/Section/CheckoutCartProductSection.xml index af9d81249e8ac..a531f85c81304 100644 --- a/app/code/Magento/Checkout/Test/Mftf/Section/CheckoutCartProductSection.xml +++ b/app/code/Magento/Checkout/Test/Mftf/Section/CheckoutCartProductSection.xml @@ -48,6 +48,7 @@ + diff --git a/app/code/Magento/Checkout/Test/Mftf/Test/StorefrontCheckRenderingClearCartButtonOnTheCartPageBasedOnStoresConfigurationTest.xml b/app/code/Magento/Checkout/Test/Mftf/Test/StorefrontCheckRenderingClearCartButtonOnTheCartPageBasedOnStoresConfigurationTest.xml new file mode 100644 index 0000000000000..794477eec39a4 --- /dev/null +++ b/app/code/Magento/Checkout/Test/Mftf/Test/StorefrontCheckRenderingClearCartButtonOnTheCartPageBasedOnStoresConfigurationTest.xml @@ -0,0 +1,73 @@ + + + + + + + + + <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> diff --git a/app/code/Magento/Checkout/etc/adminhtml/system.xml b/app/code/Magento/Checkout/etc/adminhtml/system.xml index 7454c2b6524f3..a45f9c3fbb0d3 100644 --- a/app/code/Magento/Checkout/etc/adminhtml/system.xml +++ b/app/code/Magento/Checkout/etc/adminhtml/system.xml @@ -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> diff --git a/app/code/Magento/Checkout/etc/config.xml b/app/code/Magento/Checkout/etc/config.xml index c8408f6d902fa..45691b6c54d97 100644 --- a/app/code/Magento/Checkout/etc/config.xml +++ b/app/code/Magento/Checkout/etc/config.xml @@ -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> diff --git a/app/code/Magento/Checkout/i18n/en_US.csv b/app/code/Magento/Checkout/i18n/en_US.csv index 251985faf6cc4..d244da55b28de 100644 --- a/app/code/Magento/Checkout/i18n/en_US.csv +++ b/app/code/Magento/Checkout/i18n/en_US.csv @@ -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>." \ No newline at end of file +"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" \ No newline at end of file diff --git a/app/code/Magento/Checkout/view/frontend/templates/cart/form.phtml b/app/code/Magento/Checkout/view/frontend/templates/cart/form.phtml index 370d70c44d886..7025867ee8f68 100644 --- a/app/code/Magento/Checkout/view/frontend/templates/cart/form.phtml +++ b/app/code/Magento/Checkout/view/frontend/templates/cart/form.phtml @@ -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> @@ -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="" diff --git a/app/design/frontend/Magento/luma/web/css/source/_extends.less b/app/design/frontend/Magento/luma/web/css/source/_extends.less index ce86b690f6252..e50726f2fce45 100644 --- a/app/design/frontend/Magento/luma/web/css/source/_extends.less +++ b/app/design/frontend/Magento/luma/web/css/source/_extends.less @@ -1570,8 +1570,7 @@ margin-bottom: @indent__base; .actions.main { - .continue, - .clear { + .continue { display: none; } }