hello, how do I set it off as tracking number of shipment ?
Solved! Go to Solution.
Hi @totti240282
Here's an example:
// Shipment ID. Use the right value $shipment_id = 1; // Get shipment instance $shipment = Mage::getModel('sales/order_shipment')->load($shipment_id); // Create tracking instance and add the info to shipment Mage::getModel('sales/order_shipment_track') ->setShipment($shipment) ->setData('title', 'Method') // Shipping method title that you'll see for tracking ->setData('number', '123456789') // The tracking code ->setData('carrier_code', 'shipping_method_code') // Shipping method valid code ->setData('order_id',$shipment->getOrderId()) ->save();
In that case you can get the Order and then you'll need to iterate between the Order Shipments.
Something like:
$order_id = 1; $order = Mage::getModel('sales/order')->load($order_id); $shipment = $order->getShipmentsCollection()->getFirstItem(); $shipment_id = $shipment->getId();
The problem with this example is that in theory you can have more than 1 shipment per order. In that case I'm not sure (without reading your courier documentation) how to handle this scenario to avoid errors with references and IDs,
If you are pretty sure that you'll have just 1 Shipment per Order, this could work.
Hi @totti240282
Here's an example:
// Shipment ID. Use the right value $shipment_id = 1; // Get shipment instance $shipment = Mage::getModel('sales/order_shipment')->load($shipment_id); // Create tracking instance and add the info to shipment Mage::getModel('sales/order_shipment_track') ->setShipment($shipment) ->setData('title', 'Method') // Shipping method title that you'll see for tracking ->setData('number', '123456789') // The tracking code ->setData('carrier_code', 'shipping_method_code') // Shipping method valid code ->setData('order_id',$shipment->getOrderId()) ->save();
$shipment_id is order_id ?
No, that's the Shipment ID.
You can create a shipment without tracking number.
When a user places an order and I will send the products to the carrier, to import the tracking number I do not need the order number? How would I know through Shipment ID ?
Hi @totti240282,
Knowing the Shipment ID allows you to get the Order ID.
Take a look at:
... ->setData('carrier_code', 'shipping_method_code') ->setData('order_id',$shipment->getOrderId()) // Here you'll find the Order ID for your Shipment ->save(); ...
Is this what you're asking for?
the problem that I send to the courier the order id, and he sends a csv with id order and the tracking number list.
i export csv file that containd id_order and date of order e shipping.
In that case you can get the Order and then you'll need to iterate between the Order Shipments.
Something like:
$order_id = 1; $order = Mage::getModel('sales/order')->load($order_id); $shipment = $order->getShipmentsCollection()->getFirstItem(); $shipment_id = $shipment->getId();
The problem with this example is that in theory you can have more than 1 shipment per order. In that case I'm not sure (without reading your courier documentation) how to handle this scenario to avoid errors with references and IDs,
If you are pretty sure that you'll have just 1 Shipment per Order, this could work.
Thanks do the tests and if I write problems yet.