我正在 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,但是当我单击时装运查看详细信息,两个项目都列出。所以看起来它有点工作,但不是真的
并非所有物品都会发货,所以我不能只加载订单并将它们全部标记为已发货。关于如何完成这项工作的任何想法?提前致谢 ;)