Jump to content

Creatin custom field in comment in order section


 Share

Recommended Posts

Hi! Im developing in Prestashop and I have a problem. In this part:"If you would like to add a comment about your order, please write it in the field below."  I want to put a custom checkbox field in order to appear like a message in  the backoffice if is submitted. I have already put the field and edit the php code in the orderopccontroller.php

 

                    switch (Tools::getValue('method'))
                    {
                        case 'update
                        ':
                            if (Tools::isSubmit('message'))
                            {
                                $txtMessage = urldecode(Tools::getValue('message'));
                                $this->_updateMessage($txtMessage);
                                if (count($this->errors))
                                    die('{"hasError" : true, "errors" : ["'.implode('\',\'', $this->errors).'"]}');
                                die(true);
                            }
                            
                            if (Tools::isSubmit('anonimo'))
                            {
                                  $this->_updateMessage(Tools::getValue('anonimo'));
                            break;
}
 

 

I have also put in the parentordercontroller.php

 

            if (!Validate::isMessage($messageContent))
                $this->errors[] = Tools::displayError('Invalid message');
            else if ($oldMessage = Message::getMessageByCartId((int)($this->context->cart->id)))
            {
                $message = new Message((int)($oldMessage['id_message']));
                $message->message = $messageContent;
                $message->anonimo = $_POST['anonimo'];
                $message->update();
            }
            else
            {
                $message = new Message();
                $message->message = $messageContent;
                $message->anonimo = $_POST['anonimo'];
                $message->id_cart = (int)($this->context->cart->id);
                $message->id_customer = (int)($this->context->cart->id_customer);
                $message->add();
            }
        }
 

But is not working. Please somebody help me :( Please!

Edited by Juan Pablo Malkrovi (see edit history)

Share this post


Link to post
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
 Share

×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More