4

After I updated from Magento version 2.2.3 to 2.2.6 the shopping cart stopped clearing after I click "Clear Shopping Cart" on the cart page.

After I click the button, the page reloads but everything remains the same.

I am using Ultimo theme but I have checked and it doesn't overwrite this behavior anyhow.

What could be the possible issue and where should I start my investigation from?

  • I am having same issue with Magento 2.2.6 and Latest version of Ultimo theme. Did you find a solution? This is exception I am seeing in log file. main.CRITICAL: Requested product doesn't exist {"exception":"[object] (Magento\\Framework\\Exception\\NoSuchEntityException(code: 0): Requested product doesn't exist at /home/web/site/public_html/vendor/magento/module-catalog/Model/ProductRepository.php:271) – Zoya Nov 24 '18 at 12:20
  • @Haya Check phagento answer – Ilja Davidovs Nov 26 '18 at 10:46
14

I've also encountered this issue and I've found out that in vendor/magento/module-checkout/view/frontend/templates/cart/form.phtml ~line 27, Magento Team seems missed to put a dot for the 'action' classname. It's a small mistake that creates a big problem. Hopefully this will be fixed in 2.2.7

So from

action.clear

It should be

.action.clear

*Note: Please don't edit the file in

vendor/magento/module-checkout/view/frontend/templates/cart/form.phtml

directly.*

  • I just checked one of my 2.2.7 websites and this issue is still present. I don't like the button personally (its hidden w/ css) but I don't think they've yet realized they need to fix this. – jamil Jan 18 at 18:23
2

When a user clicks on Clear Shopping Cart button then you have to check below:

  • On click on this button the http://{Example.com}/checkout/cart/updatePost/ should hit.
  • This URL must hit via POST request.

    This post request must have form_key and update_cart_action, and update_cart_action value should be empty_cart

FORM DATA should like when to click on Clear Shopping Cart

form_key: 4VQpuhYHzS9dOY3P
cart[15][qty]: 1
cart[17][qty]: 1
update_cart_action: empty_cart

Where 15,17 are cart item id.

If those are available or exist then the exception is not happening. You check error, check the exception log or changes

$this->messageManager->addException($exception, __('We can\'t update the shopping cart.'));

to

