Jump to content

Email template - order confirmation


jirka_malvin

Recommended Posts

Hi,

I did not wanted 2 emails during order process (preparation + order conformation), so I disabled sending order confirmation in in/prestashop/classes/PaymentModule.php by commenting 

 

if (Validate::isEmail($this->context->customer->email)) {

                        /* disable    Mail::Send(

                                (int)$order->id_lang,

                                'order_conf',

                                Mail::l('Order confirmation', (int)$order->id_lang),

                                $data,

                                $this->context->customer->email,

                                $this->context->customer->firstname.' '.$this->context->customer->lastname,

                                null,

                                null,

                                $file_attachement,

                                null, _PS_MAIL_DIR_, false, (int)$order->id_shop

                            ); */

Second email (order conformation) is not send, it is OK.

 

We want to confirm order manually. 

We created new order status "order confirmation" and linked to template order_conf.

But when we change status to "order confirmation", email is sent but without filled variables. Only order nr., name, surname is set up. Details are not matched:

post-1116845-0-01790700-1474139311_thumb.pngpost-1116845-0-75932800-1474139304_thumb.png

 

How to fill variables in order conformation?

Or is there any tutorial how to create email template with custom variables? 

 

Thanks

 

Jiri

Edited by jirka_malvin (see edit history)
Link to comment
Share on other sites

the variables must be prepared and passed when the email is sent.

yo may need to check following class,  the email is sent in following classes/method

 

/classes/order/OrderHistory.php

 

changeIdOrderState() or addWithemail()

Thanks, It works - I have only one problem remaining with variable {products}. '{products}' => $product_list_html ... I am not able to get list of products - in email still have blank place. 

I tried to copy all functions rom PaymentOrder relating this variable, but without success.

 

// Construct order detail table for the email
 
                    $products_list = '';
                    $virtual_product = true;
 
                    $product_var_tpl_list = array();
                    foreach ($order->product_list 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')});
 
                        $product_price = Product::getTaxCalculationMethod() == PS_TAX_EXC ? Tools::ps_round($price, 2) : $price_wt;
 
                        $product_var_tpl = array(
                            'reference' => $product['reference'],
                            'name' => $product['name'].(isset($product['attributes']) ? ' - '.$product['attributes'] : ''),
                            'unit_price' => Tools::displayPrice($product_price, $this->context->currency, false),
                            'price' => Tools::displayPrice($product_price * $product['quantity'], $this->context->currency, false),
                            'quantity' => $product['quantity'],
                            'customization' => array()
                        );
 
                        $customized_datas = Product::getAllCustomizedDatas((int)$order->id_cart);
                        if (isset($customized_datas[$product['id_product']][$product['id_product_attribute']])) {
                            $product_var_tpl['customization'] = array();
                            foreach ($customized_datas[$product['id_product']][$product['id_product_attribute']][$order->id_address_delivery] as $customization) {
                                $customization_text = '';
                                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'];
 
                                $product_var_tpl['customization'][] = array(
                                    'customization_text' => $customization_text,
                                    'customization_quantity' => $customization_quantity,
                                    'quantity' => Tools::displayPrice($customization_quantity * $product_price, $this->context->currency, false)
                                );
                            }
                        }
 
                        $product_var_tpl_list[] = $product_var_tpl;
                        // Check if is not a virutal product for the displaying of shipping
                        if (!$product['is_virtual']) {
                            $virtual_product &= false;
                        }
                    } // end foreach ($products)
 
                    $product_list_txt = '';
                    $product_list_html = '';
                    if (count($product_var_tpl_list) > 0) {
                        $product_list_txt = $this->getEmailTemplateContent('order_conf_product_list.txt', Mail::TYPE_TEXT, $product_var_tpl_list);
                        $product_list_html = $this->getEmailTemplateContent('order_conf_product_list.tpl', Mail::TYPE_HTML, $product_var_tpl_list);
                    }

 

Is there any tutorial how to get all products relating order_id more simply? or what code/functions  I miss to work it properly?

 

Thanks Jiri 

Link to comment
Share on other sites

make sure the product list data was loaded to $order->product_list.

you can try to print out using print_r(($order->product_list) to see if it is empty or not.

Thanks for reply,

if I put print_r in to OrderHistory.php - it will show nothing in email. Situation is same. 

How I can load / check product data if exist?

 

Update:

I put function in to History ordrr like this: '{products}' => print_r($order->product_list),

and result in email is:

post-1116845-0-50058000-1474209533_thumb.png

 

So it shows number of ordered products. But how to get details? 

 

Jiri

Edited by jirka_malvin (see edit history)
Link to comment
Share on other sites

try to put a line of code of following to stop PHP execution, so that you will see what is output of your print_r.

 

print "here is output of product list:";

 

print_r(($order->product_list)

 

die("...here execution stopped");

output in browser: here is output of product list:...here execution stopped

repaired code:

print "here is output of product list:";

.

print_r($order->product_list);

.

die("...here execution stopped");

 

So, it looks like it is empty.

 

How to fix this?

Is there any simple way how to get data from DB relating to order nr?

I need only these parameters: code, product name, price /pc, quantity, price total  

 

Jiri

Link to comment
Share on other sites

make sure if the $order object is loaded correctly.

If it is not, you will need load that $order object first and then call $order->getProducts() to load the list of the products.

Hi,

I do not know how to load this object in OrderHistory. Can you please show me code how to connect it to order_id?

I tried to look it up in Payment module, but without success.

 

Jiri

Link to comment
Share on other sites

I am not sure where(which file, which method) you have added your code, if you are not sure what you are doing it is difficult to get it to work.

 

I think the order status should changed in back office order details page?  So it has nothing to do with payment module since it was done after payment.

If that is the true, you will need to override AdminOrdersController.php to prepared the variables and then pass to the class/method which is used to update order status and also pass in the variables.

Link to comment
Share on other sites

I am not sure where(which file, which method) you have added your code, if you are not sure what you are doing it is difficult to get it to work.

 

I think the order status should changed in back office order details page?  So it has nothing to do with payment module since it was done after payment.

If that is the true, you will need to override AdminOrdersController.php to prepared the variables and then pass to the class/method which is used to update order status and also pass in the variables.

I changed OrderHistory.php to send email order_conf2 (copy of order_conf). Everything is OK, except matching product details {products} in email. So I am looking for solution, how to get product data for order. I have available order number so need to make function to get data from DB. I was thinking I can copy this methods from PaymentOrder.php, but it seems to be more complicated. I will try to fix it by creating special function only for this case.

 

Jiri 

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