OCMOD in OpenCartA free open-source CMS for online stores, written in PHP with a MySQL/MariaDB database. Everything that is not part of the core is added through extensions. More in the glossary → 4.1 has not disappeared: 4.1 has a modifications page, the same search/add syntax, and a «Refresh» button. But modified copies are now stored in extension/ocmod/, and the core substitutes them through service events, so a modification only affects what is loaded through the Loader: controllers, models, templates, and some libraries. For new module code, the main tool in 4.1 is events, while OCMOD remains for targeted edits that events cannot handle.
Examples are for OpenCart 4.1; in 4.0.x, model triggers and event handling differ. The operation syntax is covered in detail in the article OCMOD syntax in OpenCart 3.0. In 4.1 it is the same; below are only the differences.
What remains of OCMOD in OpenCart 4.1?
The page «ExtensionsAdditional functionality: a module, a payment or shipping method, a feed, or a theme. They are managed in "Extensions → Extensions." More in the glossary → → Modifications» (Extensions → Modifications), route marketplace/, is present in 4.1. From it you can enable, disable, or delete a modification, click «Refresh» and «Clear», and view the ocmod.log log.
The logic for applying operations in the refresh() method almost literally repeats 3.0:
- a regular
searchsearches for text in a single line, case-insensitively, and is trimmed of whitespace by default; positionaccepts the valuesreplace,before, andafter, and an unknown value works asreplace;- the attributes
offset,index, andtrim, theregex="true"mode withlimit, theignoreifelement, and theerrorattributeA product characteristic that does not affect the price: material, weight, power. It is set in "Catalog → Attributes" and displayed on the "Specification" tab. More in the glossary → (skip,abort, or stopping the remaining operations in the block) behave the same way; - during the refresh, maintenance mode is turned on, and at the end the previous value is restored.
This means a modification written for 3.0 does not have to be rewritten syntactically in 4.1. What does have to be rewritten is what it searches for: paths, namespaces, method names, and template markup are different in 4.1.

