Rinipow Posted March 1, 2022 Share Posted March 1, 2022 Hi, I've added in my Prestashop a cookie variable. I need to show this variable in the back office when the cart is converted in the order. So I want to use the private message in the order to do this. How can I write a private message automatically when a new order is generated? Thanks in advance Link to comment Share on other sites More sharing options...
Ress Posted March 1, 2022 Share Posted March 1, 2022 Hi, This is the code from AdminOrdersController, but you have to adjust it a bit (for example, for employee id, you should put it manually). //check if a thread already exist $id_customer_thread = CustomerThread::getIdCustomerThreadByEmailAndIdOrder($customer->email, $order->id); if (!$id_customer_thread) { $customer_thread = new CustomerThread(); $customer_thread->id_contact = 0; $customer_thread->id_customer = (int) $order->id_customer; $customer_thread->id_shop = (int) $this->context->shop->id; $customer_thread->id_order = (int) $order->id; $customer_thread->id_lang = (int) $this->context->language->id; $customer_thread->email = $customer->email; $customer_thread->status = 'open'; $customer_thread->token = Tools::passwdGen(12); $customer_thread->add(); } else { $customer_thread = new CustomerThread((int) $id_customer_thread); } $customer_message = new CustomerMessage(); $customer_message->id_customer_thread = $customer_thread->id; $customer_message->id_employee = (int) $this->context->employee->id; $customer_message->message = 'Message'; $customer_message->private = 0; //or 1, for customer visibility $customer_message->add() Link to comment Share on other sites More sharing options...
Rinipow Posted March 6, 2022 Author Share Posted March 6, 2022 Hi, thanks for the support. The thing is that I don't know where to write this code. In which point of the transaction I can write the message? Thanks in advance Link to comment Share on other sites More sharing options...
Ress Posted March 6, 2022 Share Posted March 6, 2022 You could use the actionValidateOrder hook (you receive the order object as a parameter). 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