0

This question is an exact duplicate of:

I am allowing user to apply some discount amount on cart page. When user clicks on checkbox or enter manually, it will call ajax action and display the discount amount in cart totals block as shown below.

Discount Amount Block

Cart total after Discount Applied

How can I load cart totals block using ajax and show discounted amount, when user clicks on checkbox ?

[EDIT]

Note: This question has been asked before, but as I still do not have an answer for it or some code flow, it compelled me to ask it again. You can still post some reference close to this question in terms of ajax with magento and container updaation.

Thanks.

marked as duplicate by Marius, MTM, Keyul Shah, Dexter, Fabian Blechschmidt Aug 25 '14 at 15:14

This question was marked as an exact duplicate of an existing question.

1
  1. Create a custom module;
  2. Create a controller
  3. On checkbox click call that controller with Ajax
  4. Inside the controller place this:

    $totalsBlock = $layout->createBlock('checkout/cart_totals')->setTemplate('checkout/cart/totals.phtml');
    return $totalsBlock;
    
  5. On ajax success, replace the content of totals div.

  • Thanks for your response, but the $totalsBlock gives me null. – Jordan Aug 26 '14 at 5:23
  • Are you sure? I did something similar to this like one week ago and I copied the code from over there. The difference was that I also loaded the checkout/cart block and the totals block was appended to the cart block. Also I had this line too but I think it doesn't do anything: $this->getResponse()->setBody($totalsblock); – Samuel Coman Aug 26 '14 at 8:03
  • I used toHtml() for block rendering, but I cant see the block loaded completely with discount applied unless I reload the page. Could you guide me on that ? – Jordan Aug 26 '14 at 9:07
  • Try this before loading the block: Mage::getSingleton('checkout/session')->setCartWasUpdated(true); – Samuel Coman Aug 26 '14 at 9:09
  • fetch() is called and I can see my changes for the display, but collect() is not called on ajax click and thus its not showing me discount amount – Jordan Aug 26 '14 at 9:10

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