如何在编程创建订单时添加送货速度
-
12-12-2019 - |
题
运送方法添加正在发生,因为它应该是。但是,根据送货方式的运费,或者,定制送货速率没有添加到订单中。
$address = $quoteObj->getShippingAddress ();
$address->setCollectShippingRates ( true )->collectShippingRates()
->setShippingMethod('flatrate_flatrate');
$quoteObj->collectTotals ()->save ();
.
通过其他一些问题搜索我找到了一个解决方案,该解决方案为订单添加了定制运输速度,但它不会将运费添加到总计。
$shippingprice = 0.9;
$orderObj->setShippingAmount($shippingprice);
$orderObj->setBaseShippingAmount($shippingprice);
.
解决方案
试试:
$shippingprice = 0.9;
$orderObj->setShippingAmount($shippingprice);
$orderObj->setBaseShippingAmount($shippingprice);
$orderObj->setGrandTotal($orderObj->getGrandTotal() + $shippingprice); //adding shipping price to grand total
$orderObj->save();
. 其他提示
你得到了这个解决了吗?
对于跑步的任何人,您需要在2个地方设置运费。 首先,您需要设置送货方式,并在您需要设置价格的运输方法中。我制作了我自己的setshippingmethod函数,如下所示:
public function setMyShippingMethod($shippingPrice = 0)
{
$result = Mage::getModel('shipping/rate_result');
// Add carrier
$method = Mage::getModel('shipping/rate_result_method');
if ($shippingPrice > 0) {
// use my custom shipping method but you can use another shipment method here
$method->setCarrier('dpdelivery');
$method->setMethod('dpdelivery');
$method->setCarrierTitle('Shipping');
$method->setMethodTitle('outside the Netherlands');
$method->setPrice($shippingPrice);
$method->setCost($shippingPrice);
} else {
$method->setCarrier('flatrate');
$method->setMethod('flatrate');
$method->setCarrierTitle('Freeshipping');
$method->setMethodTitle('within the Netherlands');
$method->setPrice($shippingPrice);
$method->setCost($shippingPrice);
}
$result->append($method);
return $result;
}
.
然后在我的createOrder函数中我添加shippingaddress,然后调用我这样的方法:
$shippingMethod = $this->setMyShippingMethod($shippingCost);
$this->_order->setShippingAddress($shippingAddress)
->setShippingMethod($shippingMethod);
$this->_order->setShippingDescription('My shipping description');
.
然后当然,我仍然需要将成本添加到订单中,如上所述:
$this->order->setIsVirtual(0)
....
->setShippingAmount($shippingCost)
->setShippingTaxAmount($shippingCostTax)
.
我希望它有助于任何人。
试试这个
$order->setShippingAmount($shippingprice);
$order->setBaseShippingAmount($shippingprice);
$order->save();
.