Skip to main content

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

Now I wannawant 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() returnreturns nothing. My json returnreturns: {"shipping":""}{"shipping":""}

Why toHtml method doesn't work?

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

Now I wanna 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() return nothing. My json return: {"shipping":""}

Why toHtml method doesn't work?

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?

added 45 characters in body
Source Link
Denis Spalenza
  • 1.4k
  • 12
  • 30

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

Now I wanna 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() return nothing. My json return: {"shipping":""}

Why toHtml method doesn't work?

I copied estimatePostAction and maked estimateAjaxPostAction (overrided core - i did not hack the core). The controllet action works.

Now I wanna 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() return nothing. My json return: {"shipping":""}

Why toHtml method doesn't work?

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

Now I wanna 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() return nothing. My json return: {"shipping":""}

Why toHtml method doesn't work?

Source Link
Denis Spalenza
  • 1.4k
  • 12
  • 30

Controller to Ajax Estimate Shipping - Load Block and display phtml

I copied estimatePostAction and maked estimateAjaxPostAction (overrided core - i did not hack the core). The controllet action works.

Now I wanna 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() return nothing. My json return: {"shipping":""}

Why toHtml method doesn't work?