title: Magento how do I programmatically ship orders?
body: <p>I am looking at some code to add <code>MassAction</code> in Magento and ship and complete multiple orders from <code>sales_order/index</code> </p>
  
  <p>Somehow the orders are not being shipped. </p>
  
  <p>It looks like (a perfectly normal order) is not passing the <code>canship()</code> test. Should it be passsed <code>$order</code> of <code>$orderid</code>?</p>
  
  <p>Here's my code</p>
  
  <pre><code>//Get orderids
  $orderIds = $this-&gt;getRequest()-&gt;getPost('order_ids');
  
  //verify if the array is not empty
  if (!empty($orderIds)) {
  //loop through orders
  foreach ($orderIds as $orderId) {
  
  // Dont know what this does
  $order = Mage::getModel('sales/order')-&gt;loadByIncrementId($orderId);
  
  // Is the order shipable?
  if($order-&gt;canShip())
  {
  $itemQty =  $order-&gt;getItemsCollection()-&gt;count();
  // This first definition and 2nd look overlapping, our one is obsolete?
  $shipment = Mage::getModel('sales/service_order', $order)-&gt;prepareShipment($itemQty);
  $shipment = new Mage_Sales_Model_Order_Shipment_Api();
  
  // But still, no shipment, why?
  $shipmentId = $shipment-&gt;create($orderId, array(), 'Shipment created through ShipMailInvoice', true, true);
  </code></pre>