0

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,

1 Answer 1

1

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()

4
  • Thank you for your help. I do not manage to make it work…But I think I have something wrong with my shipments. when i do $_shipments = $order->getShipmentsCollection(); it returns nothing, whereas when I look at my shipment in backends, it is well associated to the good order...
    – Alexglvr
    Commented Feb 17, 2015 at 10:29
  • $order->getShipmentsCollection() now works. i can sweep the items of a shipment, but the IDs are different of the IDs in the order… Is there a way from a shipment item to get the ID it has in the order?
    – Alexglvr
    Commented Feb 17, 2015 at 12:24
  • I got it : $orderitemID = $_shipItem->getOrderItem()->getId();
    – Alexglvr
    Commented Feb 17, 2015 at 12:51
  • you can just use $_shipItem->getOrderItemId() Commented Feb 17, 2015 at 14:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.