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

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.


Comments

One response to “How to programmatically add shipment with a tracking number to any order : PART II”

Leave a Reply

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

*