PrestaShop

Blank Tracking Number - PrestaShop

1.8 min read

| September 14, 2024

Problem

PrestaShop generates Shipping Confirmation Email that contains an empty tracking number:  

  • Email shows "{shipping_number}" instead of the actual tracking number. 
     
  • Email shows "{followup}" instead of the actual tracking link. 
     
  • Email shows a blank tracking number. 
     
     

Solution
 

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

 

Create a back up

Please create a back up Order.php & WebserviceRequest.php before making changes to these files in case you need to restore the originals!

 
 
This solution is required until PrestaShop resolves this bug.
 
Modify classes/order/Order.php: 
 
  1. Please open PrestaShop root directory on server. Make sure that you have permission to modify PrestaShop source files.
     
  2. Go to classes/order directory, and open Order.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 the Tracking Number placeholder in your Email Template.

'{followup}' should match Tracking URL placeholder in your Email Template
 

3. Make sure to save Order.php file before you close it.

Modify classes/webservice/WebserviceRequest.php:

4. Go to classes/webservice directory, and open file 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'])) {
......


 

5. Make sure to save WebserviceRequest.php before you close it.
 

 

Not finding the help you need?

Contact Support