PrestashopEnthu Posted October 24, 2017 Share Posted October 24, 2017 (edited) I am looking to add a condition on actionValidateOrder in my custom module. On creation of a new order, I would like to add a custom tracking code so my customers are able to use it to track their items. I have prepend and format the necessary to create a string for item tracking. I would like to insert this data into each order upon creation. It will be available in all Orders page, tied to each order. (Shipping > Tracking Number) This condition will only trigger if a specific carrier is tied to the order. I am also using actionValidateOrder to send out the order via CURL. Fortunately, this is working well currently without the condition below. public function hookActionValidateOrder($params) { $orderinfo = new Order($params['id_order']); $carrierinfo = new Carrier($orderinfo->id_carrier); if ($carrierinfo->name=='X') { //retrieve and add custom tracking code with id_order //tracking number will be displayed in back-office Order page for items } } I am able to use the code below though. $carrier_id = $params['cart']->id_carrier; if ($carrier_id==3) { //3 is the id of X, I want to use the name instead Appreciate your time and guidance. Edited October 24, 2017 by Enthu86 (see edit history) Link to comment Share on other sites More sharing options...
bellini13 Posted October 24, 2017 Share Posted October 24, 2017 I would suggest that you create a new database table that will store the necessary tracking information for each new order. So in your modules hookActionValidateOrder, you would insert a new record into this table that would associate the tracking information back to the id_order Once saved, you can then show or send this value basically anywhere you need to. Can you explain what the tracking information looks like and where it originates from? Link to comment Share on other sites More sharing options...
PrestashopEnthu Posted October 25, 2017 Author Share Posted October 25, 2017 Hi bellini13, Thank you for your suggestion. I have managed to add the custom tracking number to order_carrier in actionValidateOrder and insert in tracking_number. Db::getInstance()->update( 'order_carrier', Can I just enquire if you do know how do I get the name instead of id for the following code? $carrier_id = $params['cart']->id_carrier; if ($carrier_id==3) //3 is the carrier ID Thank you for your assistance. Link to comment Share on other sites More sharing options...
bellini13 Posted October 25, 2017 Share Posted October 25, 2017 In PS v1.6.1.14, the actionValidateOrder hook receives the following in the $params array. Notice that id_order is not one of them, but 'order' is 'cart' => $this->context->cart, 'order' => $order, 'customer' => $this->context->customer, 'currency' => $this->context->currency, 'orderStatus' => $order_status So since you already have access to the order object, there is no reason to create another order object. Just use the one from the params. $carrier = new Carrier($params['order']->id_carrier); However since Carrier names can be translated to support different languages, you need to also specify the language to use when creating a new Carrier object. $carrier = new Carrier($params['order']->id_carrier, $params['order']->id_lang); You can use the one from the order, but if the carrier name is different in each language, then you would have to check that the name matches in each language. So then you must consider which language you want to use in your code 1 Link to comment Share on other sites More sharing options...
PrestashopEnthu Posted October 25, 2017 Author Share Posted October 25, 2017 (edited) Dear bellini13, Thank you for your assistance. It is working perfectly. Thank you once again! Edited October 25, 2017 by Enthu86 (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