The ocmod-module for Opencart 2.x can have three modification files install.php, install.sql and install.xml.

We will provide examples of such files so that you can create your own modules.

install.xml - ocmod-modification file, which specifies what and where to insert into existing files

install.php - scripts to be executed during module installation

install.sql - database queries to be executed during module installation.


An example of formatting the install.xml file:

<?xml version="1.0" encoding="utf-8"?>
<modification>
    <name>Module name</name> <code>Unique-ID-module</code>
    <version>1.0</version>
    <author>Author</author>
    <link>https://opencart2x.com</link>
    <file path="catalog/controller/common/home.php">
        <operation>
            <search trim="true|false" index="0|1|2.."><![CDATA[
                $data['column_left'] = $this->load->controller('common/column_left');
            ]]></search>
            <add position="replace|before|after" trim="true|false" offset="2"><![CDATA[
                $custom_var = 'This variable is inserted through OCMOD';
            ]]></add>
        </operation>
    </file>  
</modification>
An example of formatting the install.php file:

<?php
// Adding rights to manage a module
$this->load->model('user/user_group');
$this->model_user_user_group->addPermission($this->user->getGroupId(), 'access', 'module/news');
$this->model_user_user_group->addPermission($this->user->getGroupId(), 'modify', 'module/news');

// Checking for the presence and adding additional columns to the database table
$this->db->query("ALTER TABLE `" . DB_PREFIX . "modification` CHANGE `xml` `xml` MEDIUMTEXT NOT NULL");
$chk = $this->db->query("SHOW COLUMNS FROM `" . DB_PREFIX . "modification` WHERE `field` = 'date_modified'");
if (!$chk->num_rows) {
    $this->db->query("ALTER TABLE `" . DB_PREFIX . "modification` ADD COLUMN `date_modified` datetime NOT NULL");
    $this->db->query("UPDATE `" . DB_PREFIX . "modification` SET `date_modified` = `date_added` WHERE `date_modified` = '0000-00-00 00:00:00'");
}?>
An example of formatting the install.sql file:

/* Creating a table in the database */
CREATE TABLE IF NOT EXISTS `oc_news_description` (
    `news_description_id` int(11) NOT NULL AUTO_INCREMENT,
    `news_id` int(11) NOT NULL,
    `language_id` int(11) NOT NULL,
    `title` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
    `description` text CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
    `short_description` text CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
    PRIMARY KEY (`news_description_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;

/* Adding new rows to a table */
INSERT INTO `oc_url_alias` (`query`, `keyword`) VALUES
('information/news', 'news'),
('information/posts', 'posts');