我想以编程方式创建销售订单,使用我自己的自定义送货方式,运费和价格;标题。
这是我的自定义送货方式型号:
<?php
class Mycompany_Mymodule_Model_Carrier
extends Mage_Shipping_Model_Carrier_Abstract
implements Mage_Shipping_Model_Carrier_Interface
{
protected $_code = 'icw_shipping';
public function collectRates(Mage_Shipping_Model_Rate_Request $request)
{
if (!Mage::registry($this->_code)) {
return false;
}
$info = Mage::registry($this->_code);
$method = Mage::getModel('shipping/rate_result_method');
$method->setCarrier($this->_code);
$method->setMethod($this->_code);
$method->setCarrierTitle($info['shippingCarrier']);
$method->setMethodTitle($info['shippingTitle']);
$method->setPrice($info['shippingPrice']);
$method->setCost($info['shippingPrice']);
$result = Mage::getModel('shipping/rate_result');
$result->append($method);
Mage::unregister($this->_code);
return $result;
}
public function getAllowedMethods()
{
return array(
$this->_code => 'ICW Shipping',
);
}
}
我试着像这样使用它:
// Method to save sales order quote
private function saveSalesOrderQuote()
{
Mage::register($this->_settings['ShippingMethod'], array(
'shippingCarrier' => 'Custom',
'shippingTitle' => $this->_orderData->ShippingMethod,
'shippingPrice' => $this->_orderData->ShippingAmount
));
$this->_quote->getShippingAddress()->setShippingMethod(
$this->_settings['ShippingMethod']
);
$this->_quote->getShippingAddress()->setCollectShippingRates(
true
);
$this->_quote->getShippingAddress()->collectShippingRates();
$this->_quote->collectTotals();
$this->_quote->reserveOrderId();
$this->_quote->save();
}
但它似乎没有起作用。创建订单时,一切都是正确的运输方法,标题和&amp;价钱。这就是我在后端看到的内容:
到目前为止,这是我的完整代码:http://pastebin.com/jUTM0VbD
知道我在这里做错了吗?如何使用自己的自定义送货方式并设置自定义价格和标题?
答案 0 :(得分:-1)
为编程生成的订单添加送货方式非常简单,
按照上述步骤
$shippingAddress =$_quote->getShippingAddress()->addData($ShippingAddress);
$shippingAddress->setShippingMethod('methodname_methodname')->setCollectShippingRates(true)->collectShippingRates()->setPaymentMethod('methodcode'); //