0

I have enabled table rate shipping methods in magento. This is my checkout page enter image description here

This is the action of update total button

action="http://{{site-url}}/checkout/cart/estimateUpdatePost/"

Now when I go to estimateUpdatePost action in cartcontroller.php file there is a line

   if (!empty($code)) {
        $this->_getQuote()->getShippingAddress()->setShippingMethod($code)/*->collectTotals()*/->save();
    }

I am lookin for setShippingMethod($code) function. I had look through the files in magento and found this function in these two files

\app\code\core\Mage\Adminhtml\Model\Sales\Order\Create.php \app\code\core\Mage\Checkout\Model\Cart\Shipping\Api.php

But when I put die on setShippingMethod function and try to echo something then it is not shown and the page loads. It means these two setShippingMethod function is not hit and there is a function setShippingMethod somewhere else that is hit, due to which code runs. I want to locate it or if setShippingMethod function is not hit then anyone could tell me how update total button action is working.

I have made some changes to my code. First made changes to estimateUpdatePost action

   public function estimateUpdatePostAction()
{
    $code = (string) $this->getRequest()->getParam('estimate_method');

    if (!empty($code)) {
        $this->_getQuote()->getShippingAddress()->setShippingMethod($code)/*->collectTotals()*/->save();
        die('ssssss');
    }
    $this->_goBack();
}

and then looked for setData function in magento. Found this function in following files \app\code\core\Mage\Catalog\Model\Abstract.php \app\code\core\Mage\Centinel\Model\StateAbstract.php \app\code\core\Mage\Core\Model\Log\Adapter.php \app\code\core\Mage\Core\Model\Session\Abstract\Zend.php \app\code\core\Mage\Dataflow\Model\Convert\Container\Abstract.php \app\code\core\Mage\Widget\Block\Interface.php

I had put a die with a message in all these functions, and when I clicked on update total button, 'ssssss' this message is shown on browser, means no setData function is running. I am really stuck in this. Please help me in getting part of code that runs setShippingMethod($code) in estimateUpdatePostAction.

0

Check Mage_Sales_Model_Quote_Address class

Although you won't find it as a function, because setShippingMethod is an alias for setData('shipping_method'), which just sets shipping method code in the address

So the function you are searching in this case would be setData() in Varien_Object class

/**
 * Overwrite data in the object.
 *
 * $key can be string or array.
 * If $key is string, the attribute value will be overwritten by $value
 *
 * If $key is an array, it will overwrite all the data in the object.
 *
 * @param string|array $key
 * @param mixed $value
 * @return Varien_Object
 */
public function setData($key, $value=null)
{
    $this->_hasDataChanges = true;
    if(is_array($key)) {
        $this->_data = $key;
        $this->_addFullNames();
    } else {
        $this->_data[$key] = $value;
        if (isset($this->_syncFieldsMap[$key])) {
            $fullFieldName = $this->_syncFieldsMap[$key];
            $this->_data[$fullFieldName] = $value;
        }
    }
    return $this;
}
  • I have made some changes to my question according to your answer.Please have a look. – Rajeev Singh Feb 7 '18 at 11:55
  • I think my answer would be the same, if I understand what you are asking – Raul Sanchez Feb 7 '18 at 13:48
  • You said setData function is used. So I put a die on setData function then why that die message is not showing when update total button is clicked. – Rajeev Singh Feb 7 '18 at 14:00
  • Have you validated "estimate_method" is not empty? – Raul Sanchez Feb 7 '18 at 14:15
0

I am using the following code for set Shipping method,it is working well to me.

$this->_getQuote()->getShippingAddress()->setCollectShippingRates(true)
                  ->setFreeShipping(1)
                  ->setShippingMethod('flatrate_flatrate');

You can use this code.

if Free shipping, setFreeShipping() as 1 otherwise 0.

  • I used this code $this->_getQuote()->getShippingAddress()->setCollectShippingRates(true) ->setFreeShipping(0) ->setShippingMethod('tablerate_bestway') ->save(); but not working – Rajeev Singh Feb 7 '18 at 14:04
  • is shipping method "tablerate_bestway" enabled for that store.? – Nagaraj Juro Feb 7 '18 at 14:17
  • yes, it's enabled – Rajeev Singh Feb 8 '18 at 5:50
  • I was headed in the wrong direction. Actually the problem was one of the modules. Disabled it and everything is working fine – Rajeev Singh Feb 8 '18 at 9:12
  • Did you find what problem in that module.? – Nagaraj Juro Feb 8 '18 at 10:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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