I try to create programmatically a shipment of an order with a track code.
This is my current code :

$order = Mage::getModel('sales/order')->loadByIncrementId("100014930");
$shipment = Mage::getModel('sales/service_order', $order)->prepareShipment($order->getItemQtys());

$arrTracking = array(
                'carrier_code' => $order->getShippingCarrier()->getCarrierCode(),
                'title' => $order->getShippingCarrier()->getConfigData('title'),
                'number' => "1234",

$track = Mage::getModel('sales/order_shipment_track')->addData($arrTracking);


With this, I have no error while I execute it.
In the Magento panel, you can't ship the order, but the order stay in pending and the shipment doesn't appear.
Please help

Problem solved with this solution

  • Without any errors is hard to help you. Check all logs, also if logging is on and make sure display_errors is enabled Sep 8, 2015 at 14:34

1 Answer 1


I think I've found your error. getItemQtys is not a valid function on any Magento class, so in Magento magic methods it returns null. Essentially you're trying to ship null number of items. You can't do that. Yes, it fails silently.

Some controllers implement a _getItemQtys method to return the values you're looking for; however none of these are plug and play. Instead I suggest you create this as it's just a keyed array in the format of:


However, if you're always shipping all items in a shipment, without exception there is an even easier way:


Please read this answer here for more information on how to create shipments programmatically:


  • I replaced the getItemsQty line with converter. When I execute, I got a Mage_Core_Exception "Cannot create an empty shipment" but when I var_dump the shipment (juste before saving it) I have all the information about it. Is it because loading the order like I did does make a Varien Object ? Sep 8, 2015 at 15:12
  • You needn't do anything (including save) just create the shipment with the $order.
    – philwinkle
    Sep 8, 2015 at 15:17
  • So i don't keep the line with $shipment->register() ? Do i keep the addTrack() things ? Now just nothing is happening, no error, no shipment created. Sep 8, 2015 at 15:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.