One of our clients asked for a feature that allows manually sending additional email about successful order. We created the following button for him:
And in this article you will find out how we implemented this solution.
In order to add this button we’ve done the overwrite for the template:
/administration/themes/default/template/controllers/orders/helpers/view/view.tpl
by moving it here:
/override/controllers/admin/templates/orders/helpers/view/view.tpl
1 2 3 4 5 6 7 8 9 10 11 12 13 |
... <!-- Change status form --> <form action="{$currentIndex}&vieworder&token={$smarty.get.token}" method="post" class="form-horizontal well"> <div class="row" style="padding-bottom: 15px"> <div class="col-lg-12"> <input type="hidden" name="id_order" value="{$order->id}" /> <button type="submit" name="resendOrderConfirmation" class="btn btn-primary"> {l s='Resend "Order confirmation" email'} </button> </div> </div> </form> ... |
Then we’ve done the overwrite for this class:
/override/controllers/admin/AdminOrdersController.php
by expanding this function: postProcess()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
public function postProcess() { parent::postProcess(); if (Tools::isSubmit('resendOrderConfirmation') && Tools::getValue('id_order') > 0) { $order = new Order(Tools::getValue('id_order')); $customer = new Customer($order->id_customer); if ($this->tabAccess['edit'] === '1') { $order_status = new OrderState((int)$order->current_state, (int)$order->id_lang); // Join PDF invoice if ((int)Configuration::get('PS_INVOICE') && $order_status->invoice && $order->invoice_number) { $pdf = new PDF($order->getInvoicesCollection(), PDF::TEMPLATE_INVOICE, $this->context->smarty); $file_attachement['content'] = $pdf->render(false); $file_attachement['name'] = Configuration::get('PS_INVOICE_PREFIX', (int)$order->id_lang, null, $order->id_shop).sprintf('%06d', $order->invoice_number).'.pdf'; $file_attachement['mime'] = 'application/pdf'; } else $file_attachement = null; require_once _PS_MODULE_DIR_ . 'belvg_sample/includer.php'; $data = $this->fillOrderConfirmationData($order->id); if (Mail::Send( (int)$order->id_lang, 'order_conf', Mail::l('Order confirmation', (int)$order->id_lang), $data, $customer->email, $customer->firstname.' '.$customer->lastname, null, null, $file_attachement, null, _PS_MAIL_DIR_, false, (int)$order->id_shop )) { $belvg_sample = Module::getInstanceByName('belvg_sample'); $belvg_sample->saveMsg($belvg_sample->l('Order confirmation mail has been re-sent'), $order->id); Tools::redirectAdmin(self::$currentIndex.'&id_order='.$order->id.'&vieworder&conf=10&token='.$this->token); } } else { $this->errors[] = Tools::displayError('You do not have permission to edit this.'); } } … |
Basically, we’ve conducted the same actions that Prestashop conducts when creating an order in the following class:
PaymentModule::validateOrder()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 |
public static function _getFormatedAddress(Address $the_address, $line_sep, $fields_style = array()) { return AddressFormat::generateAddress($the_address, array('avoid' => array()), $line_sep, ' ', $fields_style); } public function fillOrderConfirmationData($id_order) { $order = new Order($id_order); $customer = new Customer($order->id_customer); $invoice = new Address($order->id_address_invoice); $delivery = new Address($order->id_address_delivery); $delivery_state = $delivery->id_state ? new State($delivery->id_state) : false; $invoice_state = $invoice->id_state ? new State($invoice->id_state) : false; $carrier = new Carrier($order->id_carrier); $currency = new Currency($order->id_currency); // Construct order detail table for the email $products_list = ''; $virtual_product = false; foreach ($order->getCartProducts() as $product) { $price = Product::getPriceStatic((int)$product['id_product'], false, ($product['id_product_attribute'] ? (int)$product['id_product_attribute'] : null), 6, null, false, true, $product['cart_quantity'], false, (int)$order->id_customer, (int)$order->id_cart, (int)$order->{Configuration::get('PS_TAX_ADDRESS_TYPE')}); $price_wt = Product::getPriceStatic((int)$product['id_product'], true, ($product['id_product_attribute'] ? (int)$product['id_product_attribute'] : null), 2, null, false, true, $product['cart_quantity'], false, (int)$order->id_customer, (int)$order->id_cart, (int)$order->{Configuration::get('PS_TAX_ADDRESS_TYPE')}); $products_list .= '<tr> <td style="border:1px solid #D6D4D4;"> <table class="table"> <tr> <td width="10"> </td> <td> <font size="2" face="Open-sans, sans-serif" color="#555454"> '.$product['reference'].' </font> </td> <td width="10"> </td> </tr> </table> </td> <td style="border:1px solid #D6D4D4;"> <table class="table"> <tr> <td width="10"> </td> <td> <font size="2" face="Open-sans, sans-serif" color="#555454"> <strong>'.$product['name'].(isset($product['attributes']) ? ' - '.$product['attributes'] : '').'</strong> </font> </td> <td width="10"> </td> </tr> </table> </td> <td style="border:1px solid #D6D4D4;"> <table class="table"> <tr> <td width="10"> </td> <td align="right"> <font size="2" face="Open-sans, sans-serif" color="#555454"> '.Tools::displayPrice(Product::getTaxCalculationMethod() == PS_TAX_EXC ? Tools::ps_round($price, 2) : $price_wt, $currency, false).' </font> </td> <td width="10"> </td> </tr> </table> </td> <td style="border:1px solid #D6D4D4;"> <table class="table"> <tr> <td width="10"> </td> <td align="right"> <font size="2" face="Open-sans, sans-serif" color="#555454"> '.$product['quantity'].' </font> </td> <td width="10"> </td> </tr> </table> </td> <td style="border:1px solid #D6D4D4;"> <table class="table"> <tr> <td width="10"> </td> <td align="right"> <font size="2" face="Open-sans, sans-serif" color="#555454"> '.Tools::displayPrice($product['quantity'] * (Product::getTaxCalculationMethod() == PS_TAX_EXC ? Tools::ps_round($price, 2) : $price_wt), $currency, false).' </font> </td> <td width="10"> </td> </tr> </table> </td> </tr>'; $customization_quantity = 0; $customized_datas = Product::getAllCustomizedDatas((int)$order->id_cart); if (isset($customized_datas[$product['id_product']][$product['id_product_attribute']])) { $customization_text = ''; foreach ($customized_datas[$product['id_product']][$product['id_product_attribute']][$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 .= sprintf(Tools::displayError('%d image(s)'), count($customization['datas'][Product::CUSTOMIZE_FILE])).'<br />'; $customization_quantity = (int)$product['customization_quantity']; $products_list .= '<tr> <td colspan="2" style="border:1px solid #D6D4D4;"> <table class="table"> <tr> <td width="10"> </td> <td> <font size="2" face="Open-sans, sans-serif" color="#555454"> <strong>'.$product['name'].(isset($product['attributes']) ? ' - '.$product['attributes'] : '').'</strong><br> '.$customization_text.' </font> </td> <td width="10"> </td> </tr> </table> </td> <td style="border:1px solid #D6D4D4;"> <table class="table"> <tr> <td width="10"> </td> <td align="right"> <font size="2" face="Open-sans, sans-serif" color="#555454"> '.Tools::displayPrice(Product::getTaxCalculationMethod() == PS_TAX_EXC ? Tools::ps_round($price, 2) : $price_wt, $currency, false).' </font> </td> <td width="10"> </td> </tr> </table> </td> <td style="border:1px solid #D6D4D4;"> <table class="table"> <tr> <td width="10"> </td> <td align="right"> <font size="2" face="Open-sans, sans-serif" color="#555454"> '.$customization_quantity.' </font> </td> <td width="10"> </td> </tr> </table> </td> <td style="border:1px solid #D6D4D4;"> <table class="table"> <tr> <td width="10"> </td> <td align="right"> <font size="2" face="Open-sans, sans-serif" color="#555454"> '.Tools::displayPrice($customization_quantity * (Product::getTaxCalculationMethod() == PS_TAX_EXC ? Tools::ps_round($price, 2) : $price_wt), $currency, false).' </font> </td> <td width="10"> </td> </tr> </table> </td> </tr>'; } } // Check if is not a virutal product for the displaying of shipping if (!$product['is_virtual']) $virtual_product &= false; } $cart_rules_list = ''; foreach ($order->getCartRules() as $cart_rule) { $cart_rules_list .= ' <tr class="conf_body"> <td bgcolor="#f8f8f8" colspan="4" style="border:1px solid #D6D4D4;color:#333;padding:7px 0"> <table class="table" style="width:100%;border-collapse:collapse"> <tr> <td width="10" style="color:#333;padding:0"></td> <td align="right" style="color:#333;padding:0"> <font size="2" face="Open-sans, sans-serif" color="#555454"> <strong>'.Tools::displayError('Voucher name:').' '.$cart_rule['name'].'</strong> </font> </td> <td width="10" style="color:#333;padding:0"></td> </tr> </table> </td> <td bgcolor="#f8f8f8" colspan="4" style="border:1px solid #D6D4D4;color:#333;padding:7px 0"> <table class="table" style="width:100%;border-collapse:collapse"> <tr> <td width="10" style="color:#333;padding:0"></td> <td align="right" style="color:#333;padding:0"> <font size="2" face="Open-sans, sans-serif" color="#555454"> '.($cart_rule['value'] != 0.00 ? '-' : '').Tools::displayPrice($cart_rule['value'], $currency, false).' </font> </td> <td width="10" style="color:#333;padding:0"></td> </tr> </table> </td> </tr>'; } $data = array( '{firstname}' => $customer->firstname, '{lastname}' => $customer->lastname, '{email}' => $customer->email, '{delivery_block_txt}' => self::_getFormatedAddress($delivery, "\n"), '{invoice_block_txt}' => self::_getFormatedAddress($invoice, "\n"), '{delivery_block_html}' => self::_getFormatedAddress($delivery, '<br />', array( 'firstname' => '<span style="font-weight:bold;">%s</span>', 'lastname' => '<span style="font-weight:bold;">%s</span>' )), '{invoice_block_html}' => self::_getFormatedAddress($invoice, '<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}' => $virtual_product ? Tools::displayError('No carrier') : $carrier->name, '{payment}' => $order->payment, //Tools::substr($order->payment, 0, 32), '{products}' => $products_list, '{discounts}' => $cart_rules_list, '{total_paid}' => Tools::displayPrice($order->total_paid, $currency, false), '{total_products}' => Tools::displayPrice($order->total_paid - $order->total_shipping - $order->total_wrapping + $order->total_discounts, $currency, false), '{total_discounts}' => Tools::displayPrice($order->total_discounts, $currency, false), '{total_shipping}' => Tools::displayPrice($order->total_shipping, $currency, false), '{total_wrapping}' => Tools::displayPrice($order->total_wrapping, $currency, false), '{total_tax_paid}' => Tools::displayPrice(($order->total_products_wt - $order->total_products) + ($order->total_shipping_tax_incl - $order->total_shipping_tax_excl), $currency, false), '{samplekonto_number}' => '', '{paymentgiftcard_number}' => '', '{paymentgiftcard_cvc}' => '' ); return $data; } |
require_once _PS_MODULE_DIR_ . ‘belvg_sample/includer.php’;
$belvg_sample = Module::getInstanceByName(‘belvg_sample’);
$belvg_sample->saveMsg($belvg_sample->l(‘Order confirmation mail has been re-sent’), $order->id);
INCOMPLETE EXPLANATION!!!
I am just started using Prestashop. I want to send email notification after every two days regularly to payment pending customer automatically.
Thanks
Guys :: read ALEX’s other tutorial :: http://blog.belvg.com/how-to-create-a-custom-product-tab-in-prestashop.html
Remove the custom module dependency, it shall work.
Great post ALEX, saved me some time today. Will get running my shop much sooner. THX!
Hi !
I do the same as Jordi Llobet but I don’t recive the email too.
I think I’ve forgotten something, can you help us?
Thanks!!
Now I tried a different approach:
1st I added the view.tpl in override
2nd I created an AdminOrdersController.php empty and I posted the code provded
3rd I deleted the cache/class_index.php file
I tested but the email is not received.
What I am missing?
Thanks!
Hello, please Can you help me? I cannot find PaymentModule::validateOrder() in /override/controllers/admin/AdminOrdersController.php.Can you attach file AdminOrdersController.php ? Thank you