Page 1 of 2
Adding Customer Name to Admin Alert mail for new order
Posted: Tue Jan 16, 2018 9:32 pm
by MarijnRutten
Dear Sir / Madam,
Is there a way to add some customer details to the Email Alert which goes to the administrator after a new order has been placed?
I kind of understand PHP, so writing something myself is no problem.
I already wrote myself a script which emails me some user details when they login to the site, but I can't seem to get any details about customers when they place an order.
Help would be really appreciated, because this is the only thing preventing me from launching the shop..
Kind regards,
Marijn Rutten
Re: Adding Customer Name to Admin Alert mail for new order
Posted: Wed Jan 17, 2018 6:27 am
by straightlight
No OC version posted. Which customer details are you referring to? More information are needed.
Re: Adding Customer Name to Admin Alert mail for new order
Posted: Tue Jan 23, 2018 3:28 pm
by MarijnRutten
Dear sir / madam,
The OC version is 3.0.2.0
When I receive mail that a customer ordered something from the store, I only receive:
- Order number
- Date of purchase
- Order status
- Products
- SubTotal
- Total
I also want to see who bought something from the site.
Where can I edit these settings?
Kind Regards,
Marijn Rutten
Re: Adding Customer Name to Admin Alert mail for new order
Posted: Tue Jan 23, 2018 4:20 pm
by opencart-solutions
That's very simple:
In
catalog/controller/mail/order.php
Code: Select all
$data['date_added'] = date($this->language->get('date_format_short'), strtotime($order_info['date_added']));
after add
Code: Select all
$data['name'] = $order_info['firstname'])." ".$order_info['lastname']);
next find
Code: Select all
$data['text_date_added'] = $this->language->get('text_date_added');
and after add this
Code: Select all
$data['text_fullname'] = $this->language->get('text_fullname');
In
catalog/language/your_language/mail/order_alert.php find this
Code: Select all
$_['text_date_added'] = 'Date Added:';
and after add
In
catalog/view/theme/your_theme_name/template/mail/order_alert.twig find this
Code: Select all
{{ text_date_added }} {{ date_added }}
after add this
...and that is all. If you had problems, contact me calmly. Have a nice day
Re: Adding Customer Name to Admin Alert mail for new order
Posted: Tue Jan 23, 2018 6:39 pm
by MarijnRutten
I have got the real solution.
With this you can have an exact copy of what the customer gets.
Visit the next file:
Catalog/controller/mail/order.php
Go to:
Code: Select all
public function add($order_info, $order_status_id, $comment, $notify) {
In this function scroll down till the end of the function.
Under:
Write the next sentence:
Code: Select all
mail('YOURMAIL@.com', 'New incoming order', $this->load->view('mail/order_add', $data), 'Content-Type: text/html; charset=UTF-8\r\n');
Save the file and after that, go to "yourshop/admin" and login.
Go to "System"->"Settings"->"Edit"->"Mail" and unmark "New order"
So you won't get duplicate mails from new orders
Re: Adding Customer Name to Admin Alert mail for new order
Posted: Wed Jan 24, 2018 4:34 am
by straightlight
I would not suggest the use of the proposed solution above since most hosting providers may filter multiple outbound email activities with the use of different email protocols.
Re: Adding Customer Name to Admin Alert mail for new order
Posted: Thu Feb 08, 2018 8:47 pm
by taltenweg
Hi all,
I think it's simple,replace in /catalog/controller/mail/order.php line
$mail->setTo($order_info['email']);
with line
$mail->setTo($order_info['email'].";".$from);
or use instead of $from something like $mail->setTo($order_info['email'].";
mail@mail.com");
Cheers,
Thomas
Re: Adding Customer Name to Admin Alert mail for new order
Posted: Mon Mar 26, 2018 12:05 am
by Ninjas-Everywhere!
straightlight wrote: ↑Wed Jan 24, 2018 4:34 am
I would not suggest the use of the proposed solution above since most hosting providers may filter multiple outbound email activities with the use of different email protocols.
If the above solutions are not the answer, then what is the solution?
Re: Adding Customer Name to Admin Alert mail for new order
Posted: Mon Mar 26, 2018 12:09 am
by straightlight
Ninjas-Everywhere! wrote: ↑Mon Mar 26, 2018 12:05 am
straightlight wrote: ↑Wed Jan 24, 2018 4:34 am
I would not suggest the use of the proposed solution above since most hosting providers may filter multiple outbound email activities with the use of different email protocols.
If the above solutions are not the answer, then what is the solution?
Proper email configuration or the use of an extension that will alternate these manual tactics due to server configuration that may require different email headers in order to send those emails.
Re: Adding Customer Name to Admin Alert mail for new order
Posted: Tue Mar 27, 2018 6:18 am
by Ninjas-Everywhere!
When you say, "proper email configuration", what do you mean?
If we are receiving the various emails generated by the system, then the email is configured correctly. I am trying to figure out the correct way to adjust the Order Email that is generated by the system and sent to the Administrator to include the First and Last Name of the person who placed the order along with the details that are already present in the email.
The data was added in the .twig files (parameters copied from the New Account email .twig), but in the email generated by the system when a new order is placed, it only shows a space where the information is supposed to be and not the actual information.
If there needs to be an extension added in order to perform this, seemingly small but important function, then which extension do you recommend?
Re: Adding Customer Name to Admin Alert mail for new order
Posted: Tue Mar 27, 2018 6:37 am
by straightlight
In catalog/controller/mail/order.php file,
find:
Code: Select all
$data['comment'] = strip_tags($order_info['comment']);
add above:
Code: Select all
if ($order_info['payment_address_format']) {
$format = $order_info['payment_address_format'];
} else {
$format = '{firstname} {lastname}' . "\n" . '{company}' . "\n" . '{address_1}' . "\n" . '{address_2}' . "\n" . '{city} {postcode}' . "\n" . '{zone}' . "\n" . '{country}';
}
$find = array(
'{firstname}',
'{lastname}',
'{company}',
'{address_1}',
'{address_2}',
'{city}',
'{postcode}',
'{zone}',
'{zone_code}',
'{country}'
);
$replace = array(
'firstname' => $order_info['payment_firstname'],
'lastname' => $order_info['payment_lastname'],
'company' => $order_info['payment_company'],
'address_1' => $order_info['payment_address_1'],
'address_2' => $order_info['payment_address_2'],
'city' => $order_info['payment_city'],
'postcode' => $order_info['payment_postcode'],
'zone' => $order_info['payment_zone'],
'zone_code' => $order_info['payment_zone_code'],
'country' => $order_info['payment_country']
);
$data['payment_address'] = str_replace(array("\r\n", "\r", "\n"), '<br />', preg_replace(array("/\s\s+/", "/\r\r+/", "/\n\n+/"), '<br />', trim(str_replace($find, $replace, $format))));
if ($order_info['shipping_address_format']) {
$format = $order_info['shipping_address_format'];
} else {
$format = '{firstname} {lastname}' . "\n" . '{company}' . "\n" . '{address_1}' . "\n" . '{address_2}' . "\n" . '{city} {postcode}' . "\n" . '{zone}' . "\n" . '{country}';
}
$find = array(
'{firstname}',
'{lastname}',
'{company}',
'{address_1}',
'{address_2}',
'{city}',
'{postcode}',
'{zone}',
'{zone_code}',
'{country}'
);
$replace = array(
'firstname' => $order_info['shipping_firstname'],
'lastname' => $order_info['shipping_lastname'],
'company' => $order_info['shipping_company'],
'address_1' => $order_info['shipping_address_1'],
'address_2' => $order_info['shipping_address_2'],
'city' => $order_info['shipping_city'],
'postcode' => $order_info['shipping_postcode'],
'zone' => $order_info['shipping_zone'],
'zone_code' => $order_info['shipping_zone_code'],
'country' => $order_info['shipping_country']
);
$data['shipping_address'] = str_replace(array("\r\n", "\r", "\n"), '<br />', preg_replace(array("/\s\s+/", "/\r\r+/", "/\n\n+/"), '<br />', trim(str_replace($find, $replace, $format))));
Then, in your catalog/view/theme/<your_theme>/template/mail/order_alert.twig file,
you can use:
Code: Select all
{% if payment_address %}
{{ payment_address }}
{% endif %}
{% if shipping_address %}
{{ shipping_address }}
{% endif %}
where you see fit.
Re: Adding Customer Name to Admin Alert mail for new order
Posted: Thu Mar 29, 2018 12:25 am
by Ninjas-Everywhere!
straightlight wrote: ↑Tue Mar 27, 2018 6:37 am
In catalog/controller/mail/order.php file,
find:
Code: Select all
$data['comment'] = strip_tags($order_info['comment']);
add above:
Code: Select all
if ($order_info['payment_address_format']) {
$format = $order_info['payment_address_format'];
} else {
$format = '{firstname} {lastname}' . "\n" . '{company}' . "\n" . '{address_1}' . "\n" . '{address_2}' . "\n" . '{city} {postcode}' . "\n" . '{zone}' . "\n" . '{country}';
}
$find = array(
'{firstname}',
'{lastname}',
'{company}',
'{address_1}',
'{address_2}',
'{city}',
'{postcode}',
'{zone}',
'{zone_code}',
'{country}'
);
$replace = array(
'firstname' => $order_info['payment_firstname'],
'lastname' => $order_info['payment_lastname'],
'company' => $order_info['payment_company'],
'address_1' => $order_info['payment_address_1'],
'address_2' => $order_info['payment_address_2'],
'city' => $order_info['payment_city'],
'postcode' => $order_info['payment_postcode'],
'zone' => $order_info['payment_zone'],
'zone_code' => $order_info['payment_zone_code'],
'country' => $order_info['payment_country']
);
$data['payment_address'] = str_replace(array("\r\n", "\r", "\n"), '<br />', preg_replace(array("/\s\s+/", "/\r\r+/", "/\n\n+/"), '<br />', trim(str_replace($find, $replace, $format))));
if ($order_info['shipping_address_format']) {
$format = $order_info['shipping_address_format'];
} else {
$format = '{firstname} {lastname}' . "\n" . '{company}' . "\n" . '{address_1}' . "\n" . '{address_2}' . "\n" . '{city} {postcode}' . "\n" . '{zone}' . "\n" . '{country}';
}
$find = array(
'{firstname}',
'{lastname}',
'{company}',
'{address_1}',
'{address_2}',
'{city}',
'{postcode}',
'{zone}',
'{zone_code}',
'{country}'
);
$replace = array(
'firstname' => $order_info['shipping_firstname'],
'lastname' => $order_info['shipping_lastname'],
'company' => $order_info['shipping_company'],
'address_1' => $order_info['shipping_address_1'],
'address_2' => $order_info['shipping_address_2'],
'city' => $order_info['shipping_city'],
'postcode' => $order_info['shipping_postcode'],
'zone' => $order_info['shipping_zone'],
'zone_code' => $order_info['shipping_zone_code'],
'country' => $order_info['shipping_country']
);
$data['shipping_address'] = str_replace(array("\r\n", "\r", "\n"), '<br />', preg_replace(array("/\s\s+/", "/\r\r+/", "/\n\n+/"), '<br />', trim(str_replace($find, $replace, $format))));
Then, in your catalog/view/theme/<your_theme>/template/mail/order_alert.twig file,
you can use:
Code: Select all
{% if payment_address %}
{{ payment_address }}
{% endif %}
{% if shipping_address %}
{{ shipping_address }}
{% endif %}
where you see fit.
Thank you for the code. I added the
Code: Select all
if ($order_info['payment_address_format']) {
$format = $order_info['payment_address_format'];
...<remaining code posted>
directly above the
Code: Select all
$data['comment'] = strip_tags($order_info['comment']);
There was no change in the Admin email. The space where there would be the name and email address, there is still a blank area. This is what I have added to the order_alert.twig,
Code: Select all
{{ text_received }}
{{ text_firstname }} {{ firstname }}
{{ text_lastname }} {{ lastname }}
{{ text_email }} {{ email }}
{{ text_order_id }} {{ order_id }}
{{ text_date_added }} {{ date_added }}
{{ text_order_status }} {{ order_status }}
{{ text_product }}
...
Any other adjustments or did I insert the code in the wrong order (find x code, then insert new code in front of x code)?
Re: Adding Customer Name to Admin Alert mail for new order
Posted: Thu Mar 29, 2018 1:27 am
by straightlight
This is what you need to add in your target TWIG file as indicated on the above's instructions:
Code: Select all
{% if payment_address %}
{{ payment_address }}
{% endif %}
{% if shipping_address %}
{{ shipping_address }}
{% endif %}
Re: Adding Customer Name to Admin Alert mail for new order
Posted: Thu Mar 29, 2018 5:52 am
by Ninjas-Everywhere!
Thank you. I put the code in the .twig file. I misread that part of the instructions thinking that was optional. Now, I need someone to order something to see how it comes across.
Re: Adding Customer Name to Admin Alert mail for new order
Posted: Thu Mar 29, 2018 6:09 am
by straightlight
You can also test an order with free checkout by setting the site on temporary maintenance.
Re: Adding Customer Name to Admin Alert mail for new order
Posted: Fri Apr 06, 2018 6:10 am
by Ninjas-Everywhere!
I'm getting the information in the email, but it's all run together in terms of formatting as well as there being code <br /> inserted in the line with the other data. Here's an example of exactly how it's coming through,
"You have received an order.
Jack Boettra<br />1972<br />3410 Fawstenme Ln<br />Round Rock, Texas 78681<br />United States
Order ID: 63
Date Added: 04/04/2018
Order Status: Processing
Products
1x (Member x1) 1 Month - Unlimited ((Member x1) 1 Month - Unlimited) $125.00
Totals
Sub-Total: $125.00
Total: $125.00"
Any ideas?
Re: Adding Customer Name to Admin Alert mail for new order
Posted: Fri Apr 06, 2018 6:31 am
by straightlight
If you want to use the first name and last name only, from the controller, you could also add:
Code: Select all
$data['firstname'] = strip_tags(html_entity_decode($order_info['shipping_firstname'], ENT_QUOTES, 'UTF-8'));
$data['lastname'] = strip_tags(html_entity_decode($order_info['shipping_lastname'], ENT_QUOTES, 'UTF'8'));
Then, in the same TWIG file, you could use:
Code: Select all
{% if firstname and lastname %}
{{ firstname }} {{ lastname }}
{% endif %}
Re: Adding Customer Name to Admin Alert mail for new order
Posted: Fri Apr 06, 2018 8:21 am
by Ninjas-Everywhere!
Both of those pieces of code go in the TWIG file?
Re: Adding Customer Name to Admin Alert mail for new order
Posted: Fri Apr 06, 2018 10:17 am
by straightlight
Not what's been said on my previous post. One goes to the controller and the 2nd one goes to the TWIG file.
Re: Adding Customer Name to Admin Alert mail for new order
Posted: Fri May 04, 2018 10:06 am
by wshiwsbrding
@straightlight I have posted the code
Code: Select all
if ($order_info['payment_address_format']) {
$format = $order_info['payment_address_format'];
} else {
$format = '{firstname} {lastname}' . "\n" . '{company}' . "\n" . '{address_1}' . "\n" . '{address_2}' . "\n" . '{city} {postcode}' . "\n" . '{zone}' . "\n" . '{country}';
}
$find = array(...
in my order.php file above
Code: Select all
$data['comment'] = strip_tags($order_info['comment']);
Then I added
Code: Select all
{% if payment_address %}
{{ payment_address }}
{% endif %}
{% if shipping_address %}
{{ shipping_address }}
{% endif %}
to my order_alert.twig file.
But when I do a test purchase I get nothing new in the alert email. I have gone through your instructions step by step multiple times to see if I missed anything but I got nothing. I swear I did exactly what you instructed.
What else might I be missing?
Thanks!
p.s. I have opencart 3.0.2.0