1

I am running a cronjob to create shipments.

Method 1, shipment is created but order is not updated to complete:

$shipmentItems = [];
$comment = '';
/* @var $item Mage_Sales_Model_Order_Item */
foreach ($order->getAllItems() as $item) {

    $comment .= trim("{$item->getSku()}: {$item->getQtyOrdered()}\r\n");

    $shipmentItems[$item->getId()] = $item->getQtyOrdered();
}

Mage::helper('ffm_fulfillment/api')->log("With items {$comment}", Zend_Log::INFO);

$shipmentId = Mage::getModel('sales/order_shipment_api')->create(
    $order->getIncrementId(),
    $shipmentItems,
    $comment,
    false, // email
    false // include comment in email
);

Method 2: Shipment is created and order is updated to complete:

$itemQtys = [];$comment = '';
foreach ($order->getAllItems() as $orderItem) {
    if ($orderItem->getQtyToShip() && !$orderItem->getIsVirtual()) {
        $comment .= trim("{$orderItem->getSku()}: {$orderItem->getQtyOrdered()}\r\n");
        $itemQtys[$orderItem->getId()] = $orderItem->getQtyToShip();
    }
}
$shipment = Mage::getModel('sales/service_order', $order)->prepareShipment($itemQtys);
$shipment->register();
$shipment->addComment(
    $order->getIncrementId(),
    $itemQtys,
    $comment,
    false, // email
    false // include comment in email);
);
$order->setIsInProcess(true);
Mage::getModel('core/resource_transaction')
    ->addObject($shipment)
    ->addObject($order)
    ->save();

My question is , why by using method 1 order is not updated to complete ?

Thank you

  • have you generated invoice too ? generating invoice is must to set order complete – Shashank Kumrawat Oct 29 '18 at 14:09
  • yes, I have a paid invoice – Attila Naghi Oct 29 '18 at 14:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.