What changed in 4.1 compared with 3.0?
| Item | OpenCart 3.0 | OpenCart 4.1 |
|---|---|---|
| File in the archive | install.xml in the root | ocmod/*.ocmod.xml files |
| Modification code | <code> element, required | file name without .ocmod.xml |
| Reinstalling with the same code | the old record is replaced | the new XML is skipped, the old one remains |
| Status after installation | enabled | disabled, must be enabled and refreshed |
| Where copies are written | storage/ | extension/ocmod/ |
Prefixes in path | catalog/, admin/, system/ | the same plus extension/ |
| How the core picks up the copy | modification() function in include | event/ events with priority 0 |
Service system/ | present | absent |
The most unpleasant difference in practice concerns reinstallation and status. The 4.1 installer (marketplace/) creates a modification record with status 0. After installing the module, nothing changes until the administrator enables the modification and clicks «Refresh». And if you update a module and a modification with that code already exists, the installer will not write the new XML: the old modification must be deleted manually before installing the new version.
The location where files are unpacked has also changed. The contents of a 4.1 archive are copied into extension/{код}/, not into the core directories, and the ocmod/ folder from the archive is not copied at all: its XML files go only into the database. For how to build such an archive with install.json, see the article ocmod.zip for 3.0 and 4.1.
Example
<?xml version="1.0" encoding="utf-8"?>
<modification>
<!-- архів my_badge.ocmod.zip, файл ocmod/my_badge.ocmod.xml -->
<name>My badge</name>
<description>Бейдж на картці товару</description>
<version>1.0.0</version>
<author>Developer</author>
<link>https://example.com</link>
<file path="catalog/view/template/product/product.twig">
<operation error="skip">
<search><![CDATA[<div id="product">]]></search>
<add position="before"><![CDATA[{% if my_badge %}<span class="badge">{{ my_badge }}</span>{% endif %}]]></add>
</operation>
</file>
</modification>
How does 4.1 substitute modified files, and what comes of it?
In 3.0, modified copies were included at the level of include. 4.1 has no such mechanism. Instead, service handlers with priority 0 are registered in system/ and admin.php: event/, .model, .view, and .library. Each checks whether a modified copy exists for the current route and, if so, adds the prefix extension/ocmod/ to the route. To do this, startup/extension registers the namespaces …\Extension\Ocmod and the template paths to extension/ocmod/.
This defines the limits of OCMOD in 4.1:
- Twig templates are picked up reliably: the handler checks for the file's presence in
extension/and switches the route. But, as in 3.0, a version of the template saved in «Design → Theme Editor» is substituted inocmod/ catalog/ view/ template/ $codewith priority 500 and overrides the OCMOD edit. - Controllers and models are picked up only when they are called through the Loader or as the main page route. The handler looks for the class in the namespace
Opencart\Catalog\Controller\Extension\Ocmod\…, but the copy keeps the originalnamespace, becauserefresh()does not change it. We verified this on the 4.1.0.4 autoloader: the class check returnsfalse, the route is not switched, but the autoloader has already included the copy's file, and it defines the class under the original name. So the modified version usually works, but it takes effect indirectly, and the behavior should be checked on a test store. - Startup controllers run directly, without events, so their modifications do not take effect.
system/engine/andsystem/files, and libraries created viaframework.php new(for examplecustomerandcurrencyon the storefrontWhat the customer sees: the home page, categories, product page, and cart. More in the glossary →) do not go through the Loader, and OCMOD has no effect on them. Libraries loaded via$this, such as the cart in->load ->library() startup/application, go through thelibrary/*/beforeevent.- Language files. The config refers to
event/, but themodification.language event/modificationcontrollerCode that receives a request and prepares data. More in the glossary → in release 4.1.0.4 has nolanguagemethod, so modified language files are not picked up. It is simpler to change texts through «Design → Language Editor» or via an event.
What to replace OCMOD with in a module for 4.1?
Most typical OCMOD 3.0 tasks are solved in 4.1 with events, and this code is more reliable: it does not depend on the exact text of a core line and does not break when a third-party theme is updated. Equivalents:
| Task | How it was done with OCMOD | How to do it in 4.1 |
|---|---|---|
| Pass a variable to the template | $data[...] line in the controller | view/…/before, add the key in $data |
| Insert a block into the markup | .twig edit | view/…/before with an $code edit, or OCMOD on the template |
| Change product or list data | SQL or array edit in the model | model/…/after, $output edit |
| React to an order status change | insertion into addOrderHistory() | catalog/ |
| Admin menu item | column_left.php edit | admin/, add the element in $data['menus'] |
| Change the HTML of a finished page | template edit | view/…/after, $output edit |
Example
// OpenCart 4.1, тригер admin/view/common/column_left/before
public function menu(string &$route, array &$data, string &$code, string &$output): void {
if (!$this->user->hasPermission('access', 'extension/my_module/module/my_module')) {
return;
}
$data['menus'][] = [
'id' => 'menu-my-module',
'icon' => 'fas fa-star',
'name' => 'My module',
'href' => $this->url->link('extension/my_module/module/my_module', 'user_token=' . $this->session->data['user_token']),
'children' => []
];
}
Check the menu element structure against admin/ of your version: the template expects the same keys that the controller generates. For details on template and model events, see the articles changing a template via view/*/before and intercepting models via model/*/after. Event registration in install() is described in the article addEvent and handler order.
When is OCMOD still justified in 4.1?
Events change input and output, but not the logic inside a method. OCMOD makes sense when you need to:
- change a condition in an SQL query of a core model that cannot be fixed either through
$argsor through$outputwithout a repeated query; - insert markup into a template when neither an
$codeedit nor a full template replacement suits you; - quickly fix a bug in a third-party extension's code from
extension/without changing its files (the prefixextension/inpathappeared precisely in 4.1).
The workflow in these cases:
- During development, place the XML in
system/with the name*.ocmod.xml: such files are applied on «Refresh» without installing an archive. - Click «Refresh» and check the log: the lines
MOD:,FILE:,LINE:, and the absence ofNOT FOUND. - Make sure the copy appeared in
extension/ocmod/…and that the change is visible on the site. - Move the XML into the
ocmod/of the module archive, and remove the file from{код}.ocmod.xml system/. - In the module instructions, state that after installation the modification must be enabled and «Refresh» clicked.
Also keep in mind that refresh() in 4.1 does not check for the presence of <search> and <add> in an operation or of the root <modification>: broken XML will stop the refresh with an error, and the store may remain in maintenance mode until you turn it off in the settings. For a broader view of why OCMOD exists and how it is used, see the blog: OCMOD in OpenCart: code edits without changing system files.
Summary
- OCMOD in 4.1 is alive: the same operation syntax, the «Extensions → Modifications» page, «Refresh», and
ocmod.log. - The archive contains
ocmod/; the code is taken from the file name, the modification is installed disabled, and an existing one with the same code is not overwritten.{код}.ocmod.xml - Copies are written to
extension/ocmod/and picked up by theevent/events, that is, only for what goes through the Loader; templates work reliably, language files in 4.1.0.4 do not.modification.* - For variables, model data, menus, and HTML in 4.1, use events; keep OCMOD for logic changes inside methods.
How to choose between events and OCMOD for a specific module, and how to find a modification that was not applied, is covered in separate articles in the section Events and OCMOD. The general mechanics of events are described in the article the OpenCart event system.