15

How can I reload the page when I remove mini cart item ?
I know it's Magento 2 bug.

On the checkout cart page there are many products In mini cart as well as In checkout cart page when I remove In mini cart, content not updated and I know it's a big thing to update checkout cart page content using Ajax so I am thinking about when customer remove item from cart I need to reload the page.

1

Fixed issue in all checkout page magento 2

app/design/frontend/Magento/yourtheme/Magento_Checkout/web/js/sidebar.js

=> put the comment code after comple function

.done(function (response) {
    var msg;
    if (response.success) {
        callback.call(this, elem, response);
       /** **page reload code */
        if(this.options.url.remove == url && window.location.href.indexOf("checkout") > -1){
            window.location.reload(true);
        }**
        /** page reload code */
    } else {
        msg = response['error_message'];

        if (msg) {
            alert({
                content: msg
            });
        }
    }
    })
0

If you have any module in /app/code Then inside that module crate or edit a file under Namespace/Your module/etc/frontend/sections.xml.

And write and inside This file:

<action name="checkout/sidebar/removeItem">
<section name="cart"/>
</action> 

This should be written under valid configuration declaration you can see how to write this in module-checkout under vendor/magento.

0

A simple fix for this issue.

Copy the file

vendor/magento/module-checkout/view/frontend/web/js/view/minicart.js

to

your_theme_path/Magento_Checkout/web/js/view/minicart.js

In the initialize function

if(window.location.href.indexOf("checkout/cart") > -1) {
         location.reload();
     }

Add this code in the contentLoading function like this

$('[data-block="minicart"]').on('contentLoading', function (event) {
            addToCartCalls++;
            self.isLoading(true);
                $('[data-block="minicart"]').on('contentUpdated', function ()  {
                    $('[data-block="minicart"]').find('[data-role="dropdownDialog"]').dropdownDialog("open");       
                    setTimeout(function() {
                    $('[data-block="minicart"]').find('[data-role="dropdownDialog"]').dropdownDialog("close");
                }, 4000);
            });
            if(window.location.href.indexOf("checkout/cart") > -1) {
                location.reload();
            }
        });

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.