sandrayin Posted August 26, 2017 Share Posted August 26, 2017 Greetings, I am using PS1.6.1.16 and I have developed an override for OrderHistory.php. This override should be able you to use variables that you see in customer confirmation email to any other email templates regarding the order (shipped) (preparation), etc. I have not tried other templates. This override will not work with PS1.6.0 as it is not using the sendEmail function, rather it is using addWithemail function. You can change the function name to this and try. Put this code into override/classes/order/OrderHistory.php. If you already have a file, simply copy the function "public function sendEmail" { } and paste into your existing php. <?php class OrderHistory extends OrderHistoryCore { public function sendEmail($order, $template_vars = false) { $invoice = new Address((int)$order->id_address_invoice); $delivery = new Address((int)$order->id_address_delivery); $delivery_state = $delivery->id_state ? new State((int)$delivery->id_state) : false; $invoice_state = $invoice->id_state ? new State((int)$invoice->id_state) : false; $carrier = new Carrier((int)$order->id_carrier); $data = array( '{delivery_block_txt}' => AddressFormat::generateAddress($delivery, array('avoid' => array()), "\n", ' '), '{invoice_block_txt}' => AddressFormat::generateAddress($invoice, array('avoid' => array()), "\n", ' '), '{delivery_block_html}' => AddressFormat::generateAddress($delivery, array('avoid' => array()), '<br />', ' ', array( 'firstname' => '<span style="font-weight:bold;">%s</span>', 'lastname' => '<span style="font-weight:bold;">%s</span>' )), '{invoice_block_html}' => AddressFormat::generateAddress($invoice, array('avoid' => array()), '<br />', ' ', array( 'firstname' => '<span style="font-weight:bold;">%s</span>', 'lastname' => '<span style="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_vat_number}' => $invoice->vat_number, '{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->getUniqReference(), '{date}' => Tools::displayDate(date('Y-m-d H:i:s'), null, 1), '{carrier}' => $carrier->name, '{payment}' => Tools::substr($order->payment, 0, 32), '{shipping_number}' => $order->shipping_number, //'{products}' => $product_list_html, //'{products_txt}' => $product_list_txt, //'{discounts}' => $cart_rules_list_html, //'{discounts_txt}' => $cart_rules_list_txt, '{total_paid}' => Tools::displayPrice($order->total_paid, $this->context->currency, false), '{total_products}' => Tools::displayPrice(Product::getTaxCalculationMethod() == PS_TAX_EXC ? $order->total_products : $order->total_products_wt, $this->context->currency, false), '{total_discounts}' => Tools::displayPrice($order->total_discounts, $this->context->currency, false), '{total_shipping}' => Tools::displayPrice($order->total_shipping, $this->context->currency, false), '{total_wrapping}' => Tools::displayPrice($order->total_wrapping, $this->context->currency, false), '{total_tax_paid}' => Tools::displayPrice(($order->total_products_wt - $order->total_products) + ($order->total_shipping_tax_incl - $order->total_shipping_tax_excl), $this->context->currency, false) ); if ($template_vars) { $data = array_merge($data, $template_vars); } return parent::sendEmail($order, $data); } } For variable {products}, {discounts} will not work because I have not figure out the proper way to grab the values, as I am not using this variable for my other email templates. You can simply add your own variable provided you know how to grab it from other classes. Usable variables as of above php code: {delivery_block_txt}{invoice_block_txt}{delivery_block_html}{invoice_block_html}{delivery_company}{delivery_firstname}{delivery_lastname}{delivery_address1}{delivery_address2}{delivery_city}{delivery_postal_code}{delivery_country}{delivery_state}{delivery_phone}{delivery_other}{invoice_company}{invoice_vat_number}{invoice_firstname}{invoice_lastname}{invoice_address2}{invoice_address1}{invoice_city}{invoice_postal_code}{invoice_country}{invoice_state}{invoice_phone}{invoice_other}{order_name}{date}{carrier}{payment}{shipping_number}{total_paid}{total_products}{total_discounts}{total_shipping}{total_wrapping}{total_tax_paid} 1 Link to comment Share on other sites More sharing options...
Nickovitshj Posted September 27, 2021 Share Posted September 27, 2021 I have achieved the same as you. But I in fact do needs the products list. Does anyone know how to achieve this? Link to comment Share on other sites More sharing options...
Nickovitshj Posted September 27, 2021 Share Posted September 27, 2021 /var/www/html/classes/order/OrderHistory.php I added the {product_list_fix} variable. And i'm now able to read out the first product of my order in my email template. Does anyone know how I can read out all products from one order? $data = array( '{lastname}' => $result['lastname'], '{firstname}' => $result['firstname'], '{id_order}' => (int) $this->id_order, '{order_name}' => $order->getUniqReference(), '{followup}' => str_replace('@', $order->getWsShippingNumber(), $carrierUrl), '{shipping_number}' => $order->getWsShippingNumber(), '{delivery_country}' => $delivery->country, '{delivery_address1}' => $delivery->address1, '{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, '{product_list_fix}' => $result['product_name'], ); $result = Db::getInstance()->getRow(' SELECT osl.`template`, c.`lastname`, c.`firstname`, d.`product_name`, 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_ . 'order_detail` d ON oh.`id_order` = d.`id_order` 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'); Link to comment Share on other sites More sharing options...
Nickovitshj Posted September 28, 2021 Share Posted September 28, 2021 For those looking for a solution to this as well. The topic below was a great help for me: 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