[英]Programmatically create sales order using quote with custom shipping method in Magento
I would like to create sales orders programmatically using quotes with my own custom shipping method, shipping price & title. 我想使用报价和自己的自定义送货方式,送货价格和标题以编程方式创建销售订单。
This is my custom shipping method model: 这是我的自定义送货方式模型:
<?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',
);
}
}
I try to use it like this: 我尝试像这样使用它:
// 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();
}
But it does not appear to be working. 但是它似乎没有用。 When the order is created, everything is correct expect for the shipping method, title & price. 创建订单后,所有关于运输方式,标题和价格的信息均正确无误。 This is what I see in the backend: 这是我在后端看到的:
Here's my full code so far: http://pastebin.com/jUTM0VbD 到目前为止,这是我的完整代码: http : //pastebin.com/jUTM0VbD
Any idea what I am doing wrong here? 知道我在这里做错了吗? How do I use my own custom shipping method and set custom price and title? 如何使用自己的自定义送货方式并设置自定义价格和标题?
Its very simple to add shipping method for order generated programmatically, 添加以编程方式生成的订单的运输方式非常简单,
Follow above steps 遵循以上步骤
$shippingAddress =$_quote->getShippingAddress()->addData($ShippingAddress);
$shippingAddress->setShippingMethod('methodname_methodname')->setCollectShippingRates(true)->collectShippingRates()->setPaymentMethod('methodcode'); //
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.