Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get Shipment Increment ID by Order ID in Magento

Tags:

php

magento

Hello Guys. Can someone tell me how to get the shipment increment id by order id in Magento ?

I need this because I use an outside php file to add tracking information to a shipment and it needs the shipment id for this.

Thank you for all your help.

I am using the code below to add tracking info

$shipmentIncrementId='300000002';
$trackNumber='123456';
$carrier='custom';
$title='server10';


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

         /* @var $shipment Mage_Sales_Model_Order_Shipment */



         $track = Mage::getModel('sales/order_shipment_track')
                     ->setNumber($trackNumber)
                     ->setCarrierCode($carrier)
                     ->setTitle($title);

         $shipment->addTrack($track);

         try {
             $shipment->save();
         } catch (Mage_Core_Exception $e) {
             $thiss->_fault('data_invalid', $e->getMessage());
         }

         return $track->getId();

print_r($shipment);
like image 892
user3127781 Avatar asked Dec 22 '13 21:12

user3127781


People also ask

How can I get increment ID in Magento 2?

It can be done using Magento\Sales\Api\OrderRepositoryInterface interface, all you need to do is use getList() function to fetch order data by order increment id. That's it.


1 Answers

In theory an order can have more than one shipment. But if you make a convention to always have one single shipment per order you can get its increment id like this:

$orderIncrementId = 120000012;
$order = Mage::getModel('sales/order')->loadByIncrementId($orderIncrementId);
$shipment = $order->getShipmentsCollection()->getFirstItem();
$shipmentIncrementId = $shipment->getIncrementId();
like image 168
Marius Avatar answered Sep 21 '22 02:09

Marius