Tuesday 12 May 2015

Magento: Apply shipping method programmatically

Replace with this function:

public function saveShippingAction()
{
    if ($this->_expireAjax()) {
        return;
    }
    if ($this->getRequest()->isPost()) {
        $data = $this->getRequest()->getPost('shipping', array());
        $customerAddressId = $this->getRequest()->getPost('shipping_address_id', false);
        $result = $this->getOnepage()->saveShipping($data, $customerAddressId);

        if (!isset($result['error'])) {
            //$method = 'flatrate_flatrate';
            $method = 'tablerate_bestway';         
            $result = $this->getOnepage()->saveShippingMethod($method);
            Mage::getSingleton('checkout/type_onepage')->getQuote()->getShippingAddress()->setShippingMethod($method)->save();

            if (!isset($result['error'])) {

                $result['goto_section'] = 'payment';
                $result['update_section'] = array(
                    'name' => 'payment-method',
                    'html' => $this->_getPaymentMethodsHtml()
                );
            }
        }
        $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
    }
}

No comments:

Post a Comment