I'm trying to update my header mini cart dynamically by creating a new block, I've tried several ways including:

$block = $this->getLayout()->createBlock(
    //'checkout/cart', // OR 'Mage_Checkout_Block_Cart'
    array('template' => 'ajax/checkout/cart/sidebar/default.phtml')

//Release layout stream... lol... sounds fancy

And also

$block = $this->getLayout()->createBlock('checkout/cart')->setTemplate('ajax/checkout/cart/sidebar/default.phtml')->toHtml();

They always come back empty, I can get it to bring back static content fine. Any ideas please?

3 Answers 3


In your module/controller/CartController.php action (or another) :

$data["cart_sidebar"] = $this->getLayout()
->addItemRender("default", "checkout/cart_item_renderer", "checkout/cart/minicart/default.phtml")
->addItemRender("simple", "checkout/cart_item_renderer", "checkout/cart/minicart/default.phtml")
->addItemRender("grouped", "checkout/cart_item_renderer_grouped", "checkout/cart/minicart/default.phtml")
 ->addItemRender("configurable", "checkout/cart_item_renderer_configurable", "checkout/cart/minicart/default.phtml")

You can use json to serialize your data.

Then have just to put in your js :


If you want upgrade cart qty, serialize it too ;)

  • ;) to you too there partner. Dec 17, 2014 at 21:08

Try this in your controller as an action (which you'd then call via ajax)

public function getTopCartAction()
        $layout = Mage::getSingleton('core/layout');
        $block = $layout->getBlock('cart_sidebar');
        $html = $block->toHtml();
        return $this;

This would then use whatever layout.xml directive may have altered 'cart_sidebar' block definition, from any 3rd party modules.

I use the following (which is in a template file):

    var request = new Ajax.Request(
            '<?php echo mage::getUrl("*/cart/getTopCartQty") ?>',
                method: 'get',
                onSuccess: function(response) {
                    var json = response.responseText.evalJSON();
                    var cartElm = $$('.top-link-cart')[0];
                        var updatedTopCart = cartElm.innerHTML.replace(/(\d+)/g, 
                        cartElm.innerHTML = updatedTopCart;
                        cartElm.title = updatedTopCart;

Hope that helps


You can get minicart HTML in a controller with:

public function yourAction() {
    $minicart = $this->getLayout()->getBlock('minicart_content')->toHtml();
    echo $minicart;

Then you can replace minicart HTML using jQuery or similar:

  • This code only update minicart content. But what about if I want to update mini cart qty as well which display beside cart?
    – Indian
    Aug 8, 2017 at 7:18

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.