Magento Themes and Magento Extensions

Magento: Create multi shipment for an order programmatically

Share

This is another post for Magento programmer who needs to work with an extension for creating shipment for Magento order. You will need to use this when you have a module which connects Magento store with a vendor store. Basically, you need to program a script to create shipment for Magento automatically.

First, you will need to load an order using order increment id:

1
$order = Mage::getModel('sales/order')->loadByIncrementId($orderId);

Each order can contain more than one item. You can create a shipment for each shipped item. This is really helpful when you have an order of 2 items from 2 different vendors. Of course, they have different shipments.

Here is how I create shipment for the item available for that shipment.

1
2
3
4
5
6
7
8
$shipmentItems = array();
foreach ($shipmentItems as $item) {
$shipmentItems [$item->getId()] = $item->getQuantity();
}
if ($order->getId() && !empty($shipmentItems) && $order->canShip()) {
$shipment = Mage::getModel('sales/service_order', $order)->prepareShipment($shipmentItems);
$shipment->save();
}

Leave a Reply

You must be logged in to post a comment.