Develop an OpenCart vqmod to alter the confirm eMail

Print This Post Print This Post

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/smtp4dev
  • started 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]

&nbsp;

 

7 Comments

  1. Nasko says:

    This works for me very nice.
    I am not very sure why did you made 2 Html for the wiederuf? You could place the hole text in one file.
    I am sure there is a reason for it, but I am too blind to see it right now ?
    However thx for the vqmod and the nice solution !

  2. admin says:

    Hallo Nasko

    wenn Du Dir den code etwas näher ansiehst, wirst Du bemerken, dass ich die Shop-Daten (Adresse) zwischen den beiden html Dateien einmische. Sieht schöner aus, aber man hätte die Adresse natürlcih auch am Anfang oder Ende ausgeben können:

    //build the company address
    $firmen_addresse =
    $this->config->get(‘config_name’) . ‘
    ‘ .
    $this->config->get(‘config_owner’) . ‘
    ‘ .
    str_replace(array(“\r\n”, “\r”, “\n”), ‘
    ‘, $this->config->get(‘config_address’)) . ‘
    ‘ .
    $this->config->get(‘config_email’) . ‘
    ‘ .
    $this->config->get(‘config_telephone’) . ‘
    ‘ .
    $this->config->get(‘config_fax’) . ‘
    ‘;
    //combile top part, company address and bottom part in a new string
    $wiederruf = $wiederruf_top . $firmen_addresse . $wiederruf_bottom;

    Gruss

    Josef

  3. Nasko says:

    Hallo Josef,
    ja ich habe das schon bemerkt als ich die top und bottom html geänder habe. Dann hatte ich die Adresse nähmlich doppelt 🙂
    Vielen Dank nochmal, das war eine große Hilfe.

  4. Karola says:

    Hallo Josef,

    ich arbeite gerade an einem Open Cart Shop (in Englisch). Dieser wird bald online gehen und mache mir auch Sorgen zwecks der rechtlichen Folgen (Anzeige der IP-Adresse, kein Impressum,…). Leider bin ich nicht sehr gut in PHP und ich verstehe leider nicht, in welche Datei ich den Code von ihrer vqmod kopieren soll. Meine englischen Sprachkenntnisse sind leider auch nicht mehr perfekt. Gäbe es eine Möglichkeit, mir kurz per Mail zu erklären, wie ich vorgehen muss?! Damit würden sie mir einen großen Gefallen tun!

    Vielen Dank für ihre tolle Programmierarbeit!

    Mit lieben Grüßen,
    Karola

  5. admin says:

    Hallo Karola

    da Du PHP nicht mchtig bist, empfehle ich Dir dringend, eine für deutsches Recht optimierte OpenCart Variante zu installieren: OCIE von OsWorx [http://osworx.net/de/home]

    gruss

    josef

  6. Gabe says:

    Lieber Admin,

    ist dieser vqmod noch mit open cart 1.5.3.1 kompatibel? Wie kann ich in 1.5.3.1 Wiederruf und Impressum hinzufügen?

  7. admin says:

    Tut mir leid, aber ich habe zur Zeit kein OpenCart mehr laufen. Probier doch einfach aus, ob die vqmods noch laufen. Das ist ja das schöne an den VQmods, man kann Sie einfach ein- oder ausschalten, indem man die MOD-Datei einkopiert oder entfernt.

    Gruss

    Josef

Leave a Reply