Can’t update cart quantities after upgrade to Magento 1.8

Another issue which has cropped up on a number of clients’ sites after an upgrade to Magento 1.8 is that they can’t update cart quantities any more. The functionality still appears to be there – you change product quantities and hit the “update basket” button – but it doesn’t actually do anything.

If this is happening to you, the chances are that you’re using a custom template file for template/checkout/cart.phtml in your theme – with the recent upgrade a small change has been introduced to the base version of this file which, since you’re using a custom version, won’t be reflected in your page.

One approach is simply to delete the cart.phtml file, which forces Magento to fall back on the base file – but if you’ve got a custom version of that file the chances are you’ve made some changes to it, which would be wiped out if you went down this route.

The better approach is to add the updated lines to your own cart.phtml file – to fix the specific issue at hand there are two additions which need to be made :

Towards the top of the file, find the line :

<?php echo $this->getMessagesBlock()->getGroupedHtml() ?>

and after it add in this line :

<?php echo $this->getChildHtml('form_before') ?>

Shortly after that, look for the line :

<form action="<?php echo $this->getUrl('checkout/cart/updatePost') ?>" method="post">

and check that after it there is the following line :

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

If not, add it in.

Then, further down the file, look for the code which outputs your “clear shopping cart” button – if you’ve not customised your installation, this should look something like this :

<button type="submit" name="update_cart_action" value="empty_cart" title="<?php echo $this->__('Clear Shopping Cart'); ?>" class="button btn-empty" id="empty_cart_button"><span><span><?php echo $this->__('Clear Shopping Cart'); ?></span></span></button>

Immediately after it, paste the following lines :

                            <!--&#91;if lt IE 8&#93;>
                            <input type="hidden" id="update_cart_action_container" />
                            <script type="text/javascript">
                            //<!&#91;CDATA&#91;
                                Event.observe(window, 'load', function()
                                {
                                    // Internet Explorer (lt 8) does not support value attribute in button elements
                                    $emptyCartButton = $('empty_cart_button');
                                    $cartActionContainer = $('update_cart_action_container');
                                    if ($emptyCartButton && $cartActionContainer) {
                                        Event.observe($emptyCartButton, 'click', function()
                                        {
                                            $emptyCartButton.setAttribute('name', 'update_cart_action_temp');
                                            $cartActionContainer.setAttribute('name', 'update_cart_action');
                                            $cartActionContainer.setValue('empty_cart');
                                        });
                                    }

                                });
                            //&#93;&#93;>
                            </script>
                            <!&#91;endif&#93;-->

Save the file, upload it to your theme’s template/checkout/ folder (remember to keep a backup of your original cart.phtml) and you should be good to go!

