Last active
July 13, 2020 21:26
-
-
Save damiencarbery/2a61bee06d38ba23d5047fbfe08beaef to your computer and use it in GitHub Desktop.
Add customer address to OpenCart order alert email - Include the customer name and address for a more complete order email. https://www.damiencarbery.com/2020/07/add-customer-address-to-opencart-order-alert-email/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<modification | |
xmlns="https://github.com/vqmod/vqmod" | |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
xsi:schemaLocation="https://github.com/vqmod/vqmod https://raw.githubusercontent.com/vqmod/vqmod/master/vqmod.xsd"> | |
> | |
<id>Add customer name and address to email alert</id> | |
<version>1.0</version> | |
<vqmver>2.X</vqmver> | |
<author>Damien Carbery</author> | |
<!-- From: https://forum.opencart.com/viewtopic.php?t=201256#p711523 --> | |
<file name="catalog/controller/mail/order.php"> | |
<operation info="Add label"> | |
<search position="after"><![CDATA[ | |
$data['text_date_added'] = $this->language->get('text_date_added'); | |
]]></search> | |
<add><![CDATA[ | |
$data['text_fullname'] = $this->language->get('text_fullname'); | |
]]></add> | |
</operation> | |
<operation info="Add customer info to data sent to template"> | |
<search position="after"><![CDATA[ | |
$data['date_added'] = date($this->language->get('date_format_short'), strtotime($order_info['date_added'])); | |
]]></search> | |
<add><![CDATA[ | |
$data['name'] = $order_info['firstname']." ".$order_info['lastname']; | |
]]></add> | |
</operation> | |
<operation info="Set up customer address info"> | |
<search position="after"><![CDATA[ | |
$data['comment'] = strip_tags($order_info['comment']); | |
]]></search> | |
<add><![CDATA[ | |
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( '<br />', "\n", 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( '<br />', "\n", preg_replace(array("/\s\s+/", "/\r\r+/", "/\n\n+/"), '<br />', trim(str_replace($find, $replace, $format)))); | |
]]></add> | |
</operation> </file> | |
<file name="catalog/language/en-gb/mail/order_alert.php"> | |
<operation info="Add label"> | |
<search position="after"><![CDATA[ | |
$_['text_date_added'] = 'Date Added:'; | |
]]></search> | |
<add><![CDATA[ | |
$_['text_fullname'] = 'Name:'; | |
$_['text_billing_address'] = 'Billing Address:'; | |
$_['text_shipping_address'] = 'Shipping Address:'; | |
]]></add> | |
</operation> | |
</file> | |
<file name="catalog/view/theme/luxury/template/mail/order_alert.twig"> | |
<!--<operation info="Add name to template"> | |
<search position="after"><![CDATA[ | |
{{ text_date_added }} {{ date_added }} | |
]]></search> | |
<add><![CDATA[ | |
{{ text_fullname }} {{ name }} | |
]]></add> | |
</operation>--> | |
<operation info="Add name and address to template"> | |
<search position="before"><![CDATA[ | |
{{ text_product }} | |
]]></search> | |
<add><![CDATA[ | |
{% if payment_address %} | |
{{ text_billing_address }} | |
{{ payment_address }} | |
{% endif %} | |
{% if shipping_address %} | |
{{ text_shipping_address }} | |
{{ shipping_address }} | |
{% endif %} | |
]]></add> | |
</operation> | |
</file> | |
</modification> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment