Wednesday 6 August 2014

Can’t able to update cart quantities after upgrade Magento

Please go through the below for making the cart quantities work in Magento.

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 :

<!--[if lt IE 8]>
    <input type="hidden" id="update_cart_action_container" />
    <script type="text/javascript">
        //<![CDATA[
            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');
                    });
                }

            });
        //]]>
    </script>
 <![endif]-->

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!

No comments:

Post a Comment