我想获得给定订单尚未发货的所有商品。
假设我有部分发货订单,我想要检索所有待发货的商品。
类似的东西:
$collection = Mage::getModel('...')->getCollection()
->Add...()
答案 0 :(得分:3)
要获取订单的所有项目,请使用项目集合:
$order = Mage::getModel('sales/order')->load($orderId);
$orderItems = $order->getItemsCollection();
然后使用货件模型获取订单的所有项目:
$shippedItems = Mage::getModel('sales/order_shipment')
->setOrder($order)->getItemsCollection();
Edit2:事实证明,设置订单上的订单无法获取物品集合,因为订单可能有多个货件。请改用下面提供的代码段。
编辑:我忘记了可能有多个货件,所以这里有完整的工作代码来获取订单商品的所有ID和所有装运的ID:
$orderId = 15;
$order = Mage::getModel('sales/order')->load($orderId);
$orderItems = $order->getItemsCollection();
$allOrderItemIds = $orderItems->getAllIds();
$shipments = $order->getShipmentsCollection();
$shippedItemIds = array();
foreach ($shipments as $shipment) {
$shippedItems = $shipment->getItemsCollection();
foreach ($shippedItems as $item) {
$shippedItemIds[] = $item->getOrderItemId();
}
}
var_dump($allOrderItemIds);
var_dump($shippedItemIds);
答案 1 :(得分:2)
$orderId = 382;
$order = Mage::getModel('sales/order')->load($orderId);
// OR if you load the order with increment id ...
// $order = Mage::getModel('sales/order')->loadByIncrementId($orderId);
$orderItems = $order->getItemsCollection();
foreach ($orderItems as $item) {
$qtyToBeShipped = $item->getQtyOrdered() - $item->getQtyShipped();
if ($qtyToBeShipped)
echo $item->getId() . ' - ' . $qtyToBeShipped . '</br>';
}