0
votes

I'm programming an ajax extension to Magento and I'm having trouble when I try to make checkout/cart work with it.

I want to reload the entire block, including the item and also the cart totals after a change in any product in the cart.

I've modified the layout as many sites said and I can't get the checkout/cart block render well.

My two solutions were:


1° Tryed to update the layout via an xml file, and I get a false in $block_cart.

I've a class

Mati_Ajax_CartController extends Mage_Checkout_CartController
{
...
    public function updateShoppingCartAction()
    {
        ...
        $block_cart = $this->getLayout()->getBlock('checkout/cart');
        ...
    }
}

and a xml file (which I'm sure i'ts being loaded beacause the js pointed there is loading)

<checkout_cart_updateshoppingcart>
    <update handle="checkout_cart_index" />
</checkout_cart_updateshoppingcart>

2° Tryed to create the block

public function updateShoppingCartAction()
{
    ...
    $block_cart = $this->getLayout()->getBlockSingleton('checkout/cart')->setTemplate("checkout/cart.phtml")->toHtml();
    ...
}

And here I get the block, but when the template executes $this->getChildHtml('totals'); It gets a false anwer, so the webpage has some differences with the previousone


Does anybody knows how to make this work ?

2

2 Answers

0
votes

In your first attempt just append ->toHtml();

Alternatively you could have included that as a command in the xml output="toHtml"

Check how the checkout/onepage/review functions if you are looking for advice. There they access the response object and then set the body of the response to the html variable, in your case $block_cart

0
votes

The key was in the xml file

<ajax_cart_updateshoppingcart>
    <update handle="checkout_cart_index" />
</ajax_cart_updateshoppingcart>