2

I've looked at

How to get ordered items associated with tracking numbers?

How to Access Shipment from Order ID and product ID?

How to get the shipment number of an order item?

Create part shipment and check if item has been shipped

None have worked for what I'm trying to do.

I have the shipment ID in a variable $shipid. Is there anyway to get the products that go with the shipment ID?

I have my figures crossed!

Thanks

2 Answers 2

3

First you need to load the shipment:

$shipment = Mage::getModel('sales/order_shipment')->load($shipid);

If you're using the increment id, you'll have to use:

$shipment = Mage::getModel('sales/order_shipment')->loadByIncrementId($shipid);

Once you have the shipment loaded, you can retrieve the items collection:

$itemsCollection = $shipment->getItemsCollection(); 

Finally to get the product from the items you can loop through the item collections:

foreach($itemsCollection as $item)
{
    $_product = $item->getProduct();
}
5
  • I'm working on it. Let you know
    – Freejoy
    May 18, 2016 at 15:03
  • I get an error when I echo $_product->getName(); returns null. $array = array($_product);print_r(array_values($array)); returns Array ( [0] => ). But $array = array($item);print_r(array_values($array)); returns [name] => Chess Set [sku] => 100022 in the array
    – Freejoy
    May 18, 2016 at 19:20
  • @Freejoy in that case you can do $product = Mage::getModel('catalog/product')->load($item->getSku(),'sku'); to load your product May 18, 2016 at 19:22
  • 1
    I just got it! After two days. I changed $item->getProduct(); to $item->getName(); then echo $_product; And it worked.Thanks You were so close I mark it as correct
    – Freejoy
    May 18, 2016 at 19:30
  • @Freejoy I'm glad we got it working :) May 18, 2016 at 19:38
1

change $item->getProduct(); To $item->getData();

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.