Search code examples
magentomagento-1.7

Magento create shipment with tracking number programmatically


From a specific order I want to create shipment of that order and also allot tracking number to it programmatically. Please help . Thanks


Solution

  • The question was just for knowledge sharing purpose .

    One can understand some points from Ref_Link

    // $order_id = Order ID
    $_order = Mage::getModel('sales/order')->load($order_id);
    
    if($_order->canShip())
    {           
        $shipmentId = Mage::getModel('sales/order_shipment_api')->create($_order->getIncrementId(), $itemsarray ,'your_comment' ,false,1);
        echo $shipmentId;   // Outputs Shipment Increment Number
        $trackmodel = Mage::getModel('sales/order_shipment_api')
        ->addTrack($shipmentId,'your_shipping_carrier_code','your_shipping_carrier_title','carrier_tracking_number');
    }
    

    $itemsarray = format explained here Ref_link
    Thats it !
    A simple code snippet .
    Hope it helps someone .