Jump to content

How to duplicate order message as a note during check out ?


pojezdy.eu

Recommended Posts

Hello all,

would someone recommend me how to update PaymentModule.php (I guess that should be the one, as far as I search over forums) to copy the message content into the note stored in the note cell of ps_order table?

I guess it should be somewhere here ...

                    if (!empty($message)) {
                        $msg = new Message();
                        $message = strip_tags($message, '<br>');
                        if (Validate::isCleanHtml($message)) {
                            if (self::DEBUG_MODE) {
                                PrestaShopLogger::addLog('PaymentModule::validateOrder - Message is about to be added', 1, null, 'Cart', (int) $id_cart, true);
                            }
                            $msg->message = $message;
                            $msg->id_cart = (int) $id_cart;
                            $msg->id_customer = (int) ($order->id_customer);
                            $msg->id_order = (int) $order->id;
                            $msg->private = 1;
                            $msg->add();
                        }
                    }

Link to comment
Share on other sites

Hello, there is no field NOTE in table ORDERS in early prestashop 1.7 versions. The NOTE field have appeared in later prestashop 1.7 versions. Then, you can try this code:

if (!empty($message) && Validate::isCleanHtml($message)) {
            // Retrieve the last created order for the current cart
            $order = Order::getByCartId((int)$id_cart);

            if ($order) {
                // Sanitize the message
                $cleanMessage = strip_tags($message, '<br>');

                // Update the note field in the orders table
                Db::getInstance()->update(
                    'orders',
                    ['note' => pSQL($cleanMessage)],
                    'id_order = ' . (int)$order->id
                );
            }
        }

 

 

Edited by webprog (see edit history)
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...