Jump to content

I need to create a private message automatically when a order is created


Rinipow

Recommended Posts

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

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

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