Search code examples
phpopencartopencart-modulevqmodocmod

OpenCart OCMOD and VQMOD Modification Systems


I am new to OpenCart OCMOD and VQMOD systems. So I need some help. My questions are.

  1. It is said that OCMOD is OC2+ default system. It is also said we have to write our OCMOD ourselves. What does it mean? If OCMOD comes with OC2+. Then Why we need to write it ourselves? If OCMOD is deault part of OC+2. Then where can we find it in OC 3.0.2.0?

  2. How to use OCMOD to make changes in OpenCart without affecting core files?

  3. How to remove changes already made without installing OCMOD or VQMOD in OpenCart core files after installing new OCMOD.zip or OCMOD.xml and VQMOD.zip or VQMOD.xml without removing the effect of that changes.

  4. How to restore changes made in OpenCart in upgraded version using OCMOD or VQMOD?

  5. If new OCMOD or VQMOD is installed, does it removes all the changes already made in core files of OpenCart?


Solution

  • First time we were talking about general OCMOD and VQMOD logic. This time I'll describe the OCMOD working experience (VQMOD works mostly the same and is outdated, so I will omit it). OCMOD itself is an engine (built in OpenCart since 2.X). We need to place in this engine an instructions to make it works. The instruction files are in XML format and has specific names, like my_file.ocmod.xml, where .ocmod.xml ending is required.

    Here is an example of OCMOD file

    <?xml version="1.0" encoding="utf-8"?>
    <modification>
      <name>My OCMOD file</name>
      <code>my-ocmod</code>
      <version>1.0</version>
      <author>Me</author>
      <link>http://mywebsite.com</link>
    
      <file path="catalog/view/theme/default/template/common/header.twig">
        <operation>
          <search><![CDATA[<div id="top-links" class="nav pull-right">]]></search>
          <add position="before"><![CDATA[
            <div>Add Something</div>
          ]]></add>
        </operation>
      </file>  
      
      <file path="catalog/controller/common/header.php">
        <operation>
          <search><![CDATA[$data['name'] = $this->config->get('config_name');]]></search>
          <add position="replace"><![CDATA[
            $data['name'] = $this->config->get('config_name') . $this->document->getDescription();
          ]]></add>
        </operation>
      </file>  
    
    </modification>
    

    Here we have 2 instructions (operations) in 2 different file (we can implement multiple operations in a single file as well). In operation we are searching for a line of the code in original core file and add before/after or replace it with tho code in add tag. Here is OCMOD file documentation, might help with .ocmod.xml file building.

    When you have .ocmod.xml file - you need to install it. There are two different ways to do it:

    1. Insert file in /system folder and clear cache.
    2. In admin panel in Extension - Installer install your .ocmod.xml file and clear cache. This case is better to manage. You can find your OCMOD files in Extension - Extension. These are not files, but a database entry. To edit them after installation you may need OCMOD editor.

    In some cases you could see .ocmod.zip archive with install.xml and upload folder. It could be the module with OCMOD file and additional files, compiled in a single installer.

    ABOUT CHANGES

    Now, when we have a file with operations .ocmod.xml installed and cache is cleared - system creates core files copies and keep them in /system/storage/modifications/.... If we take the code from the example - you will find file /system/storage/modifications/catalog/view/theme/default/template/common/header.twig with implemented changes from .ocmod.xml.

    So that's it. OCMOD works as simple as this. As soon as you have installed any .ocmod.xml file - this file is keeps in OpenCart, and implement operations after every cache cleaning. You made changes in .ocmod.xml file - clear the cache. Installed new .ocmod.xml - clear the cache. Removed some old .ocmod.xml - clear the cache.

    After upgrading OpenCart version - OCMOD files may stay untouched. But if they are gone - just install them again (you should save them before somewhere).

    P.S. Different .ocmod.xml files can affect on the same core file. This is absolutely OK.