4

I copied estimatePostAction and made estimateAjaxPostAction (overrided core - i did not hack the core). The controller action works as well (class Mage_Checkout_CartController).

Now I want to get/create a block for replace shipping block after estimate shipping with ajax. I tried this:

public function estimateAjaxPostAction()
{
 $country = (string) $this->getRequest()->getParam('country_id');
 $postcode = (string) $this->getRequest()->getParam('estimate_postcode');
 $city = (string) $this->getRequest()->getParam('estimate_city');
 $regionId = (string) $this->getRequest()->getParam('region_id');
 $region = (string) $this->getRequest()->getParam('region');
 $this->_getQuote()->getShippingAddress()
 ->setCountryId($country)
 ->setCity($city)
 ->setPostcode($postcode)
 ->setRegionId($regionId)
 ->setRegion($region)
 ->setCollectShippingRates(true);
 $this->_getQuote()->save();
 //$this->_goBack();
 $this->loadLayout();
 $block = $this->getLayout()->createBlock('Mage_Checkout_Block_Cart_Shipping','checkout.cart.shipping.ajax',array('template' => 'checkout/cart/shipping.phtml'));
 if($block) {
 $response = array();
 $response['shipping'] = $block->toHtml();
 $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($response));
 }
}

The block checkout.cart.shipping.ajax was created. But toHtml() returns nothing. My json returns: {"shipping":""}

Why toHtml method doesn't work?

Keyur Shah
18.1k6 gold badges68 silver badges80 bronze badges
asked Feb 6, 2014 at 11:08
2

1 Answer 1

2

Try

....
$loadLayout = $this->loadLayout();
$block = $loadLayout->createBlock(
 'checkout/cart_shipping',
 'checkout.cart.shipping.ajax'
)->setTemplate('checkout/cart/shipping.phtml');
if($block) {
 $response = array();
 $response['shipping'] = $block->toHtml();
 $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($response));
}
....
answered Nov 7, 2014 at 15:58
1
  • oh, you wrote description for your name, awesome boss..... Commented Oct 5, 2016 at 13:39

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.