(Using magento 1,9).

I have made my own sidebar, with my own custom minicart. The minicart must be able to update the quantity of each product there's in the cart. Below is my code and what i have tried (short version):

<?php $cart = Mage::getModel('checkout/cart')->getQuote() ?>
<form action="<?php echo $this->getUrl('checkout/cart/updatePost') ?>" method="post">
<?php foreach($cart->getAllItems() as $item): ?>

<span><input type="text" class="minicartQty" name="cart[<?php echo $item->getId() ?>][qty]" id="minicartQty" value="<?php echo $item->getQty(); ?>" /></span>

<button type="submit" name="update_cart_action" value="empty_cart" class="button btn-update"><span><?php echo $this->__('Update cart'); ?></span></button>
<?php endforeach; ?>

But when i hit the update button, it perfectly redirects to the cart, but it has not updated the quantity of the chosen product. Maybe i am missing something here? :)


2 Answers 2


If you take a look at updatePostAction() method of Mage_Checkout_CartController class where your form is submitted.

if (!$this->_validateFormKey()) {

which validate formkey for your form. you have to include form key in your form to validate your form. It checks that actually form is posted not simply method called. please put this line right after opening <form> tag.

echo $this->getBlockHtml('formkey');

It will include form key to your form and your form will work.

  • I have tried to put the form key (echo $this->getBlockHtml('formkey');) right after the <form> tag, but when i change the qty, it redirects to the cart, and, this time its emptying the cart instead of changing the qty. Do i need to change something else here? :)
    – simond
    Commented Jul 7, 2014 at 9:08
  • 1
    <button type="submit" name="update_cart_action" value="empty_cart" class="button btn-update"> please change name and value attributes here. value="update_qty" It should work. Commented Jul 7, 2014 at 9:20
  • Oh how could i miss that??? It works fine now. Thanks alot for help (Mukund and all other) =)
    – simond
    Commented Jul 7, 2014 at 16:48

I did the same on 1.9 and right now my minicart works fine in the sidebar. You have to edit .../template/checkout/cart/minicart/items.phtml (copy to your theme's directory and edit that one) and make sure you have the proper divs in the proper order:

<div id="header-cart" class="block block-cart">

<div class="block-title">
    <strong><span><?php echo "Mini Shopping Cart" ?></span></strong>

<div class="block-content header-minicart">

    $_cartQty = $this->getSummaryCount();
    if(empty($_cartQty)) {
        $_cartQty = 0;
    <div id="minicart-error-message" class="minicart-message"></div>
    <div id="minicart-success-message" class="minicart-message"></div>

    <div class="minicart-wrapper">

        <?php $_items = $this->getRecentItems() ?>
        <?php $countItems = count($_items); ?>
        <?php if($countItems): ?>
                <ul id="cart-sidebar" class="mini-products-list">
                    <?php foreach($_items as $_item): ?>
                        <?php echo $this->getItemHtml($_item) ?>
                    <?php endforeach; ?>
            <script type="text/javascript">
                decorateList('cart-sidebar', 'none-recursive');
                $j('document').ready(function() {
                    var minicartOptions  = {
                        formKey:           "<?php echo $this->getFormKey();?>"
                    var Mini = new Minicart(minicartOptions);

            <div id="minicart-widgets">
                <?php echo $this->getChildHtml('cart_promotion') ?>
            <!--div class="block-content"-->

…etc. As you can see, I have commented out the original "block-content" div, it must be the wrapper of the whole thing, under "block-title". Somewhere in the codebase of Magento the required structure of these divs are mentioned, I just cannot find it at the moment.

Hope this helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.