How to get the shipment number of an order item?
-
12-12-2019 - |
Question
Once an order is placed, I programmatically generate associated shipments (because of different manufacturing time on my products)
I can then have for a single order several associated shipments:
ex:
- Shipment #100000110 in 2 days for items 1 and 2
- Shipment #100000111 in 5 days for item 3
I would like to access the shipment number associated to specific item :
something like :
$order = Mage::getModel('sales/order')->load($_order_id);
$_items = $order->getAllItems();
foreach ($_items as $_item)
{
$ciid = $_item->getId();
$shipmentNbr = $_item->getShipment()->getIncrementId();
...
}
Thank your for your help,
Solution
If you have the $orderItem
, you can easily get all the ShipmentItems:
$shipmentItems = Mage::getResourceModel('sales/order_shipment_item_collection')
->addFieldToFilter('order_item_id', $orderItem->getId());
foreach ($shipmentItems as $shipment_item) {
if ($shipment_id = $shipment_item->getParentId()) {
$shipment = Mage::getModel('sales/order_shipment')->load($shipment_id);
}
}
if this doesn't work, you need to load the shipment based on the $item->getParentId()
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange