How to programmatically add shipment with a tracking number to any order : PART II

shipment-tracking

May 15, 2012 | In: How to do, Magento, php, web development, web services

In my previous post [How to programmatically add shipment with a tracking number to any order : PART I], you found that how can we generate shipment for an order programmatically. Here we are going to learn next step to add tracking number with generated shipment.

We are assuming that you are going to use UPS (United Parcel Service) shipping method for site order. Once you submitted your order to UPS, will get a tracking number from UPS dealer. And now you have to add this tracking number with your order on site.

	$trackingDetail = array(
		'carrier_code' => 'ups',
		'title' => 'United Parcel Service',
		'number' => 'TORD23254WERZXd3', // Replace with your tracking number
	);
 
	$track = Mage::getModel('sales/order_shipment_track')->addData($trackingDetail);
	$shipment->addTrack($track);

Here, ‘$shipment’ is an object generated in previous post. Please check in my previous post: [Related Post

$transactionSave = Mage::getModel('core/resource_transaction')
	->addObject($shipment)
	->addObject($shipment->getOrder())
	->save();

And you will find that this tracking number has been attached with shipment.

You may also like these related posts

  • Manisha Gaidhane

    I want to add track link for shipment how can i do it ? like in admin side ” Track this shipment ”

Categories

By Google