Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 840
Nikhil_K_R Avatar asked Jun 09 '14 08:06

Nikhil_K_R


1 Answers

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 .

like image 116
Nikhil_K_R Avatar answered Sep 22 '22 12:09

Nikhil_K_R