- Windows CE Programming - https://www.hjgode.de/wp -

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

changed to papercut as smtp4dev is not UTF-8 compatible

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]

&nbsp;