Opencart: Vqmod tutorial

Posted: November 25, 2013 by Sankar Vijayakumar in OpenCart, Php
Tags: , , , , , ,

Opencart

Vqmod stands for ‘Virtual Quick Mod‘, also known as ‘Virtual File modification System‘. It’s used to virtually alter any php or tpl file in OpenCart except the main index.php files. The changes are mentioned in xml files using search/add/replace tags and these files are parsed on page load. The original core files with the xml files’ code injected to it are then executed. The files with injected code can be viewed in vqmod/vqcache folder. Thus the core files are never touched and the opencart version upgrade can be done anytime.

Advantages of Vqmod:

  1. No need to edit the core files.
  2. Fallback to original sourcefiles in case of errors.
  3. Opencart version upgrade can be done easily by replacing core files.
  4. Website Performance never gets affected due to vqmod xml files.
How to install vqmod?

  1. Download vqmod files from here.
  2. Extract and copy the ‘vqmod’ folder to the root folder of our website.
  3. Make index.php and admin/index.php files writable (755 or 777).
  4. Call http://www.domain.com/vqmod/install install in browser. If everything is fine then we’ll see a success message. Otherwise check the permissions again.
  5. If step 4 fails, install vqmod manually by modifying index.php and admin/index.php as mentioned below:

    In index.php :-
    REPLACE:

    // Startup
    require_once(DIR_SYSTEM . 'startup.php');

    // Application Classes
    require_once(DIR_SYSTEM . 'library/customer.php');
    require_once(DIR_SYSTEM . 'library/currency.php');
    require_once(DIR_SYSTEM . 'library/tax.php');
    require_once(DIR_SYSTEM . 'library/weight.php');
    require_once(DIR_SYSTEM . 'library/length.php');
    require_once(DIR_SYSTEM . 'library/cart.php');
    require_once(DIR_SYSTEM . 'library/affiliate.php');

    WITH:

    // vQmod
    require_once('./vqmod/vqmod.php');
    VQMod::bootup();

    // VQMODDED Startup
    require_once(VQMod::modCheck(DIR_SYSTEM . 'startup.php'));

    // Application Classes
    require_once(VQMod::modCheck(DIR_SYSTEM . 'library/customer.php'));
    require_once(VQMod::modCheck(DIR_SYSTEM . 'library/currency.php'));
    require_once(VQMod::modCheck(DIR_SYSTEM . 'library/tax.php'));
    require_once(VQMod::modCheck(DIR_SYSTEM . 'library/weight.php'));
    require_once(VQMod::modCheck(DIR_SYSTEM . 'library/length.php'));
    require_once(VQMod::modCheck(DIR_SYSTEM . 'library/cart.php'));
    require_once(VQMod::modCheck(DIR_SYSTEM . 'library/affiliate.php'));

    In admin/index.php:
    REPLACE:

    // Startup
    require_once(DIR_SYSTEM . 'startup.php');

    // Application Classes
    require_once(DIR_SYSTEM . 'library/currency.php');
    require_once(DIR_SYSTEM . 'library/user.php'));
    require_once(DIR_SYSTEM . 'library/weight.php');
    require_once(DIR_SYSTEM . 'library/length.php');

    WITH:

    // vQmod
    require_once('../vqmod/vqmod.php');
    VQMod::bootup();

    // VQMODDED Startup
    require_once(VQMod::modCheck(DIR_SYSTEM . 'startup.php'));

    // Application Classes
    require_once(VQMod::modCheck(DIR_SYSTEM . 'library/currency.php'));
    require_once(VQMod::modCheck(DIR_SYSTEM . 'library/user.php'));
    require_once(VQMod::modCheck(DIR_SYSTEM . 'library/weight.php'));
    require_once(VQMod::modCheck(DIR_SYSTEM . 'library/length.php'));

    Once the above changes are made call our website address in browser. If everything is fine, then vqmod files can be found in “vqmod/vqcache” folder.

How to create vqmod xml files?

