OpenCart – Developing a VQMOD Extension

Perhaps you’ve been interested in trying your hand at developing an actual extension for Opencart but just are not sure where to start? This article will go through the basics of doing just that. We will study the famous patching system called VQMOD and how easy it is to develop in this environment. I would venture to say that the majority if not all Opencart extensions for sale in the Opencart store are VQMOD REQUIRED which means that you will need to install the patching system in your store before you actually can deploy the extension.

WHAT IS VQMOD?

Vqmod is a patching system that allows you to NOT overwrite core files within the Opencart framework. It uses XML to do the dirty work. The official definition:

“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.

You can download it here: http://code.google.com/p/vqmod

Setting up your testing environment

Before we begin to develop the extension I recommend that you upload the latest version of Opencart to a SUB FOLDER on your main server. This will allow you to test your extensions without bothering your real store. Alternatively you can develop locally on WAMP or MAMP. This article will not guide you in setting that up, we assume that you already know how. Once you have uploaded your store, connect to the database and run the install. Now you have a testing environment. Download the VQMOD and upload it to your sub folder. Run the install at  www.yourdomain.com/subfolder/vqmod/install. You should receive a notice that it is installed! Now we can begin development.

Below is a basic layout of a vqMod .xml patch file. It’s what you will want to start with so open up your favorite code editor or notepad and paste this code:

<modification>
<id>Test Extension</id>
<version>1.4.x and 1.5.x</version>
<vqmver>1.0.8</vqmver>
<author>Your Name / Company Name</author>
<file name=”catalog/view/theme/*/template/product.product.tpl”>
<operation>
<search position=”after”><![CDATA[

]]>
</search>
<add><![CDATA[
]]></add>

</operation>
</file>

</modification>

Now save it as test.xml

For this demo we are going to patch in a string (word) into the product details page. In the code above you see the following line:

<file name=”catalog/view/theme/*/template/product.product.tpl”>

This locates the product.tpl and the wildcard(*) will choose the current template/theme if any are installed. The next step, now that we have defined the target file is to locate a line of code we can paste our NEW CODE near. You can replace an entire line of code or patch it before or after the line of code. We are to basically fill in this block which searches the entire file for the line:

<search position=”after”><![CDATA[THE LINE OF CODE]]>
</search>

Now that we have found our line of code we need only to add the NEW line of code that will display the string on the product details page. We do that like this:

<add><![CDATA[ <?php echo "THIS IS MY STRING OF CODE";?>]]></add>

That’s it.  Save the xml file and upload it to vqmod/xml/. Go to your testing environment and click on any product and you should see the string show up. If you do not then you have not done this correctly and need to go back to see where the error might be. XML is very touchy and you must make sure your code is clean and concise. Here is what the full file should look like:

<modification>
<id>Test Extension</id>
<version>1.4.x and 1.5.x</version>
<vqmver>1.0.8</vqmver>
<author>Your Name / Company Name</author>
<file name=”catalog/view/theme/*/template/product.product.tpl”>
<operation>
<search position=”after”><![CDATA[THE LINE OF CODE]]>
</search>
<add><![CDATA[ <?php echo "THIS IS MY STRING OF CODE";?>]]></add>

</operation>
</file>

</modification>

Just follow these rules and you can patch anything within that file. The key to making the best vqmod is to make sure that the code you are searching for is universal with as many different version of Opencart as possible. If not, then you will run into issues from version to version.

Looking for quality OpenCart Hosting? Look no further than Arvixe Web Hosting!

Tags: , , , | Posted under OpenCart | RSS 2.0

Author Spotlight

Joe Stenhouse

Joe Stenhouse

I am a web application developer that specializes in PHP, JAVASCRIPT, MYSQL, HTML, and CSS. We manifest exciting potentials within the world wide web through means of innovation.

2 Comments on OpenCart – Developing a VQMOD Extension

  1. Jon says:

    Hi Joe..how d i contact you?

Leave a Reply

Your email address will not be published. Required fields are marked *


× 7 = 21

You may use these HTML tags and attributes: <a href="" title="" rel=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>