3
我正在開發一個程序,它必須以編程方式爲已支付和開具發票的訂單創建裝運。創建裝運不會更新物品的裝運數量和訂單不完整
問題是,即使在創建發貨後,訂單狀態仍然是「處理」而不是「完成」。 如果手動從後端運送,則不會發生這種情況。
我發現問題在於訂單商品的發貨數量未更新,但在保存裝運和訂單後仍爲0。
這是我正在使用的程序。 不會發出異常,並且正確創建了貨件。
$orders = $this->_orderCollectionFactory->create()
->addAttributeToSelect('*')
->addFieldToFilter('entity_id' , array('in' => $ordersIdsArr))
->setOrder('created_at', 'desc');
foreach ($orders as $index => $order) {
if ($order->canShip()) {
$shipment = $this->_convertOrder->toShipment($order);;
$orderItems = $order->getItemsCollection()->addAttributeToSelect('*')->load();
foreach ($orderItems as $orderItem) {
if (! $orderItem->getQtyToShip() || $orderItem->getIsVirtual()) {
continue;
}
$qtyShipped = $orderItem->getQtyToShip();
$shipmentItem = $this->_convertOrder->itemToShipmentItem($orderItem)->setQty($qtyShipped);
$shipment->addItem($shipmentItem);
}
$shipment->register();
$shipment->getOrder()->setIsInProcess(true);
try {
$saveTransaction = $this->_transactionFactory->create();
$saveTransaction->addObject($shipment)
->addObject($shipment->getOrder());
$saveTransaction->save();
} catch (\Exception $e) {
}
}
}
/*..........*/
任何線索?