Create multi shipment for order programmatically

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 multi shipment for Magento automatically.

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

$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.

$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();
}

Try to use the code to test yourself in development environment. Happy coding!

7 thoughts on “Create multi shipment for order programmatically”

7 Responses to Create multi shipment for order programmatically

  • vikas

    Hi,

    can we create multiple shipment for an order without using a program, using localhost?

    regards

    vikas rao....

  • Neo

    I do not really understand your question.

  • Md Mazaharul Huq
    Md Mazaharul Huq on February 19, 2014 at 5:53 am said:

    I would like to know a things

    Is it possible to make

    Suppose i have 1 order with 10 product.

    What i want

    When Y product will be shipped then a shipping will be added in the magento order with X product info & their tracking number (if they are same then we will take the unique one)

    After certain day when
    When Y products will be shipped then a shipping will be added in the magento order with X product info & their tracking number (if they are same then we will take the unique one)

    When all the product will be completed .

    How can i do it

  • Neo

    I think it can be done in the admin panel. When you ship one product of the order, you can create the first shipment for that order. When you ship a new product, you can create new shipment. For each shipment, you can have its own tracking number.

  • Suvash Kumar Shah
    Suvash Kumar Shah on April 18, 2014 at 12:23 pm said:

    Thanks for the code,
    The scenario is, I want to create a module which have the facility to store the details of the vendor and when an order is place the vendor will get the email notification of the same automatically. But i don't know where and how to start.

    Thanks in advance.

  • John
    John on July 3, 2014 at 5:28 pm said:

    This is after the order is created right?
    This doesn't handle the multiple shipment rate calculations?

    Thanks

  • Saran

    I need to create multiple invoice and shipment for an order.
    Invoice can be of type,
    i) Order with one product, invoice and shipment can be generated based on the number of products
    ii) Order with 2 or three product, invoice and shipment can be generated based on each product.
    Can you please help me on that?

Comments