Blank Tracking Number - PrestaShop

Blank Tracking Number - PrestaShop

Problem

PrestaShop generates Shipping Confirmation Email that contains empty tracking number:  

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

Solution

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

Read before you doing following steps
Please 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.
  3. 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;
        }
  4. 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. 


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


Modify classes/webservice/WebserviceRequest.php:

  1. Go to classes/webservice directory, and open file WebserviceRequest.php.
  2. 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'])) {
    ......
    
    
  3. Make sure to save WebserviceRequest.php before you close it.

    • Related Articles

    • Shipping Confirmation Error - PrestaShop

      Problem Extensiv Integration Manager cannot send Shipping/Tracking to PrestaShop with following message: Could not upload tracking information for Order #xxxx: Please make sure that the carrier, FEDEX, exists in PrestaShop.  Solution Please make sure ...
    • Unexpected HTTP Status 302 - PrestaShop

      Problem Extensiv Integration Manager cannot communicate with PrestaShop and displays a 302 error like the following: This call to PrestaShop Web Services returned an unexpected HTTP status of 302 Solution Generate empty .htaccess file If PrestaShop ...
    • Error pulling mapping code from PrestaShop

      Problem You are receiving the follow error message or a similar error message in Extensiv Integration Manager: Error pulling mapping code from PrestaShop Could not retrieve countries table from PrestaShop PrestaShop error: Bad HTTP response Failed to ...
    • Internal error. To see this error please display the PHP errors. - PrestaShop

      Problem CartRover is showing the following Alert message from your PrestaShop cart: Internal error. To see this error please display the PHP errors. Solution This can be caused by many things in PrestaShop. The first step it to enable errors in ...
    • Fatal Error - PrestaShop

      Problem Newly created store cannot be open due to Fatal Error on server. Exact error may differ. Example: Solution The store is missing basic data to initialize: Please make sure that all sections under Localization, especially Currencies, are set. ...