Jump to content

Prestashop 1.6.1.14 - Add Condition to actionValidateOrder and Custom Tracking Number


Recommended Posts

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 by Enthu86 (see edit history)
Link to comment
Share on other sites

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

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

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

  • Like 1
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...