Add Tracking number inside a shipped order.

<?php

error_reporting(E_ALL & ~E_WARNING);
ini_set(‘display_errors’, TRUE);

require_once ‘../../../app/Mage.php’;
Mage::app();

 $order_id=12380;
$shipment_collection = Mage::getResourceModel(‘sales/order_shipment_collection’);
$shipment_collection->addAttributeToFilter(‘order_id’, $order_id);

echo (string) $shipment_collection->getSelect();

foreach($shipment_collection as $sc) {
    $shipment = Mage::getModel(‘sales/order_shipment’);
    $shipment->load($sc->getId());
    if($shipment->getId() != ”) {
        $track = Mage::getModel(‘sales/order_shipment_track’)
                 ->setShipment($shipment)
                 ->setData(‘title’, ‘Citylink’)
                 ->setData(‘number’, ‘$track_no’)
                 ->setData(‘carrier_code’, ‘custom’)
                 ->setData(‘order_id’, $shipment->getData(‘order_id’))
                 ->save();
    }
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s