PrestaShop generates Shipping Confirmation Email that contains empty tracking number:

PrestaShop server admin needs to modify two source files: Order.php & WebserviceRequest.php


Find function setWsShippingNumber($shipping_number) (around line 2215), and insert the following line as marked:
public function setWsShippingNumber($shipping_number)
{
$id_order_carrier = Db::getInstance()->getValue('
SELECT `id_order_carrier`
FROM `'._DB_PREFIX_.'order_carrier`
WHERE `id_order` = '.(int)$this->id);
if ($id_order_carrier) {
$order_carrier = new OrderCarrier($id_order_carrier);
$order_carrier->tracking_number = $shipping_number;
$this->shipping_number = $shipping_number; // <----------Insert this line !
$order_carrier->update();
} else {
$this->shipping_number = $shipping_number;
}
return true;
}
Find function setCurrentState($id_order_state, $id_employee = 0) (around line 1545), and add following lines to that function:
public function setCurrentState($id_order_state, $id_employee = 0)
{
if (empty($id_order_state)) {
return false;
}
$history = new OrderHistory();
$history->id_order = (int)$this->id;
$history->id_employee = (int)$id_employee;
$history->changeIdOrderState((int)$id_order_state, $this);
$res = Db::getInstance()->getRow('
SELECT `invoice_number`, `invoice_date`, `delivery_number`, `delivery_date`
FROM `'._DB_PREFIX_.'orders`
WHERE `id_order` = '.(int)$this->id);
$this->invoice_date = $res['invoice_date'];
$this->invoice_number = $res['invoice_number'];
$this->delivery_date = $res['delivery_date'];
$this->delivery_number = $res['delivery_number'];
$this->update();
$carrier = new Carrier($this->id_carrier, $this->id_lang); // <----------Insert this line !
$template_vars = array( // <----------Insert this line !
'{shipping_number}' => $this->shipping_number, // <----------Insert this line !
'{followup}' => str_replace('@', $this->shipping_number, $carrier->url), // <----------Insert this line !
); // <----------Insert this line !
$history->addWithemail(true, $template_vars);
}
'{shipping_number}' should match Tracking Number placeholder in your Email Template. '{followup}' should match Tracking URL placeholder in your Email Template.
Modify classes/webservice/WebserviceRequest.php:
Find function saveEntityFromXml($successReturnCode) (around line 1371), and insert following lines (around line 1425):
......
foreach ($xmlEntities as $xmlEntity) {
/** @var SimpleXMLElement $xmlEntity */
$attributes = $xmlEntity->children();
/** @var ObjectModel $object */
$retrieve_data = $this->resourceConfiguration['retrieveData'];
if ($this->method == 'POST') {
$object = new $retrieve_data['className']();
} elseif ($this->method == 'PUT') {
$object = new $retrieve_data['className']((int)$attributes->id);
if (!$object->id) {
$this->setError(404, 'Invalid ID', 92);
return false;
}
}
$this->objects[] = $object;
$i18n = false;
if(!empty($this->resourceConfiguration['fields']['current_state'])){ // <----------Insert this line! (Around Line 1425)
$prop = $this->resourceConfiguration['fields']['current_state']; // <----------Insert this line!
unset($this->resourceConfiguration['fields']['current_state']); // <----------Insert this line!
$this->resourceConfiguration['fields']['current_state'] = $prop; // <----------Insert this line!
} // <----------Insert this line!
// attributes
foreach ($this->resourceConfiguration['fields'] as $fieldName => $fieldProperties) {
$sqlId = $fieldProperties['sqlId'];
if ($fieldName == 'id') {
$sqlId = $fieldName;
}
if (isset($attributes->$fieldName) && isset($fieldProperties['sqlId']) && (!isset($fieldProperties['i18n']) || !$fieldProperties['i18n'])) {
if (isset($fieldProperties['setter'])) {
......