I need to check if an order has already some shipment set. The only data I can use is the increment id of the order. I'm getting an instance of a model order, but I don't see a way I can get a shipment instance.
I'm using this code:
$order = Mage::getModel('sales/order')
->loadByIncrementId($order_increment_id);
But how can I get a shipment instance? I know that I can call Mage::getModel('sales/order_shipment')->loadByIncrementId($shipment_increment_id)
but how do I get the shipment increment id?
You can get the Shipment collection data for the specific shipment by shipment id in Magento 2. Using Magento\Sales\Api\ShipmentRepositoryInterface interface, you need to use get() method to fetch shipment data by its id. Pass shipment id as get method, get($shipmentId) arguments.
Go to Admin -> Sales -> Orders. Filter out all orders with the Processing status. Select the one you want to invoice: click View in the Action column. There is the Invoice option in the header of the sales order.
After the order is placed, the admin can add order details and tracking number from the backend. Admin can also track order from the backend using the Order Tracking Extension for Magento 2. The customers can track order from their My Account section in a tabular detailed format.
Just to make it complete Mage_Sales_Model_Order
has public method:hasShipments()
which returns number of shipments and internally uses mentioned getShipmentsCollection()
.
Assume that the person who wrote this might have also needed to do what you need to do. Generally, when Magento objects have a one to many relationship you can find a method to load the many on the one.
You've got a class alias sales/order
.
This corresponds to Mage_Sales_Model_Order
(in a stock installation).
You can find this class at app/code/core/Mage/Sales/Model/Order.php
.
If you examine this class, there are 7 methods with the word "ship" in them
function canShip
function setShippingAddress
function getShippingAddress
function getShip
function getShipmentsCollection
function hasShip
function prepareShip
Of those 7, only the semantics of getShipmentsCollection
indicate a method for grabbing an order's shipments. So try
foreach($order->getShipmentsCollection() as $shipment)
{
var_dump(get_class($shipment));
//var_dump($shipment->getData());
}
Or take a look at the source for getShipmentsCollection
public function getShipmentsCollection()
{
if (empty($this->_shipments)) {
if ($this->getId()) {
$this->_shipments = Mage::getResourceModel('sales/order_shipment_collection')
->setOrderFilter($this)
->load();
} else {
return false;
}
}
return $this->_shipments;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With