0

After I have programmatically added an item to the cart, without reloading the cart page is possible to update the mini-cart, and, if so, how?

1 Answer 1

2

Yes possible.

You can update mini-cart ,without reloading the cart page .

Assume that you have using magento RWD mini-cart. In default magento, minicart_content block give mini-cart section content,so you need get that block content using ajaxfor your requirement

Let create a controller and render the content from an action.

<?php

class [CompnayName]_[ModuleName]_CustomController extends Mage_Core_Controller_Front_Action
{
  public function ajaxcontentAction()
    {

        $result = array();

            try {
                $cart =Mage::getSingleton('checkout/cart');
            $this->loadLayout();
                $result['content'] = $this->getLayout()->getBlock('minicart_content')->toHtml();
                $result['qty'] = Mage::getSingleton('checkout/cart')->getSummaryQty();
                $result['success'] = 1;
            } catch (Exception $e) {
                $result['success'] = 0;
                $result['error'] = $this->__('some error');
            }

        $this->getResponse()->setHeader('Content-type', 'application/json');
        $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
    }

}
1
  • Is this working before loading cart page ?its not working for me.My module is some customization.After adding to cart(in product details page) it should update in mini cart also any load or refreshing the cart page. Commented Oct 12, 2016 at 15:03

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.