1

When I click "Update cart" or "Empty cart" (text may be different, I'm using Magento AT in 1.9.0.1) nothing happens. The page refreshes but the content of the cart is not changed.
I have had it running on another webshop for some time and just found out about this one not working.
I have of course looked up the error and it seemed to be a problem on 1.8 that could be easily fixed (see link). I have tried if it was possible to fix it like this, but all the fixes mentioned on the page are already in the code of my default template, so nothing to change there.
I have tried to find a potential misconfiguration in the settings, but was not able to find one.

Edit: Just to make some things clear that I may have messed up, since english is not my first language: I am talking about the cart that you are automatically redirected to, when you add an item to the cart and also the page where you can check out. I can add items initially, but clicking the button "Empty cart" or "Update cart" does nothing but reloading the page. The parent theme of my theme is 'default/modern'.

2

This is easily done, but the javascript functions that trigger the minicart show/hide will "break", since you are reloading content into the DOM, which was instantiated at page load or document ready.

I'll show you how to achieve the result first, then we'll tackle the javascript issue.

Answering The Question

The block you want is called minicart_head, so your layout code in the controller addAction should be as follows:

> if (!$this->_getSession()->getNoCartRedirect(true)) {
    if (!$cart->getQuote()->getHasError()){
        $message = $this->__('%s was added to your shopping cart.', Mage::helper('core')->htmlEscape($product->getName()));
        $response['status'] = 'SUCCESS';
        $response['message'] = $message;
        $this->loadLayout();
        $minicart = $this->getLayout()->getBlock('minicart_head')->toHtml(); // <-- here's the block
        $response['minicart'] = $minicart;
    }
}

You can use the minicart data to replace the DOM object from your javascript function.

try {
    jQuery.ajax({
        url: url,
        dataType: 'json',
        type : 'post',
        data: data,
        success: function(data){
            var json =  eval(data);
            jQuery('#ajax_loader').hide();
            if (jQuery('.header-minicart')) {
                jQuery('.header-minicart').html( json.minicart );
            }
        }
    });
} catch (e) {
}

If you observe the DOM, using Web Inspector, for example, you will see that the content updates now via AJAX, but your show/hide feature will no longer work, since the javascript that acts on the #header-cart link has not been triggered for the new content.

Javascript Issue

By using jQuery's .on(), the theme developers at magento are on the right track (although they use a convoluted procedure to update the cart via AJAX).

In order for the show/hide feature to work, you need to use .on() delegation, or bubbling. In app.js, find the following:

File: app/skin/frontend/rwd/default/js/app.js

var skipContents = $j('.skip-content');
var skipLinks = $j('.skip-link');

skipLinks.on('click', function (e) {
    ...
}

And replace it as follows:

var skipContents = $j('.skip-content');
var skipLinks = $j('.skip-link');

$j('.skip-links').on('click', '.skip-link', function (e) {
    ...
}

And there you have it. Now your content reloads via AJAX, and the links still work after the cart changes.

  • This got to be the greatest response ever. In fact it is so great I did not get everything: Is there anywhere I can read more about this? I could not get this to run due to a lack of knowledge, I guess. I edited my layout code in the controller addAction to look like what you posted and I understood what I was doing until there. This alone of course did not solve the problem, but I could not figure out what exactly I have to replace in what DOM object. Also since I am not sure if I was clear enough on my question I will edit it now. – Bernie Dec 16 '14 at 20:47
  • After trying again for almost half a day I still could not figure out where to put/replace your code. I think I have found the place where to put your first snippet, but I have not found where to replace the DOM object – Bernie Dec 19 '14 at 14:02
  • i can help you just PMB – mrumair.com Dec 20 '14 at 4:14
2

As far as i know, this a common bug in magento. You can fix this by adding

<?php echo $this->getBlockHtml('formkey'); ?>

In your template/checkout/cart.phtml on line 50 after opening the form

  • This is what I have tried already (and linked above as well): This has been a bug in 1.8 from what I know, but should not appear in 1.9 – Bernie Dec 17 '14 at 8:02

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.