信息:Magento 1.7.0.2 CE
我已经制作了一个模块,用于通过 cron 计划从外部提要导入订单,我还创建了一个自定义运营商。
一切正常,但我无法设置运费......这是代码:
$shippingAddress = $quote->getShippingAddress()->addData($addressData);
$shippingAddress->setCollectShippingRates(true)->collectShippingRates()
->setShippingMethod('customname_customname')
->setShippingAmount('10')
->setBaseShippingAmount('10');
$quote->collectTotals();
$quote->save();
$addressData 包含客户信息
我尝试了不同的方法,但我无法设置运费。帮助!
这是自定义运营商代码:
protected $_code = 'customname';
/**
* Collect rates for this shipping method based on information in $request
*
* @param Mage_Shipping_Model_Rate_Request $data
* @return Mage_Shipping_Model_Rate_Result
*/
public function collectRates(Mage_Shipping_Model_Rate_Request $request){
$result = Mage::getModel('shipping/rate_result');
$method = Mage::getModel('shipping/rate_result_method');
$method->setCarrier($this->_code);
$method->setCarrierTitle($this->getConfigData('title'));
$method->setMethod($this->_code);
$method->setMethodTitle($this->getConfigData('name'));
$method->setPrice('0.00');
$method->setCost('0.00');
$result->append($method);
return $result;
}
/**
* Get allowed shipping methods
*
* @return array
*/
public function getAllowedMethods()
{
return array($this->_code=>$this->getConfigData('name'));
}
}