In purple, how to add the shipping number and order number

I need to dynamically add shipping and shipping tracking to the order, it should be dynamic, because we will do it in batch mode, can you guys help me with this?

EDIT: The
user will see a page with a list of orders, then he will enter the track number for each and send the form, so I need to find a famous carrier and send all orders through it.

+5
source share
2 answers

If you have a list of order IDs and associated tracking numbers, you can

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

Then you can go through all the deliveries and add tracking, for example,

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', 'ShippingMethodName')
                 ->setData('number', $track_no)
                 ->setData('carrier_code', 'ShippingCarrierCode')
                 ->setData('order_id', $shipment->getData('order_id'))
                 ->save();
    }
}

.

+12

:)

    private function _createShipment($shipment, $itemsQty)
    {
        $itemsQtyArr = array();
        foreach ($itemsQty as $item)
        {
            $itemsQtyArr[$item->iExternalOrderId] = $item->dQtyShipped;
        }

        try
        {
            $shipmentIncrementId = Mage::getModel('sales/order_shipment_api')->create($shipment->sOrderNumber, $itemsQtyArr, $shipment->sShipmentComment, true, true);

            if ($shipmentIncrementId)
            {
                Mage::getModel('sales/order_shipment_api')->addTrack($shipmentIncrementId, $shipment->sCarrierCode, $shipment->sTrackingTitle, $shipment->sTrackingNumber);
            }
        }
        catch(Exception $e)
        {
            Mage::log('Exception: ' . $e->getMessage());
        }

        return $shipmentIncrementId ? true : false;
    }  
+3

All Articles