ANGELO Vintage Posted July 6, 2017 Share Posted July 6, 2017 Hi, i would like to add a new placeholder to a specific email template: shipped.html actually the placholders that works are: {firstname} {lastname} {order_name} {shop_name} If i understand the placeholder substitution is made by AdminOrderController.php There is a way to override the module adding the {mail} placeholder without touching the original php script so i can use a new placeholder field in the shipped.html template? ty Link to comment Share on other sites More sharing options...
Scully Posted July 7, 2017 Share Posted July 7, 2017 (edited) You can make a copy of your controller into the /override path. The exact path must match with its original file but under ./override Thie filename is AdminOrdersController.php (with an 's'). However I am not sure if shipped is sent from this controller. WIth a quick view in 1.6. I couldn't find a reference for that. This part - templates, e-mails and the corresponding classes and controllers is a rather messy thing in PrestaShop. After having made the changes and saved the new file under /override, you have to delete ./cache/class_index.php. If you don't - your changes will have no effect. Edited July 7, 2017 by Scully (see edit history) Link to comment Share on other sites More sharing options...
ANGELO Vintage Posted July 11, 2017 Author Share Posted July 11, 2017 thank for the answer. i try to find out the place where a order status change can fire an email and i think the line 514 could be the right position to check: /* Change order status, add a new entry in order history and send an e-mail to the customer if needed */ elseif (Tools::isSubmit('submitState') && isset($order)) { if the status is changed and valid it save a new status and here is preparing to send an email @line 564: /* Add a new message for the current order and send an e-mail to the customer if needed */ elseif (Tools::isSubmit('submitMessage') && isset($order)) { and at line 629 it substitute the placeholders with the values: $varsTpl = array( '{lastname}' => $customer->lastname, '{firstname}' => $customer->firstname, '{id_order}' => $order->id, '{order_name}' => $order->getUniqReference(), '{message}' => $message ); if (@Mail::Send((int)$order->id_lang, 'order_merchant_comment', Mail::l('New message regarding your order', (int)$order->id_lang), $varsTpl, $customer->email, $customer->firstname.' '.$customer->lastname, null, null, null, null, _PS_MAIL_DIR_, true, (int)$order->id_shop)) { Tools::redirectAdmin(self::$currentIndex.'&id_order='.$order->id.'&vieworder&conf=11'.'&token='.$this->token); } I'm not very expert on core development but override only the function: public function postProcess() {} with a new one with: $varsTpl = array( '{lastname}' => $customer->lastname, '{firstname}' => $customer->firstname, '{id_order}' => $order->id, '{order_name}' => $order->getUniqReference(), '{message}' => $message, '{email}' => $customer->email, ); I think it could work. I don't have a testing server right now to verify my theory, if someone more expert then me with override controllers could confirm will save me a lot of troubles ty Link to comment Share on other sites More sharing options...
ANGELO Vintage Posted July 11, 2017 Author Share Posted July 11, 2017 i've made new research and seems that when an order status is changed the script involved is OrderHistory.php there are two hooks: actionOrderStatusUpdate actionOrderStatusPostUpdate there is a function @ line 410 public function sendEmail($order, $template_vars = false) that works with these placeholders $data = array( '{lastname}' => $result['lastname'], '{firstname}' => $result['firstname'], '{id_order}' => (int)$this->id_order, '{order_name}' => $order->getUniqReference() ); maybe tweaking there adding a new placeholder like {email} will work: $data = array( '{lastname}' => $result['lastname'], '{firstname}' => $result['firstname'], '{email}' => $result['email'], '{id_order}' => (int)$this->id_order, '{order_name}' => $order->getUniqReference() ); That function is called also in function public function addWithemail() that is used in AdminOrdersController.php script @ line 542 // Save all changes if ($history->addWithemail(true, $templateVars)) { Just a quick thought. In this way every template like shipped.html can work with the {email} placeholder Link to comment Share on other sites More sharing options...
Scully Posted July 11, 2017 Share Posted July 11, 2017 What kind of information should be stored in email? The recipient address is always available, also bcc if set. Link to comment Share on other sites More sharing options...
ANGELO Vintage Posted July 12, 2017 Author Share Posted July 12, 2017 HI, i need to integrate trustpilot AUTO invite adding this code inside the email body: <!-- trustpilot --> <script type="application/json+trustpilot"> { "recipientEmail": "{email}", "recipientName": "{firstname} {lastname}", "referenceId": "{order_name}" } </script> <!-- trustpilot --> By integrating these info and sending a BCC to a trustpilot email receiver the customer that have ordered and the good are shipped will receive in 7 days a suggest to give a rating. the email placeholder is the only variable that is not processed on the template is why i need to add the {email} processing to OrderHistory.php when the order status change. for the bcc i've already solved overriding the mail.php with: <?php /* MODIFIED VERSION TO SUPPORT TRUSTPILOT SEND ON SHIPPED STATUS CHANGE */ class Mail extends MailCore { public static function Send($id_lang, $template, $subject, $template_vars, $to, $to_name = null, $from = null, $from_name = null, $file_attachment = null, $mode_smtp = null, $template_path = _PS_MAIL_DIR_, $die = false, $id_shop = null, $bcc = null, $reply_to = null) { if($template == 'shipped') { $bcc = array('[email protected]'); } return parent::Send($id_lang, $template, $subject, $template_vars, $to, $to_name, $from, $from_name, $file_attachment, $mode_smtp, $template_path, $die, $id_shop, $bcc, $reply_to); } } I hoope is more clear why i need this extension of {mail} placeholder ty Link to comment Share on other sites More sharing options...
ANGELO Vintage Posted July 12, 2017 Author Share Posted July 12, 2017 (edited) reading on the forum another user thaty need to override another function i create this ovveraid but dont' know if is ok : <?php /* Added new {mail} template */ class OrderHistory extends OrderHistoryCore { public function sendEmail($order, $template_vars = false) { $result = Db::getInstance()->getRow(' SELECT osl.`template`, c.`lastname`, c.`firstname`, osl.`name` AS osname, c.`email`, os.`module_name`, os.`id_order_state`, os.`pdf_invoice`, os.`pdf_delivery` FROM `'._DB_PREFIX_.'order_history` oh LEFT JOIN `'._DB_PREFIX_.'orders` o ON oh.`id_order` = o.`id_order` LEFT JOIN `'._DB_PREFIX_.'customer` c ON o.`id_customer` = c.`id_customer` LEFT JOIN `'._DB_PREFIX_.'order_state` os ON oh.`id_order_state` = os.`id_order_state` LEFT JOIN `'._DB_PREFIX_.'order_state_lang` osl ON (os.`id_order_state` = osl.`id_order_state` AND osl.`id_lang` = o.`id_lang`) WHERE oh.`id_order_history` = '.(int)$this->id.' AND os.`send_email` = 1'); if (isset($result['template']) && Validate::isEmail($result['email'])) { $data = array( '{mail}' => $result['mail'], ); if ($template_vars) { $data = array_merge($data, $template_vars); } } return parent::sendEmail($order, $data); } } I still learning how things works on prestashop. My objective is to add a new placeholder {mail} to be processed when order status is chhanging so in mail templates the new {mail} placeholder will be substituted by the user email. Any help is apreciated Edited July 12, 2017 by ANGELO Vintage (see edit history) Link to comment Share on other sites More sharing options...
Scully Posted July 12, 2017 Share Posted July 12, 2017 I'd use the ./classes/Mail.php, public static function Send around line 250 insert this if($template == 'shipped') { $template_vars['{email}'] = $to; } template shipped refers to the sending shipped message. you can change this with any template you'd like. $to represents the recipients mail address. Then change your email template according to your needs where you have now this new variable. Link to comment Share on other sites More sharing options...
ANGELO Vintage Posted July 13, 2017 Author Share Posted July 13, 2017 (edited) so an all-in-one tweak solution for trustpilot could be override the mail.php like: <?php /* MODIFIED VERSION TO SUPPORT TRUSTPILOT SEND ON SHIPPED STATUS CHANGE */ class Mail extends MailCore { public static function Send($id_lang, $template, $subject, $template_vars, $to, $to_name = null, $from = null, $from_name = null, $file_attachment = null, $mode_smtp = null, $template_path = _PS_MAIL_DIR_, $die = false, $id_shop = null, $bcc = null, $reply_to = null) { if($template == 'shipped') { $bcc = array('[email protected]'); $template_vars['{email}'] = $to; } return parent::Send($id_lang, $template, $subject, $template_vars, $to, $to_name, $from, $from_name, $file_attachment, $mode_smtp, $template_path, $die, $id_shop, $bcc, $reply_to); } } ?> is that correct? Edited July 13, 2017 by ANGELO Vintage (see edit history) Link to comment Share on other sites More sharing options...
Scully Posted July 14, 2017 Share Posted July 14, 2017 Does look good. But If you wan't to maintain already existing BCC addresses, you would have to change the code I guess by antoher if. if($template == 'shipped') { $template_vars['{email}'] = $to; if (isset($bcc) or is_array($bcc) ) $bcc = array('[email protected]', $bcc); ) } Link to comment Share on other sites More sharing options...
ANGELO Vintage Posted July 17, 2017 Author Share Posted July 17, 2017 i think there is a typo error, should be: if($template == 'shipped') { $template_vars['{email}'] = $to; if (isset($bcc) or is_array($bcc)) { $bcc = array('[email protected]', $bcc); } } An dif the condition is not TRUE, for example $bcc is not set and is empty we don't need an ELSE statement or is_array is always TRUE? 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