Skip to main contentSkip to footer

Opencart OCMOD documentation

Rupak Nepali
Share:
Opencart OCMOD documentation

Hi me Rupak Nepali again, today I am going to cover OpenCart OCMOD documentation and tutorial for the developer and show how to start coding in OCMOD to change the files and extend functionalities. How are OCMOD code flows described here?

OCMOD is a system that allows store owners to be able to modify their store by uploading a compressed file that contains XML, SQL, and PHP files. If an OCMOD is developed correctly it can modify how a user’s OpenCart stores without changing any of the core files, This means that if a modification is removed none of the original OpenCart files need to be restored or fixed.
OCMOD is based on Qphoria’s VqMOD system.

Opencart 4 OCMOD

Opencart 3 install uninstall method in OCMOD

module install database

The detailed documentation of OCMOD for the developer is at  https://github.com/opencart/opencart/wiki/Modification-System  

Both have the same functionalities, you have to install VqMOD in OpenCart 3 and OpenCart 2 but OCMOD is by default in OpenCart 3 and you can easily upload from the admin sections.

The main feature differences for the programmers are:

Both OCMOD and VqMOD have:
Replace, Before, After, Regex, Offset, Limit, ignore if, error
Missing in OCMOD which had in VqMOD are:
Attributes top, bottom, before, after

The file and folder structure to create OCMOD in OpenCart 3 are like below:

file structure of OCMOD
  • The File structure of OCMOD compressed zip ocmod.zip files may look like below but can differ as per the functionalities of the module
  • For an OCMOD file to be uploaded the file extension must be either .ocmod.zip or .ocmod.xml.

File Structure

  • Example file structure for OCMOD compressed files.
  • upload
  • install.sql 
  • install.php 
  • install.xml

upload

  • All files under this directory will be uploaded to the directory of your OpenCart installation.

install.sql

  • Add any create, drop, insert, and update SQL queries here. Make sure each query ends with the following;

install.php

  • If the modification requires any custom PHP code.

install.xml

Demo to install the OCMOD

show module link at left menu

Let’s see XML example of the module install.xml 

<?xml version="1.0" encoding="utf-8"?>
<modification>
<name>Show Module Link At Left Menu</name>
<version>3.0</version>
<author>Rupak Nepali</author>
<link>https://webocreation.com</link>
<code>webocreation_show_module_link_at_left_menu</code>
<description>Show module link at left menu</description>
<file path="admin/controller/common/column_left.php">
<operation>
<search><![CDATA[ if ($this->user->hasPermission('access', 'marketplace/extension')) { ]]></search>
<add position="after"><![CDATA[
$marketplace[] = array(
'name'   => "Modules",
'href' => $this->url->link('marketplace/extension&type=module', 'user_token=' . $this->session->data['user_token'], true),
'children' => array()
);
]]></add>
</operation>
</file>
</modification>

Tags

You can set multiple file locations by spiting up the file locations using commas. The modification system uses the PHP function glob.

Direct file path.

<file path="admin/controller/common/column_left.php">

Using braces allows for selecting multiple files and not having to repeat the code operation multiple times.

<file path="system/engine/action.php|system/engine/loader.php|system/library/config.php|system/library/language.php">

also allows braces

<file path="system/{engine,library}/{action,loader,config,language}*.php">

Please note that all file paths must start with either admin, catalog or system. You can also use a wildcard to search for multiple directories and files.

Search

Search code

Allowed Attributes

  • trim=”(true|false)”
  • regex=”(true|false)”
  • index=”(number)”

Example:

<?xml version="1.0" encoding="utf-8"?>
<modification>
    <name>Modification Default</name>
    <version>1.0</version>
    <author>OpenCart Ltd</author>
    <link>http://www.opencart.com</link>
    <code>webocreation_mod_1</code>
    <file path="catalog/controller/common/home.php">
        <operation>
            <search trim="true|false" index="1"><![CDATA[
            $data['column_left'] = $this->load->controller('common/column_left');
            ]]></search>
            <add position="replace" offset="1"><![CDATA[
            test123
            ]]></add>
        </operation>
    </file>  
</modification>

Add

The code to replace the search with.

Allowed Attributes

  • trim=”(true|false)”
  • position=”(replace|before|after)”
  • offset=”(number)”

(note position can not be used if regex is set to true in the search attribute).

Example

<?xml version="1.0" encoding="utf-8"?>
<modification>
    <name>Modification Default</name>
    <version>1.0</version>
    <author>OpenCart Ltd</author>
    <code>webocreation_modification_default</code>
    <link>http://www.opencart.com</link>
    <file path="catalog/controller/common/home.php">
        <operation>
            <search trim="true|false"><![CDATA[
            $data['column_left'] = $this->load->controller('common/column_left');
            ]]></search>
            <add position="replace|before|after" trim="true|false" offset="2"><![CDATA[
            test123
            ]]></add>
        </operation>
    </file>  
</modification>
Regex

Allowed Attributes

  • limit=”(number)”

Example:

<?xml version="1.0" encoding="utf-8"?>
<modification>
    <name>Regex Example</name>
    <version>1.0</version>
    <author>OpenCart Ltd</author>
    <code>webocreation_regexexample</code>
    <link>http://www.opencart.com</link>
    <file path="system/{engine,library}/{action,loader,config,language}*.php">
        <operation>
            <search regex="true" limit="1"><![CDATA[
            ~(require|include)(_once)?\(([^)]+)~
            ]]></search>
            <add><![CDATA[
            $1$2(modification($3)
            ]]></add>
        </operation>
    </file>
</modification>

If you use a regex you can not use attributes position, trim or offset as these are handled by the regular expression code you write. The limit attribute is still available.

If, for example, you want to change the 3rd ‘foo’ to ‘bar’ on the following line:

lorem ifoopsum foo lor foor ipsum foo dolor foo
^1      ^2      ^3         ^4        ^5

Run:

s/\(.\{-}\zsfoo\)\{3}/bar/

Result:

lorem ifoopsum foo lor barr ipsum foo dolor foo
^1      ^2      ^3=bar     ^4        ^5

Let us know if you have any more ideas.

Comments

Join the conversation and share your thoughts

Leave a Comment

Your comment will be reviewed before publishing.

Be the first to comment on this post!

Innovation

Let's Make Something Amazing Together

We always provide our best creative ideas at the highest level. Tell us about your project and we will make it work.

InnovateBringing innovative solutions to complex problems
AutomateStreamlining processes through automation
DominateLeading the market with exceptional results
Build Smarter and Launch FasterEfficient development for rapid deployment