pepperoni Posted March 23, 2019 Share Posted March 23, 2019 (edited) Hi, I have been searching in the forum and saw that other people are interested to achieve this but looks like there hasn't been any solution for this. A bit sad really. There are many courriers out there that use more than one parameter to track parcels. So by default prestashop uses a single parameter, tracking id and I'm trying to add another one, the post code. I have managed to add it in one of the places, there more though. Unfortunately looks like this is a core change. I have edited the file AdminOrdersController in controllers/admin/. Around line 487 there is this $templateVars = array( '{followup}' => str_replace('@', $order->shipping_number, $carrier->url), '{firstname}' => $customer->firstname, '{lastname}' => $customer->lastname, '{id_order}' => $order->id, '{shipping_number}' => $order->shipping_number, '{order_name}' => $order->getUniqReference() ); I found out this code is responsible for the email the buyer gets with the tracking url. Now to add the postcode I'm querying the db. So before this piece of code I do this: $post_code = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS(' SELECT a.postcode FROM `' . _DB_PREFIX_ . 'address` a WHERE a.id_address = '.(int)$order->id_address_invoice.' '); This will give me an array as a result. The the {followup} would become like this: '{followup}'=> str_replace('@', $order->shipping_number, $carrier->url)."&postcode=".$post_code[0]['postcode'], That is because I want my tracking url to be like this: https://apc-overnight.com/track-parcel.php?id=[22 DIGIT IDENTIFIER]&postcode=[POSTCODE] This is all fine but there are more places to tweak. - In the BO the Order page. There is a place to enter the tracking id and that is a link too. - For customer, the order history page has a link there too. How can I achieve this and progress further? Any help is much appreciated. many thanks Otto prestashop version 1.6 Edited March 23, 2019 by pepperoni (see edit history) 1 Link to comment Share on other sites More sharing options...
pepperoni Posted March 27, 2019 Author Share Posted March 27, 2019 I have solved this in the following way. It is not a clean solution and it will break on update. I have made notes and comments though so hopefully it won't be hard to reapply on update. 1. First I have made tracking url in my Carrier, like this: https://apc-overnight.com/track-parcel.php?id=@&postcode=# 2. Then I edited /controllers/admin/AdminOrdersController.php The changes here are responsible for the tracking link in the email that the customer will receive. There is a public function postProcess(). In there around line 487 there is this: $templateVars = array( '{followup}' => str_replace('@', $order->shipping_number, $carrier->url), '{firstname}' => $customer->firstname, '{lastname}' => $customer->lastname, '{id_order}' => $order->id, '{shipping_number}' => $order->shipping_number, '{order_name}' => $order->getUniqReference() ); We need to change the {followup} var to include the postcode. So be fore this code I query the database to get the postcode. $post_code = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS(' SELECT a.postcode FROM `' . _DB_PREFIX_ . 'address` a WHERE a.id_address = '.(int)$order->id_address_invoice.' '); Then the {followup} var inside $templateVars will become: '{followup}' => str_replace(array('@', '#'), array($order->shipping_number, str_replace(" ","+",$post_code[0]['postcode'])), $carrier->url), This will replace character @ with the shipping number and character # with the postcode, replacing any spave in postcode with the character +. (this is one of the specs from courier) 3. Then I override Order.php file. So this will be safe in prestashop updates. /override/classes/order/Order.php This change is responsible for the B.O. order page class Order extends OrderCore { public function getShipping() { return Db::getInstance()->executeS(' SELECT DISTINCT o.`id_address_delivery`, a.`postcode`, oc.`id_order_invoice`, oc.`weight`, oc.`shipping_cost_tax_excl`, oc.`shipping_cost_tax_incl`, c.`url`, oc.`id_carrier`, c.`name` as `carrier_name`, oc.`date_add`, "Delivery" as `type`, "true" as `can_edit`, oc.`tracking_number`, oc.`id_order_carrier`, osl.`name` as order_state_name, c.`name` as state_name FROM `' . _DB_PREFIX_ . 'orders` o LEFT JOIN `' . _DB_PREFIX_ . 'order_history` oh ON (o.`id_order` = oh.`id_order`) LEFT JOIN `' . _DB_PREFIX_ . 'order_carrier` oc ON (o.`id_order` = oc.`id_order`) LEFT JOIN `' . _DB_PREFIX_ . 'carrier` c ON (oc.`id_carrier` = c.`id_carrier`) LEFT JOIN `' . _DB_PREFIX_ . 'order_state_lang` osl ON (oh.`id_order_state` = osl.`id_order_state` AND osl.`id_lang` = ' . (int) Context::getContext()->language->id . ') LEFT JOIN `' . _DB_PREFIX_ . 'address` a ON (o.`id_address_delivery` = a.`id_address`) WHERE o.`id_order` = ' . (int) $this->id . ' GROUP BY c.id_carrier'); } } Basically I added the postcode so we can use it later. 4. /admin/themes/theme/template/controlers/orders/_shipping.tpl This change is again responsible for the B.O. order page and we are going to use previous change. Around line 65 we have <span class="shipping_number_show">.......... This becomes like this now {assign "letters" array('@', '#')} {assign "new_data" array($line.tracking_number, $line.postcode|replace:' ':'+')} <span class="shipping_number_show">{if $line.url && $line.tracking_number}<a class="_blank" href="{$line.url|replace:$letters:$new_data}">{$line.tracking_number}</a>{else}{$line.tracking_number}{/if}</span> 5. Then I override OrderDetailController.php /override/controllers/front/OrderDetailController.php This change is responsible for the customer order details Around line 208 there is this if ($carrier->url && $order->shipping_number) .... So this becomes now like this $post_code = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS(' SELECT a.postcode FROM `' . _DB_PREFIX_ . 'address` a WHERE a.id_address = ' . (int) $order->id_address_invoice . ' '); $order->postcode = $post_code[0]['postcode']; $this->context->smarty->assign('followup', str_replace(array('@', '#'), array($order->shipping_number, str_replace(" ","+",$post_code[0]['postcode'])), $carrier->url)); These 5 changes seem to be working for me, for now. Would be nice to see some flexibility within prestashop regarding the tracking url and not have to go through these changes. I hope it will help a soul here. cheers 1 1 Link to comment Share on other sites More sharing options...
Snobs Posted November 15, 2021 Share Posted November 15, 2021 (edited) Hi Pepperoni I have read your string with great interest, I don't know if you will see my enquiry let alone have the time or interest in responding to it, however; here goes. Firstly from what I read of what you wrote, there is yet another basic flaw in PS base system, in that it only allows for the carriers URL tracking refence as a way of tracking or sorting outgoing packages & that you cleverly have figured away to allow this happen with the post code as well. Yet what I want to know is if this is supposed to be a community lead open source platform, why has your work not been included in one of the latest version of PS. In fact there have been many good ideas & workarounds I have seen which PS just seems to ignore. Is there a place in the forums or anywhere that we, as users can register upgrade ideas/requirements, such as yours where users & developers can vote for what we think is a good idea for the next incarnation of PS, so that the powers to be at PS can see what the users want as a priority & what can wait? My real question that I was looking for an answer to which lead me to your post is how to I find out what is the best carrier interface for PS, I have been trying to researching the addition of a module that interfaces with my choice of carriers & its a minefield, because of they way PS sells through its market place, there does not appear to be away of comparing them or clearly understanding what the pros or cons of each module are. Mostly they seem to be very expensive label printers from within PS , & that all the tracking & sorting is done by the carrier, can you point me at a place on the internet where I can find out honest reviews that helkp me understand what these modules do or don't do. Apologies for taking up your time but I am lost on the carrier interface issue?? Kind Regards Snob Edited November 15, 2021 by Snobs (see edit history) Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now