In this article, we will discuss a very popular patching system called VQMOD. VQMOD started being used with OpenCart a few years back and now it’s everywhere. Extensions are not developed anymore without the use of VQMOD.
What is VQMOD?
“vQmod™” (aka Virtual Quick Mod) is an override system designed to avoid having to change core files. The concept is quite simple… Instead of making changes to the core files directly, the changes are created as xml search/replace script files. These script files are parsed during page load as each “source” core file is loaded with the “include” or “require” php functions. The source is then patched with the script file changes, and saved to a temp file. That temp file is then substituted for the original during execution. The original source file is never altered. This results in a “virtual” change to the core during execution without any actual modification to the core files. VQMOD is also easily installed along with .XML patch files. If you are curious about where the .XML files are kept all you have to do is upload/install VQMOD then direct your FTP to here: /vqmod/xml
Creating your own .VQMOD
There is an open source VQ MOD generator available for download that we recommend you use if doing a large project, but for this article we’re just going to use a basic note-pad which can be found in your computer’s menu. If you have never written XML before, you will have little trouble catching on because it really is a simple syntax with simple rules. The full set of vqmod options and features can be found HERE.
So let’s get on with it. We’re going to write a basic REPLACE script. The script will locate a line or block of code within the .PHP and replace it with whatever we specify. Don’t forget, we are PATCHING CODE IN. You have to be real smart in terms of your SEARCH for the code. You don’t want to use a line of code that is often changed in the core. Use something unique…and normal untouched that way the patch won’t be affected for future updates.
Open up a note pad document and go ahead and save it as test.xml
Now we have our empty XML file. Paste the following code in the xml file:
<?xml version="1.0" encoding="UTF-8"?> <modification> <id>Replace 123 with ABC</id> <version>1.0.0</version> <vqmver>1.0.9</vqmver> <author>arvixe</author> <file name="relative/path/myfile.php"> <operation> <search position="replace"><![CDATA[ $var = '123'; ]]></search> <add><![CDATA[ $var = 'ABC'; ]]></add> </operation> </file> </modification>
Let’s break down this code. The first line to pay attention to is the file. <file name=”relative/path/myfile.php”> This is a relative path that points towards the PHP file that you are patching. It must be correct or the patch will not work at all.
Now we turn our attention to the search line: <search position=”replace”><![CDATA[
$var = '123';
The system will specify the replace command and then will look for the line of code $var = ‘123’; and when it finds it, it will then replace the code with the patched code which is this line:
$var = 'ABC';
All you have to do now is save your test.xml and upload it to the XML FOLDER on the server. Go to the page that file is related to and see the magic.
Pointers for position
- Required attribute “position” set to before|after|replace|top|bottom|all|ibefore|iafter.
- replace will replace the data in the search tag with the data in the add tag. (default)
- before will insert the add data before the search data
- after will insert the add data after the search data
- top will insert the add data at the top of the file. The search data is ignored.
- bottom will insert the add data at the bottom of the file. The search data is ignored.
- all will completely replace all the code in the file with the add data. The search data is ignored. Deprecated as of 2.4.0
- ibefore will insert the code before the search inline instead of the line before
- iafter will insert the code after the search inline instead of the line before