49 comments

  • Die

    Hello, I am trying to solve this problem and I can not find a solution. I have seen all your steps and they do not solve the problem. I have Magento 1.9.3.1
    Could you help me?

  • Jane

    Amazing !! Thank you so much for taking the time to post this, I have been searching all day for this fix and your edits worked first time !!

    • Giles Bennett (author)

      Jane,

      You’re welcome.

      Kind regards,

      Giles

  • Geo

    Hello, Im experiencing this issue but from updating magento 1.9.1.0 to 1.9.2.4. I tried to delete the file, but it didnt work, and to add the lines, but they all seem diferent in the new version file. Hope you can give me some help. thank you

    • Giles Bennett (author)

      Geo,

      If they all seem different, then you may not be editing the correct file…

      Kind regards,

      Giles

  • Mirjam

    Hello,
    The checkout cart for me is properly working, but the mini cart (ajax) doesn’t update on my webshop.
    Do u know the solution for it. I would be so happy if it works. When I add a product it stays on zero.

    http://imgur.com/aFCj6Tr

    Friendly regards Mirjam.

  • Panjianom

    It works!
    Thank you so much!

  • Sean

    Thanks mate. Easy to follow and done the job perfectly. Cheers

  • MgWorx

    Hi, I have experienced this exact same issue on Magento 1.9. I have tried the fix you posted but it is not working. Can ou perhaps advise – thanks!

    • Giles (author)

      Joseph,

      Are you sure that your amended template file is being picked up?

      Kind regards,

      Giles

  • Jack

    Thanks, this works great!

  • Arjen

    I bow to you, this saved the day!

  • mister-eeee

    life saver!!! 🙂 Thanks sooo much!

  • Francoisd

    Hello,

    I’m on a Magento CE 1.7 with multisite configuration
    On a subdomain, my update button doesn’t work even with your code suggestion.
    On the main domain, it works without adding code ( in my case, missing getBlockHtml(‘formkey’); ?> in the 1.7)

    In my firebug, the POST Request /checkout/cart/updatePost/ as a 302 Moved temporarily status.

    Have you seen this case ?

    Thanks

    • Giles (author)

      Francois,

      Not to my knowledge. But the fix in this post is specifically for something which was added in 1.8, so isn’t relevant to 1.7.

      Kind regards,

      Giles

  • Chris

    Thanks dude!
    You’ve saved me a lot of time.

  • Bob

    Thanks, fixed the problem!

  • Bethan

    Thank you! Quick question, my clear cart button is now working correctly but although the update cart button is working now too, the user is being taken back to the home page instead of staying on the cart. Any ideas? Thanks in advance.

    • Giles (author)

      Bethan,

      Sounds a bit broken – the Continue Shopping button should take the user to the homepage, but not the update cart button. What’s the site’s URL?

      Giles

  • Nick

    Just used this fix and it worked.

    For some reason the lines with update cart action were already there, just commented out. Uncommenting them fixed it!

    Thank you!

  • chamal

    thanks man you saved my day !!! keep writing

  • nick

    Awesome

  • marc

    thanks works 🙂

    • Giles (author)

      You’re welcome!

      Giles

  • wendell alves

    Muito obrigado meu caro… salvou meu trabalho!!!!!!!!!!!!!!!!!!!!!!!!!!

    • Giles (author)

      De nada. 😉

      Giles

  • ilia

    Thanks! this worked for – in my case only needed to add first 2 lines

  • Jesse

    Hello Giles,

    My site’s cart.phtml file has all of the line codes you provided, but still can’t update shopping cart qty.
    Any other thought?
    Thanks for your work.

    Jesse

    • Giles (author)

      Jesse,

      Could be any number of things – drop us a line at info@hummingbirduk.com and we’ll happily take a quick look for you without charge and see if anything jumps out.

      Kind regards,

      Giles

    • Kenneth

      It thought I had em all until I actually saw that I was missing

      getBlockHtml(‘formkey’); ?>

      after

      <form action="getUrl(‘checkout/cart/updatePost’) ?>” method=”post”>

  • Narayan

    Great article!! Thanks 🙂

  • josh

    This article actually fixed my problem where other articles and posts about the same issue did not.

    TIL – that buying magento themes even if they state they are 1.7 1.8 1.81 etc… compatible is a punt in the dark is not always true.

    Thank you Giles

  • hasitha1986

    Wow Cool, it is working thanks a lot…..

  • Inge

    Thanks a lot!!

    • Giles (author)

      Inge,

      You’re welcome!

      Giles

  • AJ

    Thank you for this 🙂 🙂

    • Giles (author)

      AJ,

      You’re welcome. Nice profile pic!

      Giles

  • kulai

    Thanks for this fix. It worked for me too!

    • Giles (author)

      Kulai,

      You’re more than welcome.

      Kind regards,

      Giles

  • sjoerd

    Fantastic!!

    • sohail

      Thanks Brother…God Bless You a Lot….

  • smd

    Thank you, thats the solution! I experienced the same: customized cart, update to 1.8.1. and the cart update did not work any more – until now 😉

    • Giles (author)

      No problem – glad the post helped.

      Giles

  • Marvin

    Great article, thank you!

    • Giles (author)

      Marvin,

      You’re welcome – thanks for your comment!

      Giles

Leave a Reply

Your email address will not be published. Required fields are marked *

Want to talk to us about your project?