我從一個導入文件中創建Magento的貨件,該文件讀取將逐行運送的訂單商品,但在創建貨件並將我遇到的第一個項目添加到困難中後。我正在創建這樣的貨件:如何在Magento中以編程方式將訂單項添加到現有貨件中?
$itemsData = array(
'qtys' => array(
$orderItem->getId() => $importData['qty placed'],
)
);
$shipment = Mage::getModel('sales/service_order', $order)
->prepareShipment($itemsData['qtys']);
$shipment->addComment("Shipment created from shipment importer", false);
$shipment->register();
$shipment->getOrder()
->setIsInProcess(true);
$shipment->setShippingCost($shipCost);
if (isset($trackingNumber)) {
$this->addTrack($shipment, $importData); //this function adds the tracking data
}
if ($order->getCustomerEmail()) {
$shipment->setEmailSent(true);
$shipment->sendEmail(true, '');
}
$transactionSave = Mage::getModel('core/resource_transaction')
->addObject($shipment)
->addObject($shipment->getOrder());
$transactionSave->save();
$shipment->save();
這對第一件物品很好,但對於具有多件物品的貨件我無法將下一件物品添加到貨件。我想添加後續項目是這樣的:
//I first load the existing shipment
$shipItem = Mage::getModel('sales/order_shipment_item');
$shipItem->setShipment($shipment);
$shipItem->setOrderItem($orderItem);
$shipItem->setQty($qtyShipped);
$shipItem->register();
$shipment->addItem($shipItem);
$transactionSave = Mage::getModel('core/resource_transaction')
->addObject($shipment)
->addObject($shipment->getOrder());
$transactionSave->save();
$shipment->save();
現在在管理員的順序查看/信息頁,第二項仍然說「發票」而不是「發貨」,當我點擊發運標籤的總數量列爲'1'而不是2,但是當我點擊該貨件查看詳細信息時,這兩項都列出。所以它似乎有點工作,但不是真的
並非所有項目都會發貨,所以我不能只加載訂單並將它們全部標記爲已發貨。 關於我如何完成這項工作的任何想法?在此先感謝;)
我不知道了'銷售/ service_order'是什麼,通常使用'銷售/訂單' –