Bonjovi67 Posted April 5, 2016 Share Posted April 5, 2016 (edited) Hi I need to put the costumers birthdate in new_order mail from the the mail alerts module so i can easely check it when printing out my orders. I tried with this code in in the new_order.html code {date_of_birth} but it just returns {date_of_birth} in the email i recieve. I hope anyone would be kind to help. Best Regards John Edited May 20, 2016 by Bonjovi67 (see edit history) Link to comment Share on other sites More sharing options...
presta4you.com Posted April 5, 2016 Share Posted April 5, 2016 What prestashop version? Link to comment Share on other sites More sharing options...
Bonjovi67 Posted April 6, 2016 Author Share Posted April 6, 2016 (edited) What prestashop version? The version is 1.6.1.4 I am unsure of the syntax for the birthday field Edited April 6, 2016 by Bonjovi67 (see edit history) Link to comment Share on other sites More sharing options...
Bonjovi67 Posted April 7, 2016 Author Share Posted April 7, 2016 (edited) Anyone please that know the syntax for the birthday field in prestashop 1.6.1.4 mail alert emails. Edited April 8, 2016 by Bonjovi67 (see edit history) Link to comment Share on other sites More sharing options...
shokinro Posted April 8, 2016 Share Posted April 8, 2016 all variable used in email template must be prepared in PHP code before passing it to Mail::send() via parameter public static function Send($id_lang, $template, $subject, $templateVars, I do not think the variable {date_of_birth} is included by default, I think you have prepare the data for this variable and pass it so that you can use it in email templates. You can refer related code in following file PaymentModule->vaidateOrder() for sending order confirmation email as example on how to prepare variables. Link to comment Share on other sites More sharing options...
Bonjovi67 Posted April 8, 2016 Author Share Posted April 8, 2016 Thank you for the answer. It is not as simple as i thought then. Link to comment Share on other sites More sharing options...
shokinro Posted April 8, 2016 Share Posted April 8, 2016 yes, it is not as that simple, but this is the way it works. you may need to learn how to use Smarty and PrestaShop if you to make some custom changes to PrestaShop. Link to comment Share on other sites More sharing options...
Bonjovi67 Posted April 16, 2016 Author Share Posted April 16, 2016 (edited) all variable used in email template must be prepared in PHP code before passing it to Mail::send() via parameter public static function Send($id_lang, $template, $subject, $templateVars, I do not think the variable {date_of_birth} is included by default, I think you have prepare the data for this variable and pass it so that you can use it in email templates. You can refer related code in following file PaymentModule->vaidateOrder() for sending order confirmation email as example on how to prepare variables. Hi again Thank you for the answer What is the path/name of the php file where i have to make the changes ? Is it in classes/mail.php ? I have to add costumers birthday (for order confirmation mail) and costumers email adress (for shipped mail), but i am not sure what file to edit and the syntax Edited April 16, 2016 by Bonjovi67 (see edit history) Link to comment Share on other sites More sharing options...
shokinro Posted April 16, 2016 Share Posted April 16, 2016 (edited) As suggested by @mdekker, it should be done in override class file, not in original file. The original file is /classes/PaymentModule.php The override classes is - if it does not exist, please create one and then copy the method and modify it. /override/classes/PaymentModule.php Edited April 16, 2016 by shokinro (see edit history) Link to comment Share on other sites More sharing options...
shokinro Posted April 16, 2016 Share Posted April 16, 2016 (edited) sorry, it seems that I misunderstood your requirement, I was thought the "order confirmation" email. yes, please follow instructions from @mdekker to implement your requirements. Edited April 16, 2016 by shokinro (see edit history) Link to comment Share on other sites More sharing options...
shokinro Posted April 16, 2016 Share Posted April 16, 2016 @mdekker thanks for follow-up. and its my pleasure to help. Link to comment Share on other sites More sharing options...
Bonjovi67 Posted April 18, 2016 Author Share Posted April 18, 2016 New order mails are sent by the mailalerts module. We're going to make a new override for the module mailalerts in order the expose the wanted variable: Create the file /override/modules/mailalerts/mailalerts.php and paste the following contents in it: <?php class MailAlertsOverride extends MailAlerts { public function hookActionValidateOrder($params) { if (!$this->merchant_order || empty($this->merchant_mails)) { return; } // Getting differents vars $context = Context::getContext(); $id_lang = (int)$context->language->id; $id_shop = (int)$context->shop->id; $currency = $params['currency']; $order = $params['order']; $customer = $params['customer']; $configuration = Configuration::getMultiple( array( 'PS_SHOP_EMAIL', 'PS_MAIL_METHOD', 'PS_MAIL_SERVER', 'PS_MAIL_USER', 'PS_MAIL_PASSWD', 'PS_SHOP_NAME', 'PS_MAIL_COLOR' ), $id_lang, null, $id_shop ); $delivery = new Address((int)$order->id_address_delivery); $invoice = new Address((int)$order->id_address_invoice); $order_date_text = Tools::displayDate($order->date_add); $carrier = new Carrier((int)$order->id_carrier); $message = $this->getAllMessages($order->id); if (!$message || empty($message)) { $message = $this->l('No message'); } // Join PDF delivery slip if ($order->delivery_number) { $order_delivery_list = $order->getDeliverySlipsCollection(); Hook::exec('actionPDFDeliverySlipRender', array('order_delivery_list' => $order_delivery_list)); $pdf = new PDF($order_delivery_list, PDF::TEMPLATE_DELIVERY_SLIP, $this->context->smarty); $file_attachment['content'] = $pdf->render(false); $file_attachment['name'] = Configuration::get('PS_DELIVERY_PREFIX', (int)$order->id_lang, null, $order->id_shop).sprintf('%06d', $order->delivery_number).'.pdf'; $file_attachment['mime'] = 'application/pdf'; } else { $file_attachment = null; } $items_table = ''; $products = $params['order']->getProducts(); $customized_datas = Product::getAllCustomizedDatas((int)$params['cart']->id); Product::addCustomizationPrice($products, $customized_datas); foreach ($products as $key => $product) { $unit_price = Product::getTaxCalculationMethod($customer->id) == PS_TAX_EXC ? $product['product_price'] : $product['product_price_wt']; $customization_text = ''; if (isset($customized_datas[$product['product_id']][$product['product_attribute_id']])) { foreach ($customized_datas[$product['product_id']][$product['product_attribute_id']][$order->id_address_delivery] as $customization) { if (isset($customization['datas'][Product::CUSTOMIZE_TEXTFIELD])) { foreach ($customization['datas'][Product::CUSTOMIZE_TEXTFIELD] as $text) { $customization_text .= $text['name'].': '.$text['value'].'<br />'; } } if (isset($customization['datas'][Product::CUSTOMIZE_FILE])) { $customization_text .= count($customization['datas'][Product::CUSTOMIZE_FILE]).' '.$this->l('image(s)').'<br />'; } $customization_text .= '---<br />'; } if (method_exists('Tools', 'rtrimString')) { $customization_text = Tools::rtrimString($customization_text, '---<br />'); } else { $customization_text = preg_replace('/---<br \/>$/', '', $customization_text); } } $url = $context->link->getProductLink($product['product_id']); $items_table .= '<tr style="background-color:'.($key % 2 ? '#DDE2E6' : '#EBECEE').';"> <td style="padding:0.6em 0.4em;">'.$product['product_reference'].'</td> <td style="padding:0.6em 0.4em;"> <strong><a href="'.$url.'">'.$product['product_name'].'</a>' .(isset($product['attributes_small']) ? ' '.$product['attributes_small'] : '') .(!empty($customization_text) ? '<br />'.$customization_text : '') .'</strong> </td> <td style="padding:0.6em 0.4em; text-align:right;">'.Tools::displayPrice($unit_price, $currency, false).'</td> <td style="padding:0.6em 0.4em; text-align:center;">'.(int)$product['product_quantity'].'</td> <td style="padding:0.6em 0.4em; text-align:right;">' .Tools::displayPrice(($unit_price * $product['product_quantity']), $currency, false) .'</td> </tr>'; } foreach ($params['order']->getCartRules() as $discount) { $items_table .= '<tr style="background-color:#EBECEE;"> <td colspan="4" style="padding:0.6em 0.4em; text-align:right;">'.$this->l('Voucher code:').' '.$discount['name'].'</td> <td style="padding:0.6em 0.4em; text-align:right;">-'.Tools::displayPrice($discount['value'], $currency, false).'</td> </tr>'; } if ($delivery->id_state) { $delivery_state = new State((int)$delivery->id_state); } if ($invoice->id_state) { $invoice_state = new State((int)$invoice->id_state); } if (Product::getTaxCalculationMethod($customer->id) == PS_TAX_EXC) { $total_products = $order->getTotalProductsWithoutTaxes(); } else { $total_products = $order->getTotalProductsWithTaxes(); } $order_state = $params['orderStatus']; // Filling-in vars for email $template_vars = array( '{firstname}' => $customer->firstname, '{lastname}' => $customer->lastname, '{birthday}' => date('d-m-Y', strtotime($customer->birthday)), '{email}' => $customer->email, '{delivery_block_txt}' => MailAlert::getFormatedAddress($delivery, "\n"), '{invoice_block_txt}' => MailAlert::getFormatedAddress($invoice, "\n"), '{delivery_block_html}' => MailAlert::getFormatedAddress( $delivery, '<br />', array( 'firstname' => '<span style="color:'.$configuration['PS_MAIL_COLOR'].'; font-weight:bold;">%s</span>', 'lastname' => '<span style="color:'.$configuration['PS_MAIL_COLOR'].'; font-weight:bold;">%s</span>' ) ), '{invoice_block_html}' => MailAlert::getFormatedAddress( $invoice, '<br />', array( 'firstname' => '<span style="color:'.$configuration['PS_MAIL_COLOR'].'; font-weight:bold;">%s</span>', 'lastname' => '<span style="color:'.$configuration['PS_MAIL_COLOR'].'; font-weight:bold;">%s</span>' ) ), '{delivery_company}' => $delivery->company, '{delivery_firstname}' => $delivery->firstname, '{delivery_lastname}' => $delivery->lastname, '{delivery_address1}' => $delivery->address1, '{delivery_address2}' => $delivery->address2, '{delivery_city}' => $delivery->city, '{delivery_postal_code}' => $delivery->postcode, '{delivery_country}' => $delivery->country, '{delivery_state}' => $delivery->id_state ? $delivery_state->name : '', '{delivery_phone}' => $delivery->phone ? $delivery->phone : $delivery->phone_mobile, '{delivery_other}' => $delivery->other, '{invoice_company}' => $invoice->company, '{invoice_firstname}' => $invoice->firstname, '{invoice_lastname}' => $invoice->lastname, '{invoice_address2}' => $invoice->address2, '{invoice_address1}' => $invoice->address1, '{invoice_city}' => $invoice->city, '{invoice_postal_code}' => $invoice->postcode, '{invoice_country}' => $invoice->country, '{invoice_state}' => $invoice->id_state ? $invoice_state->name : '', '{invoice_phone}' => $invoice->phone ? $invoice->phone : $invoice->phone_mobile, '{invoice_other}' => $invoice->other, '{order_name}' => $order->reference, '{order_status}' => $order_state->name, '{shop_name}' => $configuration['PS_SHOP_NAME'], '{date}' => $order_date_text, '{carrier}' => (($carrier->name == '0') ? $configuration['PS_SHOP_NAME'] : $carrier->name), '{payment}' => Tools::substr($order->payment, 0, 32), '{items}' => $items_table, '{total_paid}' => Tools::displayPrice($order->total_paid, $currency), '{total_products}' => Tools::displayPrice($total_products, $currency), '{total_discounts}' => Tools::displayPrice($order->total_discounts, $currency), '{total_shipping}' => Tools::displayPrice($order->total_shipping, $currency), '{total_tax_paid}' => Tools::displayPrice( ($order->total_products_wt - $order->total_products) + ($order->total_shipping_tax_incl - $order->total_shipping_tax_excl), $currency, false ), '{total_wrapping}' => Tools::displayPrice($order->total_wrapping, $currency), '{currency}' => $currency->sign, '{gift}' => (bool)$order->gift, '{gift_message}' => $order->gift_message, '{message}' => $message ); // Shop iso $iso = Language::getIsoById((int)Configuration::get('PS_LANG_DEFAULT')); // Send 1 email by merchant mail, because Mail::Send doesn't work with an array of recipients $merchant_mails = explode(self::__MA_MAIL_DELIMITOR__, $this->merchant_mails); foreach ($merchant_mails as $merchant_mail) { // Default language $mail_id_lang = $id_lang; $mail_iso = $iso; // Use the merchant lang if he exists as an employee $results = Db::getInstance()->executeS(' SELECT `id_lang` FROM `'._DB_PREFIX_.'employee` WHERE `email` = \''.pSQL($merchant_mail).'\' '); if ($results) { $user_iso = Language::getIsoById((int)$results[0]['id_lang']); if ($user_iso) { $mail_id_lang = (int)$results[0]['id_lang']; $mail_iso = $user_iso; } } $dir_mail = false; if (file_exists(dirname(__FILE__).'/mails/'.$mail_iso.'/new_order.txt') && file_exists(dirname(__FILE__).'/mails/'.$mail_iso.'/new_order.html') ) { $dir_mail = dirname(__FILE__).'/mails/'; } if (file_exists(_PS_MAIL_DIR_.$mail_iso.'/new_order.txt') && file_exists(_PS_MAIL_DIR_.$mail_iso.'/new_order.html') ) { $dir_mail = _PS_MAIL_DIR_; } if ($dir_mail) { Mail::Send( $mail_id_lang, 'new_order', sprintf(Mail::l('New order : #%d - %s', $mail_id_lang), $order->id, $order->reference), $template_vars, $merchant_mail, null, $configuration['PS_SHOP_EMAIL'], $configuration['PS_SHOP_NAME'], null, null, $dir_mail, null, $id_shop ); } } } } This will change the validateOrder hook of the module. On line 124 you can see that we have exposed a new variable: {birthday}. You can use this to show the birthday. We are reformatting it to the language the customer is familiar with. Just pick your own preferred date format: http://php.net/manual/en/function.date.php Hi mdekker Thank you for your help. I have tried your suggestion, but when i upload the file to /override/modules/mailalerts/mailalerts.php, my checkout page just shows the code lines from the override file on the screen.. Link to comment Share on other sites More sharing options...
Bonjovi67 Posted April 18, 2016 Author Share Posted April 18, 2016 (edited) Can you provide us with a screenshot? Yes, Edited April 18, 2016 by Bonjovi67 (see edit history) Link to comment Share on other sites More sharing options...
Bonjovi67 Posted April 18, 2016 Author Share Posted April 18, 2016 Add the php tag before the class definition: <?php class MailAlertsOverride extends MailAlerts Thank you that helped, do i need a closing tag too ? Link to comment Share on other sites More sharing options...
Bonjovi67 Posted April 18, 2016 Author Share Posted April 18, 2016 Nice! A closing tag is not necessary. Even recommended against nowadays. But now i dont recieve a copy of the order_conf mail for the mail alerts module Link to comment Share on other sites More sharing options...
Bonjovi67 Posted April 18, 2016 Author Share Posted April 18, 2016 Cannot reproduce. Can you remove /cache/class_index.php in order to regenerate the class index? I just tried to delete it. Did not help, i still dont receive the order confirmation mail. I am using Prestashop 1.6.1.4 with danish language pack as default and one page checkout module from prestashop modules. Link to comment Share on other sites More sharing options...
Bonjovi67 Posted April 18, 2016 Author Share Posted April 18, 2016 I just tried to delete it. Did not help, i still dont receive the order confirmation mail. I am using Prestashop 1.6.1.4 with danish language pack as default and one page checkout module from prestashop modules. If i delete the new mail alerts override file, i can recieve the order_conf mails again Link to comment Share on other sites More sharing options...
Bonjovi67 Posted April 18, 2016 Author Share Posted April 18, 2016 Are we missing something perhaps: http://build.prestashop.com/howtos/module/how-to-override-modules/ ? Maybee Would it be easier to put the call for the birthday data in the original mail alerts file ? I can always redo it after a new prestashop version. Link to comment Share on other sites More sharing options...
Bonjovi67 Posted April 18, 2016 Author Share Posted April 18, 2016 Yes, that doesn't look like a bad idea. The module hasn't been updated for almost a year! I just put your line 124 in the original mail alerts file and now it is working fine, so i can live with that. So it must be some error with the override. Link to comment Share on other sites More sharing options...
Bonjovi67 Posted April 18, 2016 Author Share Posted April 18, 2016 Yeah, overriding a response to a hook is kinda tricky. I'm wondering if it has been implemented correctly in PrestaShop, because if you override this hook it will never get called. Even if you hook the module again onto actionValidateOrder it will not get called anymore... Yes, i think you are right there. But, thank you very much for your help. It got what i needed nevermind the override. Just a small side question if i may,, I also need to pull the costumer email data in the same way for the 'shipped mail', do you know in what file i can find the array for that ? Sorry i am new to prestashop, so it would be a great help, last thing i need to solve for now Link to comment Share on other sites More sharing options...
Bonjovi67 Posted April 18, 2016 Author Share Posted April 18, 2016 I'm not sure if I understand your question correctly. What "costumer email data" would you like to pull? I need to put the costumers email adress in the mail /themes/default-bootstrap/mails/da/shipped.html But i get same problem as above because the costumers email adress is not defined in the corresponding php file that pulls the data for the shipped mail. Same as before i just dont know what php file pulls the data for the shipped mail Link to comment Share on other sites More sharing options...
Bonjovi67 Posted April 21, 2016 Author Share Posted April 21, 2016 You can add extra variables over here: https://github.com/PrestaShop/PrestaShop/blob/9b7702d4ebea82a5b391a8f4cc3f01520d64ab6a/controllers/admin/AdminOrdersController.php#L1510 Like so: if ($order_state->id == Configuration::get('PS_OS_SHIPPING') && $order->shipping_number) { $customer = new Customer($order->id_customer); if (Validate::isLoadedObject($customer)) { $customer_email = $customer->email; } else { $customer_email = ''; } $templateVars = array( '{followup}' => str_replace('@', $order->shipping_number, $carrier->url), '{email}' => $customer_email ); } Thank you very much for the answer. But is this not for 'in_transit' mail ? I cant find elements for the the 'shipped' mail there ? Link to comment Share on other sites More sharing options...
Bonjovi67 Posted May 20, 2016 Author Share Posted May 20, 2016 You can add extra variables over here: https://github.com/PrestaShop/PrestaShop/blob/9b7702d4ebea82a5b391a8f4cc3f01520d64ab6a/controllers/admin/AdminOrdersController.php#L1510 Like so: if ($order_state->id == Configuration::get('PS_OS_SHIPPING') && $order->shipping_number) { $customer = new Customer($order->id_customer); if (Validate::isLoadedObject($customer)) { $customer_email = $customer->email; } else { $customer_email = ''; } $templateVars = array( '{followup}' => str_replace('@', $order->shipping_number, $carrier->url), '{email}' => $customer_email ); } Hi again mdekker I tried the your solution above, but it only works for the in_transit.html mail. I need to put the costumers email adress in the shipped.html mail(the email that is send to the costumer, when you change the order status to 'shipped'). The variables for the order status mails must in another file ?, but i dont know what file to look in. Anyone please ? i am really stuck with this problem and cannot use my trustpilot Link to comment Share on other sites More sharing options...
Bonjovi67 Posted May 20, 2016 Author Share Posted May 20, 2016 Hi again mdekker I tried the your solution above, but it only works for the in_transit.html mail. I need to put the costumers email adress in the shipped.html mail(the email that is send to the costumer, when you change the order status to 'shipped'). The variables for the order status mails must in another file ?, but i dont know what file to look in. Anyone please ? i am really stuck with this problem and cannot use my trustpilot I got it to work now. The changes above should be at line 536 not 1511 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