Develop an OpenCart vqmod to alter the confirm eMail
Hello
[updated 21. dec 2011, see code change]
I had the need to alter the OpenCart (1.5.1.3) order confirmation eMail to include some legal text (german Impressum (company contact) and Wiederrufsbelehrung, Stichwort Abmahnung) and to remove the display of the IP.
To be able to watch and debug my code additions, I had to setup a development system for the OpenCart shop instance:
Development system Windows 7 (x64)
opencart 1.5.1.3 + german language extension and vqmod
- Installed xampp17
- copied online opencart dir to xampp/htdocs/opencart
- edited opencart/config.php and opencart/admin/config.php
- did a mysql export of the online database (phpMyAdmin)
- imported mysql backup to development xampp mysql
- installed netbeans
- installed xdebug (xampp/php/php.ini changes and xampp/php/ext/xdebug_php)
- removed opencart/vqmod xml files that alter the opencart URLs
installed smtp4dev by copying the exe to xampp/smtp4devstarted smtp4dev
changed to papercut as smtp4dev is not UTF-8 compatible
- downloaded and installed papercut (http://papercut.codeplex.com/releases/view/41337)
- started papercut
- start xampp apache and mysql
- check if localhost ports (80, 25, 9000) are in use (tcpmon by sysinternals), possibly kill or disable processes or change port for xdebug
- check if browser can load http://localhost/opencart
- start netbeans, create new project and import existing php code
- check, if you can debug: start a debug of the netbeans php project, debugger will stop at first line
- change netbeans setting PHP-debug stop at first line
- place a break point in confirm function of opencart\catalog\model\checkout\order.php
- test if debugger breaks when you place an order and press (Confirm Order)
- possibly disable opencart SEO friendly URL setting
- if URLs are changed (ie using vqmod beop_all_clean_urls_v1.0.4.xml), netbeans will have problems following the code (breakpoints will never been hit)
+ready to debug+ - Enable Charge-on-delivery payment option, testing with a paypal payment in plcae does not make sense
The Confirm eMail will be generated by the confirm function inside
catalog/model/checkout/order.php
The file
catalog/language/_xy_/checkout/checkout.php
has the fixed texts for the confirm eMail
catalog\view\_xy_\default\template\checkout\checkout.tpl
In order.php you can see the construction of the the main html order confirmation email template variables and also those for the plain text version. The final template can then be found in catalog/view/theme/default/mail/order_confirm.tpl.
First I did a direct change of order.php for testing
As everything works as desired, I moved the added lines into a vqmod file which I already had ready for IP replacing.
I will use two external files which hold the fixed text for the legal information:
opencart\catalog\view\theme\wiederruf_bottom.html
opencart\catalog\view\theme\wiederruf_top.html
Here is my direct test code addition inside opencart\catalog\model\checkout\order.php just before
if ($comment && $notify) {
in the confirm function:
[codesyntax lang=”php”]
//replace footer text by impressum if german session if($this->session->data['language'] == 'de'){ //$language->data[code]=="de" // files in opencart/catalog/view/theme/' //read top html part of wiederrufsbelehrung $wiederruf_top=""; $wiederruf_top = file_get_contents($filename= DIR_TEMPLATE . 'wiederruf_top.html'); //read bottom html part of wiederrufsbelehrung $wiederruf_bottom=""; $wiederruf_bottom = file_get_contents(DIR_TEMPLATE . 'wiederruf_bottom.html'); //build the company address $firmen_addresse = $this->config->get('config_name') . '<br>' . $this->config->get('config_owner') . '<br>' . str_replace(array("\r\n", "\r", "\n"), '<br />', $this->config->get('config_address')) . '<br>' . $this->config->get('config_email') . '<br>' . $this->config->get('config_telephone') . '<br>' . $this->config->get('config_fax') . '<br>'; //combile top part, company address and bottom part in a new string $wiederruf = $wiederruf_top . $firmen_addresse . $wiederruf_bottom; //build the impressum (company address and contact info) $impressum = 'Impressum:<br>' . $firmen_addresse; $this->config->get('config_name') . '<br>' . $this->config->get('config_owner') . '<br>' . str_replace(array("\r\n", "\r", "\n"), '<br />', $this->config->get('config_address')) . '<br>' . $this->config->get('config_email') . '<br>' . $this->config->get('config_telephone') . '<br>' . $this->config->get('config_fax') . '<br>'; //$this->config->get('config_title') . '<br>'; //replace footer in confirm eMail by our impressum and wiederrufsbelehrung $template->data['text_footer'] = $impressum . $wiederruf; }
[/codesyntax]
For hiding the IP address in the order confirmation eMail I had to change several lines, please see the full vqmod file:
[codesyntax lang=”php”]
<?xml version="1.0" encoding="UTF-8"?> <modification> <id>Replace IP and footer text in confirm eMail</id> <version>1.0.1</version> <vqmver>1.0.9</vqmver> <author>hjgode</author> <!-- <file name="catalog/view/theme/*/template/mail/order.tpl"> <operation> <search position="replace"> <![CDATA[<b><?php echo $text_ip; ?></b> <?php echo $ip; ?><br />]]> </search> </operation> <operation> <add> <![CDATA[<?php echo '-'; ?><br />]]> </add> </operation> </file> --><file name="catalog/model/checkout/order.php"> <operation> <search position="replace"> <![CDATA[$template->data['text_ip'] = $language->get('text_new_ip');]]> </search> <add> <![CDATA[$template->data['text_ip'] =''; ]]> </add> </operation> <operation> <search position="replace"> <![CDATA[$template->data['ip'] = $order_info['ip'];]]> </search> <add> <![CDATA[$template->data['ip'] = ''; ]]> </add> </operation> <operation> <search position="before"> <![CDATA[if ($comment && $notify) {]]> </search> <add> <![CDATA[ //replace footer text by impressum if german session if($this->session->data['language'] == 'de'){ //$language->data[code]=="de" // files in opencart/catalog/view/theme/' //read top html part of wiederrufsbelehrung $wiederruf_top=""; $wiederruf_top = file_get_contents($filename= DIR_TEMPLATE . 'wiederruf_top.html'); //read bottom html part of wiederrufsbelehrung $wiederruf_bottom=""; $wiederruf_bottom = file_get_contents(DIR_TEMPLATE . 'wiederruf_bottom.html'); //build the company address $firmen_addresse = $this->config->get('config_name') . '<br>' . $this->config->get('config_owner') . '<br>' . str_replace(array("\r\n", "\r", "\n"), '<br />', $this->config->get('config_address')) . '<br>' . $this->config->get('config_email') . '<br>' . $this->config->get('config_telephone') . '<br>' . $this->config->get('config_fax') . '<br>'; //combile top part, company address and bottom part in a new string $wiederruf = $wiederruf_top . $firmen_addresse . $wiederruf_bottom; //build the impressum (company address and contact info) $impressum = 'Impressum:<br>' . $firmen_addresse; $this->config->get('config_name') . '<br>' . $this->config->get('config_owner') . '<br>' . str_replace(array("\r\n", "\r", "\n"), '<br />', $this->config->get('config_address')) . '<br>' . $this->config->get('config_email') . '<br>' . $this->config->get('config_telephone') . '<br>' . $this->config->get('config_fax') . '<br>'; //$this->config->get('config_title') . '<br>'; //replace footer in confirm eMail by our impressum and wiederrufsbelehrung $template->data['text_footer'] = $impressum . $wiederruf; }]]> </add> </operation> </file> </modification>
[/codesyntax]
For this vqmod you need the two htm files wiederruf_bottom.html and wiederruf_top.html in place.
The legal address is read from the opencart store settings using $this->config->get(‘foo’). The names for foo are found in the opencart database itself inside the setting table. The address is then merged in between the top and bottom legal text. The top and bottom legal text files are just html files.
[Download not found]updated vqmod file: [Download not found]