我试图以编程方式为订单创建一个货件,它在我下面复制时抛出错误。
我的代码:
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 />
有人可以解释一下这意味着什么,为什么我会收到这个错误?
亲切的问候
JEY
答案 0 :(得分:0)
你得到一个PHP错误,不一定是Magento错误。 Mage_Sales_Model_Order_Shipment
没有方法create()
。你要的是一些不存在的东西。
查看Mage_Sales_Model_Order_Shipment_Api::create()
以了解如何创建新货件。
另请参阅:In magento, how to add shipment and track number to order
您使用Mage_Sales_Model_Order_Shipment::addItem()
构建货件,然后使用Mage_Sales_Model_Order_Shipment::save()
“创建”。