Examples for 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; in 4.0.x, model triggers and event handling differ.
The ocmod.zip archive is uploaded via the ExtensionsAdditional functionality: a module, a payment or shipping method, a feed, or a theme. They are managed in "Extensions → Extensions." More in the glossary → → Installer page, but its internal structure differs between versions. In OpenCart 3.0, files go into the upload/ folder with the same directory structure as the store, and the modification is described in install.xml. In OpenCart 4.1, the root of the archive becomes the extension folder extension/{код}/, the module description is in install.json, and modifications are in the ocmod/ folder. Below we cover both schemes, the Installer rules, and the pitfalls when updating.
What should the archive look like for OpenCart 3.0?
Installer 3.0 accepts only a file whose name ends in .ocmod.zip, otherwise it shows "Invalid file type". After upload, the archive is extracted to a temporary directory, and two things are processed:
- the
upload/folder: its contents are moved into the store directories, meaningupload/admin/goes to admin,upload/catalog/to the catalog,upload/system/tosystem, andupload/image/toimage; - the
install.xmlfile in the archive root: a OCMOD modification is created from it.
Example
mymodule.ocmod.zip
├── install.xml
└── upload/
├── admin/
│ ├── controller/extension/module/mymodule.php
│ ├── language/en-gb/extension/module/mymodule.php
│ ├── model/extension/module/mymodule.php
│ └── view/template/extension/module/mymodule.twig
└── catalog/
├── controller/extension/module/mymodule.php
└── view/theme/default/template/extension/module/mymodule.twig
You can't write files just anywhere. Installer 3.0 has a whitelist of directories and stops with the error "The directory … is not allowed to be written to" if a file falls outside them. The list includes:
admin/,controller/ extension/ admin/,model/ extension/ admin/,view/ template/ extension/ admin/language/, as well asadmin/view/image/,admin/,view/ javascript/ admin/;view/ stylesheet/ catalog/,controller/ extension/ catalog/,model/ extension/ catalog/language/,catalog/,view/ javascript/ catalog/view/theme/;system/config/,system/library/,image/catalog/.
So you cannot ship your own controllerCode that receives a request and prepares data. More in the glossary → in catalog/ via the archive. If you need to change a core file, do it through a modification in install.xml or through an event, not by replacing the file. In 3.0, files are moved with overwriting: if a file with that path already exists, it will be replaced.
What should the archive look like for OpenCart 4.1?
In 4.1, extensions live separately from the core, and the archive reflects this directly. The file name without .ocmod.zip becomes the extension code and folder name: mymodule.ocmod.zip will be extracted to extension/mymodule/. Routes, namespaces, and permissions depend on this name, so the archive cannot be renamed after release.
Example
mymodule.ocmod.zip
├── install.json
├── admin/
│ ├── controller/module/mymodule.php
│ ├── language/en-gb/module/mymodule.php
│ ├── model/module/mymodule.php
│ └── view/template/module/mymodule.twig
├── catalog/
│ ├── controller/module/mymodule.php
│ └── view/template/module/mymodule.twig
├── system/
│ └── library/mymodule/client.php
└── ocmod/
└── mymodule.ocmod.xml
When extracting, Installer 4.1 follows these rules:
- everything from the archive root goes to
extension/{код}/; - paths starting with
image/are copied to the store's sharedimage/directory; - paths starting with
system/storage/are copied to the storage directory, for example for ComposerA PHP dependency manager. Some 4.1 extensions use it. More in the glossary → libraries; - the
ocmod/folder is not copied: a separate step reads the*.ocmod.xmlfiles from it and writes them to the database as modifications; - items with
..in the path are skipped.
Installer records every file and directory it creates in the database. So uninstalling in Installer removes exactly what was installed from the archive, nothing extra. Files are extracted in batches of 200, so large archives install too, just over several requests.

What should go into install.json and install.xml?
These files describe the extension for the administrator and for the database. Their fields only partly match.
| Field | install.xml (3.0) | install.json (4.1) |
|---|---|---|
| Name | <name> | name |
| Code | <code>, required and unique among modifications | taken from the archive name; the field in JSON does not affect the code |
| Version | <version> | version |
| Author | <author> | author |
| Link | <link> | link |
| Description | none | description |
Example
{
"name": "My Module",
"version": "1.0.0",
"author": "Studio Name",
"link": "https://example.com/mymodule",
"description": "Блок рекомендацій для сторінки товару"
}
OpenCart 4.1: without install.json in the archive root, Installer rejects the upload with the message "Could not find install.json!". Missing keys are filled with empty strings, so valid JSON with name and version is the minimum.
OpenCart 3.0: install.xml is not required, because a module without modifications doesn't need it. If the file is present but there is no <code>, installation stops with "Unique code is required for modification XML!", and a code already used by another modification gives "Modification … is already being used!". Build the code from your brand prefix and the module name.
In 4.1 there can be several modifications, one ocmod/ file for each. The modification code is taken from the file name. How to write the OCMOD instructions themselves (<file>, <search>, <add>) is described in detail in the blog article OCMOD in OpenCart: code changes without modifying system files.

