October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PCOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk3 min

Get the Shipment ID Associated With a Product in Magento 1 PHP

Use Magento 1’s shipment model and getItemsCollection() to list only the products assigned to a shipment, while avoiding the array/object error caused by mixing tracking data with shipment models.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

In Magento 1, retrieve the shipment model by its shipment increment ID, then iterate that shipment’s item collection. The collection contains only the products assigned to that shipment, so it prevents products from other shipments in the same order appearing again.

Load a shipment and list its products

Use loadByIncrementId() on sales/order_shipment. In this example, $shipid must contain a shipment increment ID such as 37006 or 37014, not the order increment ID.

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

$items = $shipment->getItemsCollection();

foreach ($items as $item) {
    echo '<div>' . htmlspecialchars($item->getName(), ENT_QUOTES, 'UTF-8') . '</div>';
}
?>

The accepted SitePoint solution uses this same model-and-collection pattern; the original poster confirmed that it worked in the Magento 1 context (SitePoint discussion).

Keep shipment data separate from order data

Collection or object What it represents Use when
$shipment->getItemsCollection() Items assigned to one shipment You need to show the products shipped under a particular shipment ID
Order-level item collection All items belonging to the order You need the complete order contents, regardless of shipment assignment
Tracking-data array Carrier/tracking details collected by your template You need tracking numbers or carrier information, not shipment products

Magento’s order model exposes an order-level item collection, but that is not the shipment-specific collection needed here (OpenMage Magento 1.9 source). If an order is split between shipments 55555 and 77777, iterate the item collection from shipment 55555 for the first group and the collection from shipment 77777 for the second.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Why the “call to a member function … on array” error occurs

The failed template built $shipTrack by looping over an order’s shipment collection and storing tracking details under each shipment increment ID. Each $_results value was therefore an array of tracking records, not a shipment object. Calling getAllItems() on that value caused the fatal error because PHP cannot invoke a Magento model method on an array.

Use the right value for each operation

  • Use a shipment model to obtain shipped items: $shipment->getItemsCollection().
  • Use tracking records for carrier and tracking-number output.
  • Do not assume an array of tracking details has shipment-model methods.

Displaying every item correctly

The forum snippet assigns $_product inside the loop and echoes after the loop. That placement displays only the final item. Put the output inside the loop when every shipped product must be shown.

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

foreach ($shipment->getItemsCollection() as $item) {
    echo '<div class="shipment-item">';
    echo '<span class="name">'
        . htmlspecialchars($item->getName(), ENT_QUOTES, 'UTF-8')
        . '</span>';
    echo '</div>';
}
?>

Iterating all shipments for an order

If the page already has an order object and must render each shipment separately, keep the shipment loop and item loop nested. The inner loop must use the current shipment’s collection.

<?php
foreach ($order->getShipmentsCollection() as $shipment) {
    echo '<h3>Shipment '
        . htmlspecialchars($shipment->getIncrementId(), ENT_QUOTES, 'UTF-8')
        . '</h3>';

    foreach ($shipment->getItemsCollection() as $item) {
        echo '<div>'
            . htmlspecialchars($item->getName(), ENT_QUOTES, 'UTF-8')
            . '</div>';
    }
}
?>

Using the full order item collection inside that outer loop would repeat every order product under every shipment instead of preserving shipment membership.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Checks before deploying the template

  1. Confirm that the value passed to loadByIncrementId() is the shipment increment ID, not the order increment ID.
  2. Verify that the shipment exists before rendering its items; a missing or invalid ID should be handled by the surrounding template rather than assumed valid.
  3. Call getItemsCollection() on the shipment model, not on tracking arrays.
  4. Place per-item output inside the item loop.
  5. Test against the store’s local Magento 1 installation, especially if extensions or rewrites modify sales models.

What this pattern does—and does not—provide

The collection gives you the shipment’s item records and their product names. The basic example does not implement carrier display, tracking numbers, product images, custom options, or shipped quantities. Those require reading the corresponding fields and models in the target store’s shipment and tracking implementation.

This is Magento 1 syntax using Mage::getModel(); Magento 2 service contracts and factories are a different API and should not be substituted into this code.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

The Bottom Line

For a product’s shipment association in Magento 1, work from the shipment model: load it by shipment increment ID and iterate getItemsCollection(). Keep tracking arrays and order-wide item collections out of that shipment-specific loop.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Leave a Reply

Your email address will not be published. Required fields are marked *

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. Shenzhen desk3 min
    HONOR Expands Beyond Smartphones With Humanoid Robot RevealHONOR said it unveiled its first humanoid robot at MWC 2026 and named shopping assistance, workplace inspections, and supportive companionship as intended uses. Later Robotics D1 claims and a reported…
  2. Cupertino desk5 min
    Apple Unveils AirPods Max 2: The Upgrade That Should Have Happened Years AgoAirPods Max 2 adds H2-powered audio features and Apple claims up to 1.5× more effective ANC, but its design, Smart Case, and 20-hour battery rating are unchanged. Wired lossless audio…
  3. Cupertino desk4 min
    Apple’s OLED Touch MacBooks Are Coming—but the Dynamic Island Is the Real GambleApple has not announced an OLED touchscreen MacBook, but reports point to high-end models arriving in late 2026 or early 2027. The reported Mac Dynamic Island could be useful, but…
Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.