I want to add a new SOAP API similar to shoppingCartShippingMethod() so that I can pass the shipping rate to the SOAP call to set the shipping rate. This is needed for integration with other ordering systems where the shipping rates are dynamic.

However, each shipping method requires implementing collectRates() but I am not sure how to pass the arguments in the SOAP call to that method.

Do I need to save the shipping rate in a session (even though it's through the API) so that collectRates() can retrieve the rate?

  • It seems that collectRates() gets executed when calling the SOAP API's shoppingCartCustomerAddresses() and shoppingCartProductAdd(). For collectRates() to retrieve any settings, the settings need to be set before hand (perhaps via another custom API). This gets complicated. – Saul Karl Dec 23 '14 at 8:51
  • please check here : magento.stackexchange.com/questions/95560/… – Baby in Magento Jan 12 '16 at 13:53

It is possible to force Magento to recalculate the shipping rates:

class Mage_Checkout_Model_Cart_Shipping_Api extends Mage_Checkout_Model_Api_Resource
  public function setShippingMethod($quoteId, $shippingMethod, $price = null, $store = null)
    $quote = $this->_getQuote($quoteId, $store);

    $quoteShippingAddress = $quote->getShippingAddress();
    if(is_null($quoteShippingAddress->getId()) ) {

    if (isset($price)) {
        $sessionId = $this->_getSession()->getSessionId();
        Mage::register('customShippingRate' . $sessionId, $price);
        // force calling carrier collectRates() again
    $rate = $quote->getShippingAddress()->collectShippingRates()->getShippingRateByCode($shippingMethod);
    if (!$rate) {

    try {
    } catch(Mage_Core_Exception $e) {
        $this->_fault('shipping_method_is_not_set', $e->getMessage());

    return true;

Then in collectRates(), I can get the custom shipping rate from the variable stored in the registry:

public function collectRates(Mage_Shipping_Model_Rate_Request $request) {
  $sessionId = Mage::getSingleton('api/session')->getSessionId();
  $price = Mage::registry('customShippingRate' . $sessionId);
  if (isset($price)) {
    Mage::unregister('customShippingRate' . $sessionId);
  • would you be able to provide any more information on this? Can't seem to get it working? – willboudle Aug 2 '17 at 15:08

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.