Jump to content

Send mail on customer page on BO


Recommended Posts

In tab orders, you can send mail to the customer.
I would like to do the same thing on the customer page (tab costumers, and click a costumer...)
The mail will be write in text area (no mail predefined).
So, in file tab\AdminCustomers.php, before :

// display hook specified to this page : AdminCustomers

i added :

/* Display send a message to customer/
       $returns = OrderReturn::getOrdersReturn($order->id_customer, $order->id);
       $slips = OrderSlip::getOrdersSlip($order->id_customer, $order->id);
       echo '

           <form action="'.$_SERVER['REQUEST_URI'].'&token;='.$this->token.'" method="post" onsubmit="if (getE(\'visibility\').checked == true) return confirm(\''.$this->l('Do you want to send this message to the customer?', __CLASS__, true, false).'\');">

 '.$this->l('New message').'

'.$this->l('Click here').' '.$this->l('to add a comment or send a message to the customer').'

l('Do you want to overwrite your existing message?').'\')">
-- '.$this->l('Choose a standard message').' --';
       $orderMessages = OrderMessage::getOrderMessages(intval($order->id_lang));
       foreach ($orderMessages AS $orderMessage)
           echo '        '.$orderMessage['name'].'';
       echo '        

'.$this->l('Display to consumer?').'

                   <input type="radio" name="visibility" id="visibility" value="0" /> '.$this->l('Yes').'
                   <input type="radio" name="visibility" value="1" checked="checked" /> '.$this->l('No').'

'.$this->l('If yes, the message will be sent to customer and displayed in this account.').'

'.$this->l('If no, the message will be displayed only here and no sent to customer').'

                   <textarea id="txt_msg" name="message" cols="50" rows="8"> 600) length = \'600+\'; document.getElementById(\'nbchars\')[removed] = \''.$this->l('600 chars max').' (\' + length + \')\';">'.htmlentities(Tools::getValue('message'), ENT_COMPAT, 'UTF-8').'</textarea><br />

                   <input type="hidden" name="id_order" value="'.intval($order->id).'" />
                   <input type="hidden" name="id_customer" value="'.intval($order->id_customer).'" />
                   <input type="submit" class="button" name="submitMessage" value="'.$this->l('Send').'" />


Link to comment
Share on other sites

and after :

    public function postProcess()
       global $currentIndex;

       if (Tools::getValue('submitAdd'.$this->table))
            /* Checking fields validity */
           if (!sizeof($this->_errors))
               $id = intval(Tools::getValue('id_'.$this->table));
               if (isset($id) AND !empty($id))
                   if ($this->tabAccess['edit'] !== '1')
                       $this->_errors[] = Tools::displayError('You do not have permission to edit anything here.');
                       $object = new $this->className($id);
                       if (Validate::isLoadedObject($object))
                           $customer_email = strval(Tools::getValue('email'));

                           // check if e-mail already used
                           if ($customer_email != $object->email)
                               $customer = new Customer();
                               if ($customer->id)
                                   $this->_errors[] = Tools::displayError('an account already exists for this e-mail address:').' '.$customer_email;

                           // Updating customer's group
                           if (!sizeof($this->_errors))
                               $groupList = Tools::getValue('groupBox');
                               if (is_array($groupList) AND sizeof($groupList) > 0)
                           $this->_errors[] = Tools::displayError('an error occurred while loading object').' '.$this->table.' '.Tools::displayError('(cannot load object)');

i added :

        if (isset($_POST['submitMessage']))
           $_GET['view'.$this->table] = true;
            if ($this->tabAccess['edit'] === '1')
               if (!($id_customer = intval(Tools::getValue('id_customer'))))
                   $this->_errors[] = Tools::displayError('an error occurred before sending message');
               elseif (!Tools::getValue('message'))
                   $this->_errors[] = Tools::displayError('message cannot be blank');
                   /* Get message rules and and check fields validity */
                   $rules = call_user_func(array('Message', 'getValidationRules'), 'Message');
                   foreach ($rules['required'] AS $field)
                       if (($value = Tools::getValue($field)) == false AND (string)$value != '0')
                           if (!Tools::getValue('id_'.$this->table) OR $field != 'passwd')
                               $this->_errors[] = Tools::displayError('field').' '.$field.' '.Tools::displayError('is required');
                   foreach ($rules['size'] AS $field => $maxLength)
                       if (Tools::getValue($field) AND Tools::strlen(Tools::getValue($field)) > $maxLength)
                           $this->_errors[] = Tools::displayError('field').' '.$field.' '.Tools::displayError('is too long').' ('.$maxLength.' '.Tools::displayError('chars max').')';
                   foreach ($rules['validate'] AS $field => $function)
                       if (Tools::getValue($field))
                           if (!Validate::$function(htmlentities(Tools::getValue($field), ENT_COMPAT, 'UTF-8')))
                               $this->_errors[] = Tools::displayError('field').' '.$field.' '.Tools::displayError('is invalid');
                   if (!sizeof($this->_errors))
                       $message = new Message();
                       $message->id_employee = intval($cookie->id_employee);
                       $message->message = htmlentities(Tools::getValue('message'), ENT_COMPAT, 'UTF-8');
                       $message->private = Tools::getValue('visibility');
                       if (!$message->add())
                           $this->_errors[] = Tools::displayError('an error occurred while sending message');

                       elseif (Validate::isLoadedObject($customer = new Customer($id_customer)))

                               $title = html_entity_decode($this->l('New message regarding your order').' '.$message->id_customer, ENT_NOQUOTES, 'UTF-8');
                               $varsTpl = array('{lastname}' => $customer->lastname, '{firstname}' => $customer->firstname, '{id_customer}' => $message->id_customer, '{message}' => (Configuration::get('PS_MAIL_TYPE') == 2 ? $message->message : nl2br2($message->message)));

                       $this->_errors[] = Tools::displayError('an error occurred while sending e-mail to the customer');
               $this->_errors[] = Tools::displayError('You do not have permission to delete here.');

The text area is displayed on customer page but no mail sent.
I think i need to adapt and clean the code to send by customer id, but I do not know how.
An experienced developer could help me?

Prestashop V1.2.5.0

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