【发布时间】:2013-03-27 10:53:30
【问题描述】:
这是什么意思?
我试图以编程方式为订单创建发货,它抛出了一个错误,如下所示。
我的代码:
if (!$order->canShip()) {
echo 'can not ship this order';
return false;
}
$itemQty = $order->getItemsCollection()->count();
$shipment = Mage::getModel('sales/service_order', $order)
->prepareShipment($itemQty);
$shipmentId = $shipment->create($order->getIncrementId(), $itemQty, 'Shipment created through ShipMailInvoice', true, true);
错误是:
<b>Fatal error</b>: Uncaught exception 'Varien_Exception' with message 'Invalid method Mage_Sales_Model_Order_Shipment::create(Array
(
[0] => $orderId
[1] => 8
[2] => Royal mail Shipment
[3] => 1
[4] => 1
)
)'
in /home/toesocks/public_html/lib/Varien/Object.php:569
Stack trace:
#0 /home/toesocks/public_html/product_scanning/v2/functions/orderDispatch.php(82): Varien_Object->__call('create', Array)
#1 /home/toesocks/public_html/product_scanning/v2/functions/orderDispatch.php(82): Mage_Sales_Model_Order_Shipment->create('15300007141', 8, 'Shipment create...', true, true)
#2 {main}
thrown in <b>/home/toesocks/public_html/lib/Varien/Object.php</b> on line <b>569</b><br />
有人能解释一下这是什么意思吗?为什么会出现这个错误?
亲切的问候
杰
【问题讨论】:
-
嗨 Rob,
if (!$order->canShip()) { echo '无法运送此订单';返回假; } $itemQty = $order->getItemsCollection()->count(); $shipment = Mage::getModel('sales/service_order', $order) ->prepareShipment($itemQty); $shipmentId = $shipment->create($order->getIncrementId(), $itemQty, '通过 ShipMailInvoice 创建的货件', true, true); -
@Rob,您的意思是用该代码编辑问题?如果是这样,我已经编辑了问题。
-
创建货件的前提条件很少。你确定这些前提条件已经满足吗?
-
嗨@SatishMantri,我已经解决了这个问题,但由于某种原因我无法更改订单状态。我希望在创建货件后将订单状态设置为已完成。由于某种原因,它没有改变状态 CODE : $history = Mage::getModel('sales/order_status_history') ->setStatus('complete') ->setComment($cmets); $order->addStatusHistory($history); $订单->保存();你认为你能帮我解决这个问题吗?