I am trying to modify third-party code that adds a discount and then reloads the cart.
What I want to do is skip reloading the cart and updating the totals via JS.
To be able to do this, I need to pass the updated totals via JSON, and here is my problem:
I know the formatting of the totals is done by rendertotals() in Mage_Checkout_Block_Cart_Totals, but how can I access this code?

I can access the cart with Mage::helper('checkout/cart')->getCart(), and I know there's Mage::helper('checkout/cart')->getCart()->getQuote()->getTotals(), but this returns an array while I'd like to call the same formatting procedure that is called when the cart is displayed initially to be sure the update procedure is visually compatible.

I guess it's trivial, but I am not yet familiar with the calling syntax of Magentos helpers and singletons.

Thank you for reading!

2 Answers 2


Did you try:

  • Your suggestion echoes checkout/cart_totals, but replacing toHtml() with renderTotals() does the trick. Thanks!
    – Imanuel
    Jan 20, 2014 at 18:29
  • Fixed the answer. Jan 20, 2014 at 20:10

If you are calling the code from your own controller, then the layout update of the cart controller is not loaded and you will not get the template file defined. So, to get the exact same html that is returned with the cart view, you can set the template in the following way:


That is the reason, I think, that the previous answer not work at the first time.

There is a harder way, forcing the controller to load the layout updates (checkout.xml) of the checkout/cart module, and after, get the block output by his name. This way:

$layout = $this->getLayout();
$total_html = $layout->getBlock('checkout.cart.totals')->toHtml();

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.