I have a developer who is saying he can not get the shipmentIncrementId to get the tracking number.
What is the procedure for getting the tracking number from an order?
I have a developer who is saying he can not get the shipmentIncrementId to get the tracking number.
What is the procedure for getting the tracking number from an order?
This is a silly example with Magento 1.9.2.4
<?php
ini_set('max_execution_time','1000');
set_time_limit(0);
$client = new SoapClient("http://www.yourstore.com/index.php/api/?wsdl");
try {
//Login
$session = $client->login("username", "password");
//Request shipment number 100000001
$result = $client->call($session, 'sales_order_shipment.info', '100000001');
//Store shipping information
$tracking_information = $result['tracks'];
echo "<pre>";
//$tracking_infrmation will be an array and can conatin multiple tracking codes. You'll need to iterate the variable and get the number value.
print_r($tracking_information);
echo "</pre>";
} catch (SoapFault $exception) {
echo "There were an error on your request\n\n";
echo "Code: " . $exception->faultcode . "\n";
echo "Message: " . $exception->faultstring . "\n";
}
//Logout
$client->endSession($session);
Here is the way to do that with SOAP V1 if you only have the order increment ID:
/** @var array $orderInfo */
$orderInfo = $client->call($session, 'sales_order.info', $orderIncrementId);
/** @var string $orderId */
$orderId = $orderInfo['order_id']; // Entity ID
/** @var array $filters */
$filters = array(
array('order_id' => array('eq' => $orderId))
);
/** @var array $orderShipments */
$orderShipments = $client->call($session, 'sales_order_shipment.list', $filters);
foreach ($orderShipments as $shipment) {
/** @var string $shipmentIncrementId */
$shipmentIncrementId = $shipment['increment_id'];
/** @var array $shipmentInfo */
$shipmentInfo = $client->call($session, 'sales_order_shipment.info', $shipmentIncrementId);
/** @var array $tracks */
$tracks = $shipmentInfo['tracks'];
foreach ($tracks as $track) {
/** @var string $trackingNumber */
$trackingNumber = $track['track_number'];
}
}