2012-09-03 37 views
1

典型的magento订单有shipping_method。例如,就我而言,这是“flatrate_flatrate”。如何通过magento中的“运输方式”获得承运人

如何将shipping(“flatrate”)与shipping_method绑定?

感谢您的回复。

+0

您可以从Mage_Checkout_Model_Cart_Shipping_Api类中获取它。 –

+0

帮助我在Google上搜索时的答案:http://stackoverflow.com/questions/9433627/ –

回答

3
public function getShippingMethodsList($quoteId, $store=null) 
{ 
    $quote = $this->_getQuote($quoteId, $store); 

    $quoteShippingAddress = $quote->getShippingAddress(); 
    if (is_null($quoteShippingAddress->getId())) { 
     $this->_fault("shipping_address_is_not_set"); 
    } 

    try { 
     $quoteShippingAddress->collectShippingRates()->save(); 
     $groupedRates = $quoteShippingAddress->getGroupedAllShippingRates(); 

     $ratesResult = array(); 
     foreach ($groupedRates as $carrierCode => $rates) { 
      $carrierName = $carrierCode; 
      if (!is_null(Mage::getStoreConfig('carriers/'.$carrierCode.'/title'))) { 
       $carrierName = Mage::getStoreConfig('carriers/'.$carrierCode.'/title'); 
      } 

      foreach ($rates as $rate) { 
       $rateItem = $this->_getAttributes($rate, "quote_shipping_rate"); 
       $rateItem['carrierName'] = $carrierName; 
       $ratesResult[] = $rateItem; 
       unset($rateItem); 
      } 
     } 
    } catch (Mage_Core_Exception $e) { 
     $this->_fault('shipping_methods_list_could_not_be_retrived', $e->getMessage()); 
    } 

    return $ratesResult; 
} 
相关问题