Jump to content
Roman0002

How to add {id_order} on email(order conf.)

Recommended Posts

Hi guys,

 

I would like to add order number({id_order}) to mail(order conf.)

How do I do that?

 

For answers and help thank you in advance

Share this post


Link to post
Share on other sites

You have 2 ways of doing this:

 

1. Change directly in classes/PaymentModule.php. Search for 

// Send an e-mail to customer (one order = one email)
					if ($id_order_state != Configuration::get('PS_OS_ERROR') && $id_order_state != Configuration::get('PS_OS_CANCELED') && $this->context->customer->id)
					{
						$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;

						$data = array(
						'{firstname}' => $this->context->customer->firstname,
						'{lastname}' => $this->context->customer->lastname,
						'{email}' => $this->context->customer->email, 
.....

and add {id_order} in the $data array:

						'{id_order}' => $order->id, 

2. If you want to do this from within a module, you have to override Mail class, somethings like:

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)
	{
		$status = true;
		if (is_array($template_vars) && (
				(isset($template_vars['{id_order}']) && (int)$template_vars['{id_order}'] > 0) ||
				isset($template_vars['{order_name}']) && $template_vars['{order_name}'] != '')
		){

			//if we don't have an id_order but we have order_name - get the corresponding id_order
			if (!isset($template_vars['{id_order}']) || (int)$template_vars['{id_order}'] == 0) {
				$orderList = Db::getInstance (_PS_USE_SQL_SLAVE_)->ExecuteS ("
				SELECT `id_order`
				FROM `"._DB_PREFIX_."orders`
				WHERE `reference` = '" . $template_vars[ '{order_name}' ] . "'");
			} else
				$orderList = array('id_order' => $template_vars['{id_order}']);

			//For each id_order, add id_order and send it
			foreach ($orderList as $order) {
				$order = new Order($order);

				if ($order->id) {
					$template_vars['{id_order}'] = $order->id;
				}

				$st = parent::Send($id_lang, $template, $subject, $template_vars, $to,
					$to_name, $from, $from_name, $file_attachment, $mode_smtp,
					$template_path, $die, $id_shop, $bcc);

				if ($status && !$st)
					$status = false;
			}

			return $status;
		} else {
			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);
		}

		return true;
	}
}

The second choice will ensure that all emails sent that have an id_order - will add them to $template_vars array and can be used in email template.

  • Like 1

Share this post


Link to post
Share on other sites

Unfortunately both methods do not work on PS 1.6. I try to find a solution a couple of weeks now but no luck

Share this post


Link to post
Share on other sites

Find the data array on line 705 (in PrestaShop v1.6.1.7) of classes/PaymentModule.php:

                        $data = array(
                        '{firstname}' => $this->context->customer->firstname,

and change it to:

                        $data = array(
                        '{order_id}' => (int)$order->id,
                        '{firstname}' => $this->context->customer->firstname,

Then you can use {order_id} in order_conf.html and order_conf.txt.

Share this post


Link to post
Share on other sites

Sorry no luck

I changed order_conf in both /mails & /themes/mytheme/mails

I also changed new_order in both /modules/mailalerts and /themes/mytheme/modules/mailalerts

 

 

Find the data array on line 705 (in PrestaShop v1.6.1.7) of classes/PaymentModule.php:

                        $data = array(
                        '{firstname}' => $this->context->customer->firstname,

and change it to:

                        $data = array(
                        '{order_id}' => (int)$order->id,
                        '{firstname}' => $this->context->customer->firstname,

Then you can use {order_id} in order_conf.html and order_conf.txt.

Share this post


Link to post
Share on other sites

That should have worked for order_conf.html and order_conf.txt, assuming it's being called by a payment module. If you've set it up to be called by an order status change, then the code above won't work, since you'd have to modify the data array in classes/OrderHistory.php instead.

Share this post


Link to post
Share on other sites

Oh I see..

as payment I use codfee (Cash on delivery with fee) which is an alternative to COD. What can I do in this case?

 

Thanks

Share this post


Link to post
Share on other sites

I'm not familiar with that module. I would have expected it to use the PaymentModule class to send emails like the original Cash on Delivery module, but then my code above should have worked for you. Search the module to see if you can find where it's sending emails.

Share this post


Link to post
Share on other sites

Hello,

so is there actually any way to add variables to order_conf email? I'm trying to add bankwire details to template if a customer uses bankwire payment method.
For the test I've added test tag

{tagtest} => 'test'

to data array but it doesn't work at all.
I would be grateful for any help.

Share this post


Link to post
Share on other sites

Not sure how to do that, but I know for sure that bankwire payment sends it's own email to customer with the bank details. Just make sure that the order status has "Send email to customer" checked.

 

Hello,

so is there actually any way to add variables to order_conf email? I'm trying to add bankwire details to template if a customer uses bankwire payment method.
For the test I've added test tag

{tagtest} => 'test'

to data array but it doesn't work at all.
I would be grateful for any help.

Edited by joss54 (see edit history)

Share this post


Link to post
Share on other sites

I have made 2 modifications in order to add the ID of order to emails subject, tested and worked for me (PS 1.6.1.18). I have posted already my solution on another topic, here:

https://www.prestashop.com/forums/topic/926319-change-prestashop-email-subject-add-order-number/?tab=comments#comment-3192192

The ID of order is added now in 2 situations: 1. in subject of first email which customer receive after successful place an order; 2. on all emails subject sent when an order status have been changed and of course, PS was set up to notify the customer by email about status change.

cheers !

Share this post


Link to post
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...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More