in this guide i want to show you how easily you can add tracking number field to your orders list page in back office. Modification like that allows you to easily find products related to parcels / delivery number. I created this tutorial for prestashop forum purposes. Some of merchants asks about that feature - so heare it is
Modification of controller
All that we have to do in this case - is modification of admin controller named AdminOrdersController.php located in /controllers/ directory in admin subdirectory. So, basically open this file and search for this code:
$this->_join = ' LEFT JOIN `'._DB_PREFIX_.'customer` c ON (c.`id_customer` = a.`id_customer`) INNER JOIN `'._DB_PREFIX_.'address` address ON address.id_address = a.id_address_delivery INNER JOIN `'._DB_PREFIX_.'country` country ON address.id_country = country.id_country INNER JOIN `'._DB_PREFIX_.'country_lang` country_lang ON (country.`id_country` = country_lang.`id_country` AND country_lang.`id_lang` = '.(int)$this->context->language->id.') LEFT JOIN `'._DB_PREFIX_.'order_state` os ON (os.`id_order_state` = a.`current_state`) LEFT JOIN `'._DB_PREFIX_.'order_state_lang` osl ON (os.`id_order_state` = osl.`id_order_state` AND osl.`id_lang` = '.(int)$this->context->language->id.')';
and add there highlighted line:
$this->_join = ' LEFT JOIN `'._DB_PREFIX_.'order_carrier` oc ON a.`id_order` = oc.`id_order` LEFT JOIN `'._DB_PREFIX_.'customer` c ON (c.`id_customer` = a.`id_customer`) INNER JOIN `'._DB_PREFIX_.'address` address ON address.id_address = a.id_address_delivery INNER JOIN `'._DB_PREFIX_.'country` country ON address.id_country = country.id_country INNER JOIN `'._DB_PREFIX_.'country_lang` country_lang ON (country.`id_country` = country_lang.`id_country` AND country_lang.`id_lang` = '.(int)$this->context->language->id.') LEFT JOIN `'._DB_PREFIX_.'order_state` os ON (os.`id_order_state` = a.`current_state`) LEFT JOIN `'._DB_PREFIX_.'order_state_lang` osl ON (os.`id_order_state` = osl.`id_order_state` AND osl.`id_lang` = '.(int)$this->context->language->id.')';
Then in the same file search for this code:
$this->fields_list = array( 'id_order' => array( 'title' => $this->l('ID'), 'align' => 'text-center', 'class' => 'fixed-width-xs' ), 'reference' => array( 'title' => $this->l('Reference') ),
and change it to:
$this->fields_list = array( 'id_order' => array( 'title' => $this->l('ID'), 'align' => 'text-center', 'class' => 'fixed-width-xs' ), 'reference' => array( 'title' => $this->l('Reference') ), 'tracking_number' => array( 'title' => $this->l('tracking number'), 'havingFilter' => true, ),
Then save changes. Go to orders > orders tab in your back office, you will see tracking number field. You can filter orders list with this field. Enjoy!
Create clickable tracking number
If you want to create clickable tracking number, that will redirect to tracking page you need to modify code you added to the $this->fields_list variable. Previously you added:
'tracking_number' => array( 'title' => $this->l('tracking number'), 'havingFilter' => true, ),
change it to:
'tracking_number' => array( 'title' => $this->l('tracking number'), 'callback' => 'buildTrackingLink' ),
Then, go to the end of AdminOrdersControl.php file. Right before last closing bracket } paste function code i attach below. It builds a trakcing url and displays it on the list of orders.
public function buildTrackingLink($group, $row) { $order = new Order($row['id_order']); $carrier = Carrier::getCarrierByReference($order->id_carrier); return '<a class="tracking_number" target="_blank" href="'.$carrier->url.$row['tracking_number'].'"><script>$(\'document\').ready(function(){$(\'.tracking_number\').parent().removeAttr(\'onclick\');});</script>'.$row['tracking_number'].'</a>'; }