How to create vQmod file

In this article I will tell you how to create your own vQmod files. What is vQmod and why you need it you can read here.

Now suppose that you need to change some core files of your OpenCart. Because OpenCart doesn't have a good hook system as in the Drupal or Events (Events appeared since OpenCart 2.0.0.0 are underdeveloped and doesn't cover all engine yet) you have 2 ways to do this:

1. Open the core file and change it like you want. In the other engines, it is very bad practice to do this, but in the OpenCart it is practically normal because often it is the only way to make these changes.

2. Use vQmod for this. 

For create vQmod file you need any simple text editor (better with the code highlighter). Create a file with "xml" extension, for example my_first_vqmod.xml. Here is a listing of this file:

<?xml version="1.0" encoding="UTF-8"?>
 
<modification>
 
  <!-- Modification id -->
  <id>My first fix</id>
 
  <!-- Modification version -->
  <version>1.0.0</version>
 
  <!-- vQmod version for this modification -->
  <vqmver>2.3.0</vqmver>
 
  <!-- The author of the modification -->
  <author><a href="mailto:sv2109@gmail.com">sv2109@gmail.com</a></author>
 
  <comment><![CDATA[
    Leave some comment here
  ]]></comment>
 
  <!-- File to change. Such files can be several in one xml file -->
  <file name="admin/model/catalog/product.php">
 
    <!-- Operation for one change. Such operations can be several for this file -->
    <operation>
 
      <!-- Exact place where you need to add your change. You can set position position for it (in our case "after") and the code between <![CDATA[...]]> It means that "after" this code you will add some your code. If you want to add your code before you need to set "before" position. You can also "replace" some code with your code. Important! The code to change must to be exactly like in the file. One space or tab more or less between words and vQmod will find nothing. -->
      <search position="after"><![CDATA[$product_id = $this->db->getLastId();]]></search>
 
      <!-- Here we write our code what we want to add after, before, or instead of the existing code -->
      <add><![CDATA[
$this->load->model('module/my_module');
$this->model_module_my_module->action($product_id);
      ]]></add>
    </operation>
  </file>
</modification>

That is all. In short. 


In addition to usual positions "before", "after", "replace" you can use the regular expression as well and insert your code with offset. You can also use "*" symbol in the file path instead of exact path, for example "admin/model/catalog/*.php" means change all ".php" files in the  "admin/model/catalog/" folder.
But I do not recommend to do it. Because it can create many conflicts in the future. Do this only if it is the only way to do it.  
 

 

Добавить комментарий

CAPTCHA
Защита от спама
Target Image