Get Shipment data by order increment id Magento 2.

You can get the Shipment collection for the specific order by order increment id in Magento 2.

Using Magento\Sales\Api\ShipmentRepositoryInterface interface, you need to use getList() function to fetch no. of Shipment by sales order increment id.

When you check the sales_shipment table, one field order_id is available in sales_shipment table so you first fetch the order id from the order increment id. Continue reading “Get Shipment data by order increment id Magento 2.”

Get Shipment data by order id Magento 2.

You can get the Shipment data or collection for the specific order by order id in Magento 2.

Using Magento\Sales\Api\ShipmentRepositoryInterface interface, you need to use getList() function to fetch no. of Shipment by sales order id.

Using SearchCriteriaBuilder Class, You need to use addFilter() method, filter by order id and pass searchCriteria object to getList() method of ShipmentRepositoryInterface.

Using the above way you got the output as Shipment records as an array and iterate over a loop to Shipment array to fetch no. of different Shipment record for an order.

Output:

 

Count total shipment for an order by order id Magento 2.

You can count the no. of Shipment generated for the specific order by order id in Magento 2.

Using Magento\Sales\Api\ShipmentRepositoryInterface interface you need to use getList() method with SearchCriteriaBuilder Object to add filter by order id.

Using Below code snippet, You can fetch the count of shipment for an order, Continue reading “Count total shipment for an order by order id Magento 2.”