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

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.



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

Avatar

Manisha Gaidhane

November 20th, 2013 at 5:37 am

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

Comment Form

Leave a Reply

Your email address will not be published. Required fields are marked *

*

Categories

Latest comments


    Fatal error: Uncaught Error: Call to undefined function split() in /home4/nos/public_html/naveenos.com/wp-content/themes/smoker/functions.php:72 Stack trace: #0 /home4/nos/public_html/naveenos.com/wp-content/themes/smoker/sidebar.php(11): mdv_recent_comments() #1 /home4/nos/public_html/naveenos.com/wp-content/themes/smoker/single.php(47): include('/home4/nos/publ...') #2 /home4/nos/public_html/naveenos.com/wp-includes/template-loader.php(74): include('/home4/nos/publ...') #3 /home4/nos/public_html/naveenos.com/wp-blog-header.php(19): require_once('/home4/nos/publ...') #4 /home4/nos/public_html/naveenos.com/index.php(17): require('/home4/nos/publ...') #5 {main} thrown in /home4/nos/public_html/naveenos.com/wp-content/themes/smoker/functions.php on line 72