Magento TopLink Cache My Cart (#)

558 views Asked by At

I have some problem with "My Car (#)" on the header and cache.

I'm using Magento Enterprise 1.12. The problem is when I add or delete some item into the Cart in the header i have "My Car (#)" and doesn't update every time I add or remove item form the cart, that because the cache, and i dont know how to solve it...

Steps:

1) Clean cache from admin

2) Enter to Home Page (in the header appear "My Cart")

3) Go some product page

4) Add some product into the cart

5) Redirect to My Cart page (in the header appear "My Cart (1 item)")

6) Go to Home Page Again (and in the header still appear "My Cart") without the "1 item"

If i go to admin site and clean cache on the home page appear "My Cart (1 item)". And I have the same problem when I have 1 item and then I delete that item from the cart.

I need to be dynamic that black and i don't know how to do it.

Tnks for reading! :)

1

There are 1 answers

0
Chris Rogers On

Okay, there maybe many problems here, but perhaps a decent way to debug this issue would be to override the JavaScript Minicart methods to see where it trips up.

In your Module's layout.xml file add a custom script by following this post

Next, Minicart.prototype has many functions, console.log(Minicart.prototype); to view them.

I hazard a guess something is going wrong in the updateItem method. Override this by adding this in your JS file:

if (typeof Minicart != "undefined") {
    Minicart.prototype.updateItem = function(el) {
        var cart = this;
        var input = $j(this.selectors.quantityInputPrefix + $j(el).data('item-id'));
        var quantity = parseInt(input.val(), 10);
        cart.hideMessage();
        cart.showOverlay();
        $j.ajax({
            type: 'POST',
            dataType: 'json',
            url: input.data('link'),
            data: {qty: quantity, form_key: cart.formKey}
        }).done(function(result) {
            cart.hideOverlay();
            if (result.success) {
                cart.updateCartQty(result.qty);
                if (quantity !== 0) {
                    cart.updateContentOnUpdate(result);
                } else {
                    cart.updateContentOnRemove(result, input.closest('li'));
                }
            } else {
                cart.showMessage(result);
            }
        }).error(function() {
            cart.hideOverlay();
            cart.showError(cart.defaultErrorMessage);
        });
        return false;
    };
}

And start to log out the parts where it fails. If this isn't causing the error then try another method.

Happy coding!