A typical vqmod xml looks like (Filename: qwerty.xml):

     <![CDATA[###Description/Title###]]>
     <![CDATA[###Our code version (Usually specifies plugin/extension version)###]]>
     <![CDATA[###Vqmod version###]]>
     <![CDATA[###Author's Name###]]>
     <file path="###Folder path###" name="###File name###" >
          <operation info="###Operation Info###" >
<search position="###Search/Replace filter###" regex="false" ><![CDATA[###Search Code###]]>
<![CDATA[
###Add Code###
]]>
          
          <operation info="###Operation Info###" >
<search position="###Search/Replace filter###" offset="0" ><![CDATA[###Search Code###]]>
<![CDATA[
###Add Code###
]]>
<![CDATA[
###Add Code###
]]>
          
     

Search/Replace filter:

  • replace: substitutes the code in search tag with the code in the add tag.
  • before : inserts the code in add tag before the code in search tag.
  • after: inserts the code in add tag after the code in search tag.
  • top: inserts the add tag code at the beginning of the file. The search tag data is ignored.
  • bottom: inserts the add tag code at the end of the file. The search tag data is ignored.
  • all: replaces the whole code in file with the add tag data. The search data is ignored.

Offset:
Integer value needed. When Adding, add before/after “Search” + this number of lines. When Replacing, replace “Search” + this number of lines.

  • offset = 3, search position = before : inserts the add tag code before the line, 3 lines above the searched line.
  • offset = 3, search position = after : inserts the add tag code after the line, 3 lines below the searched line.
  • offset = 3, search position = replace : replaces the code in search tag and an additional 3 lines, then add the code in add tag.
  • offset = 3, search position = top : inserts the add tag code 3 lines below the beginning of the file.
  • offset = 3, search position = bottom : inserts the add tag code 3 lines above the end of the file.

Index:
Single or Comma Separated Integers ONLY If the “Search” string is ‘echo’ and there are 5 echos in the file, but you only want to replace the 1st and 3rd, use Index: 1,3.

Ignore If:
Ignore this operation if the code/string in ignoreif tag is found in file.

Regex:
Default value: false. To use a regular expression for “Search”/”Ignore If”, set to ‘True’ inside those tags/

Sample vqmod xml file:

<![CDATA[My first vqmod xml]]>
<![CDATA[0.8]]>
<![CDATA[2.4]]>
<![CDATA[Sankar]]>
<file path="catalog/view/theme/default/template/common/" name="header.tpl">
<operation info="Add data after search button">
<search position="after" ><![CDATA[

]]>
<![CDATA[Hurray!! My Vqmod XML file worked!!!]]>

 
Opencart Vqmod xml file not working??

Things to try:

  1. If you’re using opencart verion 2.* go for vqmod 2.5.1: https://github.com/vqmod/vqmod/releases
  2. Check whether vqmod is installed by calling https://domain.com/vqmod/install in browser. If not installed, then please scroll up and read the steps.
  3. Verify file name and path, also confirm that the code in search tag exists in the file mentioned.
  4. Check folder permissions. Make sure that vqmod/vqcache and vqmod/logs have 755 or 777 permission. If nothing works, then try 777 permission recursively for vqmod folder.
  5. Check the error logs in vqmod/logs.
  6. Check the installed vqmod version and the vqmod version given in xml file (), both need to be the same.
  7. Delete the files in vqmod/vqcache and check again. Also see whether vqmod copy of your file is generated or not.
  8. Move any vqmod xml file outside the vqmod folder and check. If everything works, move the xml back to the vqmod folder. I don’t know the reason, but it worked for me in some cases 🙂 !
  9. – put this line at the top of the XML to make it valid and more compatible.
  10. Try the VQMod Manager extension. It may help you!

Opencart Vqmod Extensions/Plugins

Now it’s time to import/create vqmod xml files. Happy Coding :lol:.

Reference links:
http://code.google.com/p/vqmod/downloads/list
http://code.google.com/p/vqmod/wiki/Install_OpenCart

Opencart Vqmod tutorial

Comments
  1. […] do the same without modifying the opencart core files, use vqmod : Vqmod tutorial. Happy Coding 😀 […]

    Like

  2. tttony says:

    Thanks for the tutorial!!

    But how to revert the changes? If I install my mod that makes some changes in some files, how to revert those changes to the original state?

    When I Uninstall my mod, the changes remains in the files

    Like

  3. tttony says:

    Alright!! I got it… just delete the xml file and you are done!!

    Silly me!!!

    Every change that you do in the xml file will be presented in the files .tpl or .php that you are editing

    Like

  4. sahil says:

    Thanks for this tutorial bless you

    Liked by 1 person

  5. Sourav says:

    Great tutorial. I was stuck for months as vqmod was not working. Then I went through this tutorial and now the bug is gone 🙂

    Liked by 1 person

  6. Good day very cool web site!! Guy .. Beautiful .. Amazing .. I will bookmark your web site and take the feeds also¡KI am happy to search out numerous helpful info right here within the publish, we’d like work out more strategies in this regard, thanks for sharing. . . . . .

    Like

How's it? Your comments and suggestions...