I am looking at some code to add MassAction
in Magento and ship and complete multiple orders from sales_order/index
Somehow the orders are not being shipped.
It looks like (a perfectly normal order) is not passing the canship()
test. Should it be passsed $order
of $orderid
?
Here's my code
//Get orderids
$orderIds = $this->getRequest()->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')->loadByIncrementId($orderId);
// Is the order shipable?
if($order->canShip())
{
$itemQty = $order->getItemsCollection()->count();
// This first definition and 2nd look overlapping, our one is obsolete?
$shipment = Mage::getModel('sales/service_order', $order)->prepareShipment($itemQty);
$shipment = new Mage_Sales_Model_Order_Shipment_Api();
// But still, no shipment, why?
$shipmentId = $shipment->create($orderId, array(), 'Shipment created through ShipMailInvoice', true, true);
code
Trace:Order/Shipment/Api.php(142): Mage_Api_Model_Resource_Abstract->_fault('order_not_exist...') Sales/OrderController.php(45): Mage_Sales_Model_Order_Shipment_Api->create('121', Array, 'Shipment create...', true, true)code
– Remonstrant