Jump to content

Get Order Id on actionValidateOrder hook


marco.predari

Recommended Posts

Hi everyone,

 

I am new in the prestashop community and I have a question about developing modules in PS.

 

I am creating a module that has to make some stuff when a new order is submitted. Well i found the "actionValidateOrder" hook and i have used it. But now i'am trying to get the id of the order that has been submitted.

 

Getting the last order on the database, it's correct but it will maybe cause some problems if multiple order are submitted at the same time. So i have looked at the "params" passed by the hook, but i get only the value "1" (so i think will be a confirm that the order has been processed correctly).

 

Can someone help me about getting the order id (or better the order data) when the "hook" is processed?

 

Thanks everyone

 

Marco

 

PS : my code ->

public function hookActionValidateOrder($params){
    Logger::AddLog("A new order has been submitted. Data : ".print_r($params));
    /*
    *
    * More stuff here, but i need the order data
    *
    */
}
Link to comment
Share on other sites

Below is the code that actually executes the hook you have registered

// Hook validate order
Hook::exec('actionValidateOrder', array(
    'cart' => $this->context->cart,
    'order' => $order,
    'customer' => $this->context->customer,
    'currency' => $this->context->currency,
    'orderStatus' => $order_status
));

$params is an array that contains 5 objects, the Order object being one of them.

 

this should get you started...

//get the Order object
$order = $params['order'];

//validate that the Order is an Object and has a valid ID
if (!Validate::isLoadedObject($order))
{
      //do what you need to do
      $id_order = (int)$order->id;

      //do some other stuff
}
  • Like 1
Link to comment
Share on other sites

  • 2 years later...

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...