After installing an archive with a modification, the administrator must click Refresh (Оновити) on the Extensions → Modifications page (in 3.0 it is Extensions → Modifications, in 4.1 Extensions → Modification; route marketplace/ in both branches), otherwise the changes won't be applied. Mention this in the module's instructions.
How do you build the archive without surprises?
Build the archive with a script, not manually from a file manager. This way every release has the same structure, and nothing extra gets into it.
Example
# OpenCart 4.1: пакуємо вміст каталогу, а не сам каталог
cd build/mymodule
zip -r ../../mymodule.ocmod.zip . -x "*.DS_Store" -x "__MACOSX/*" -x ".git/*"
# OpenCart 3.0: у корені архіву лише upload/ і install.xml
cd build/oc3
zip -r ../../mymodule-oc3.ocmod.zip upload install.xml -x "*.DS_Store"
Before publishing, check the contents with the unzip -l mymodule.ocmod.zip command. The top level must contain install.json, admin/, catalog/ in 4.1, or upload/ and install.xml in 3.0.
- File name. In 4.1 it becomes the code, so use only lowercase Latin letters, digits, and underscores, with no version in the name. An archive named
mymodule-1.2.ocmod.zipwill create the folderextension/, and the next version becomes a separate extension. Moreover, the core builds a PHP namespace from the folder name: it removes underscores but keeps hyphens and dots, and such a namespace becomes invalid.mymodule-1.2/ - Service files.
.git,node_modules, tests, SCSS sources: all of this will end up on the client's server. Exclude them via-x. - Encoding. Save PHP files as UTF-8 without BOM. A BOM before
<?phpcauses "headers already sent" and breaks JSON responses. - Two archives for two versions. The structures are incompatible, so build separate archives for 3.0 and 4.1 and label them in the file name on the marketplace, not inside the extension code.
How do you release module updates?
Most questions come up with updates, because Installer behaves oppositely in the two versions.
OpenCart 3.0: re-uploading the archive overwrites the files, so an update is essentially a new upload. But files you removed from the new version will stay on the server and must be deleted separately. A modification with the same <code> is considered taken, so before updating, delete the old modification on the Modifications page.
OpenCart 4.1: Installer does not overwrite existing files, and installation stops if the extension/{код}/ directory already exists. You also can't delete files through Installer while at least one extension from that folder is installed in Extensions → Extensions: Installer will answer that they must be removed first. So the standard admin update path is:
- In Extensions → Extensions, uninstall each type the module ships. This runs
uninstall(), and the core deletes the settings fromsetting. - In Extensions → Installer, uninstall the installed version. The files, directories, and modifications of this archive are removed according to the recorded list. Then, on the same page, delete the archive itself from the list: otherwise it will remain in
storage/, and uploading a new file with the same name will fail with "already exists".marketplace/ - Upload the new archive with the same name, install it, and install the module again in Extensions → Extensions.
- Click Refresh in Modifications if the module has OCMOD, and save the settings again.
This path loses settings, so account for it when designing the module. Keep data that must survive the update (history, bindings, logs) in your own tables and don't delete them in uninstall(). The alternative is updating over the files via SFTP or deployment: settings remain, but Installer won't know about the new files. In both cases, add new columns and events via migrations, as described in the article install and uninstall of a module.
Checklist before publishing the archive
- The archive is named
{код}.ocmod.zip; in 4.1 without a version and without hyphens in the code. - The top level of the archive matches the version:
upload/andinstall.xmlfor 3.0, the extension folder contents andinstall.jsonfor 4.1. - In 3.0, all files are in directories from the Installer whitelist.
install.xmlhas a unique<code>, andinstall.jsonis valid JSON (check viaphp -r 'var_dump(json_decode(file_get_contents("install.json")));').- The archive is installed on a clean store of the correct version, the module is installed with the Install button, settings are saved, and the storefrontWhat the customer sees: the home page, categories, product page, and cart. More in the glossary → is checked.
- The module is uninstalled and installed again: no errors about existing files or modification codes.
The general structure of files that go into the archive is described in the article anatomy of an extension in 3.0 and 4.1. A complete working example is in the material how to create a module from scratch.
Summary
- OpenCart 3.0: files go into
upload/with a directory whitelist, the modification is ininstall.xmlwith a required unique<code>, and on re-upload files are overwritten. - OpenCart 4.1: the archive root becomes
extension/,{назва архіву}/ install.jsonis required, modifications are inocmod/*.ocmod.xml, and existing files are not overwritten. - In 4.1 the archive name is the extension code: stable, in Latin letters, without a version.
- In 4.1, updating means uninstalling in Installer and installing anew, and database changes require migrations.
Other topics about extensions are collected on the page creating extensions for OpenCart.