$this->messageManager->addError($exception->getMessage()
  • update_cart_action parameter is missing. Is it related to JavaScript? – Ilja Davidovs Oct 3 '18 at 9:32
  • @Amit Bera please check my answer – Ranganathan Oct 6 '18 at 5:05
0

The Problem is 'update_cart_action' Parameter is not sending because Mageno developers added 'Magento_Checkout/js/action/update-shopping-cart' js function for validation. They Submit the form in this file. So the submit button value param is not sending. Add the hidden field with submit button name in

Magento_Checkout/templates/cart/item/form.phtml


<input type="hidden" id="update_cart_action_hidden" name="update_cart_action" value="">

And assign the value of submit button using onClick event to the hidden field

$('.update-cart-action').click(function(){
     $('#update_cart_action_hidden').val($(this).val());
});

Hope this will work

0

Checkout Cart Page >> Clear Shopping Cart button should have alert to the users if they want to clear or not.

Here I am overriding form.phtml in my theme.

app/design/frontend/Namespace/yourthemename/Magento_Checkout/templates/cart/form.phtml

form.phtml

<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

// @codingStandardsIgnoreFile

/**  @var $block \Magento\Checkout\Block\Cart\Grid */
?>
<?php $mergedCells = ($this->helper('Magento\Tax\Helper\Data')->displayCartBothPrices() ? 2 : 1); ?>
<?= $block->getChildHtml('form_before') ?>
<form action="<?= /* @escapeNotVerified */ $block->getUrl('checkout/cart/updatePost') ?>"
          method="post"
          id="form-validate"
          data-mage-init='{"Magento_Checkout/js/action/update-shopping-cart":
              {"validationURL" : "/checkout/cart/updateItemQty"}
          }'
          class="form form-cart">
    <?= $block->getBlockHtml('formkey') ?>
    <div class="cart table-wrapper<?= $mergedCells == 2 ? ' detailed' : '' ?>">
        <?php if ($block->getPagerHtml()): ?>
            <div class="cart-products-toolbar cart-products-toolbar-top toolbar" data-attribute="cart-products-toolbar-top"><?= $block->getPagerHtml() ?></div>
        <?php endif ?>
        <table id="shopping-cart-table"
               class="cart items data table"
               data-mage-init='{"shoppingCart":{"emptyCartButton": ".action.clear",
               "updateCartActionContainer": "#update_cart_action_container"}}'>
            <caption role="heading" aria-level="2" class="table-caption"><?= /* @escapeNotVerified */ __('Shopping Cart Items') ?></caption>
            <thead>
                <tr>
                    <th class="col item" scope="col"><span><?= /* @escapeNotVerified */ __('Item') ?></span></th>
                    <th class="col price" scope="col"><span><?= /* @escapeNotVerified */ __('Price') ?></span></th>
                    <th class="col qty" scope="col"><span><?= /* @escapeNotVerified */ __('Qty') ?></span></th>
                    <th class="col subtotal" scope="col"><span><?= /* @escapeNotVerified */ __('Subtotal') ?></span></th>
                </tr>
            </thead>
            <?php foreach ($block->getItems() as $_item): ?>
                <?= $block->getItemHtml($_item) ?>
            <?php endforeach ?>
        </table>
        <?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()): ?>
            <a class="action continue"
               href="<?= $block->escapeUrl($block->getContinueShoppingUrl()) ?>"
               title="<?= $block->escapeHtml(__('Continue Shopping')) ?>">
                <span><?= /* @escapeNotVerified */ __('Continue Shopping') ?></span>
            </a>
        <?php endif; ?>
        <button type="button"
                title="<?php echo $block->escapeHtml(__('Clear Shopping Cart')); ?>"
                class="action clear" id="cp-empty_cart_button">
            <span><?php /* @escapeNotVerified */
                echo __('Clear Shopping Cart'); ?></span>
        </button>
        <button type="submit"
                name="update_cart_action"
                data-cart-empty=""
                value="empty_cart"
                title="<?= $block->escapeHtml(__('Clear Shopping Cart')) ?>"
                class="action clear" id="empty_cart_button" style="display: none;">
            <span><?= /* @escapeNotVerified */ __('Clear Shopping Cart') ?></span>
        </button>
        <button type="submit"
                name="update_cart_action"
                data-cart-item-update=""
                value="update_qty"
                title="<?= $block->escapeHtml(__('Update Shopping Cart')) ?>"
                class="action update">
            <span><?= /* @escapeNotVerified */ __('Update Shopping Cart') ?></span>
        </button>
        <input type="hidden" value="" id="update_cart_action_container" data-cart-item-update=""/>
    </div>
</form>
<?= $block->getChildHtml('checkout.cart.order.actions') ?>
<?= $block->getChildHtml('shopping.cart.table.after') ?>
<script type="text/javascript">
    require([
        'jquery',
        'Magento_Ui/js/modal/alert',
        'Magento_Ui/js/modal/confirm'
    ], function ($, alertt, confirmation) {
        $(document).ready(function () {
            $('.cp-action-accept').parents('aside').addClass('confirm');
            $('#cp-empty_cart_button').on('click', function (event) {
                event.preventDefault();
                confirmation({
                    title: '',
                    content: 'Are you sure to remove products from cart ?',
                    actions: {
                        confirm: function () {
                            window.location.href = '<?php /* @escapeNotVerified */ echo $block->getUrl('checkout/cart/updatePost'); ?>';
                        },
                        cancel: function () {
                        }
                    },
                    buttons: [{
                        text: $.mage.__('OK'),
                        class: 'action secondary cp-action-accept',
                        /**
                         * Click handler.
                         */
                        click: function (event) {
                            this.closeModal(event, true);
                            $('#empty_cart_button').trigger('click');
                        }
                    },
                        {
                            text: $.mage.__('Cancel'),
                            class: 'action secondary action-dismiss',
                            /**
                             * Click handler.
                             */
                            click: function (event) {
                                this.closeModal(event);
                            }
                        }
                    ]
                });
            });
        });
    });
</script>

Output will be like this :-

enter image description here

0

Its a default bug in Magento2 version : https://github.com/magento/magento2/issues/18475

To resolve this issue you need to override the file

vendor/magento/module-checkout/view/frontend/templates/cart/form.phtml

into your theme

app/design/frontend/{PackgageName}/{ThemeName}/Magento_Checkout/templates/cart/from.phtml

and change the line number 27 from action.clear to .action.clear

0

It's default bug.

Here I am overriding form.phtml in my theme.

app/design/frontend/Namespace/yourthemename/Magento_Checkout/templates/cart/form.phtml

Two Changes required

1) At line no 17 :

/checkout/cart/updateItemQty

to

updateItemQty

2) At line no 27 :

action.clear

to     

.action.clear

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.