# OpenCart Module Structure: Files in 3.0 and 4.1 Extensions

> Which files make up an OpenCart 3.0 and 4.1 extension, where they go, how the core finds them, installs them, and stores their settings. A map for developers.

Джерело: https://opencartcode.com/en/wiki/dev-extensions/opencart-module-structure
OpenCart: 3.0, 4.1
Оновлено: 2026-11-24

The structure of an OpenCart module depends on the version. In 3.0, extension files are spread across the shared core directories `admin/` and `catalog/`, in subfolders `extension/{тип}/`. In 4.1, each extension lives in its own folder `extension/{код_розширення}/`, with the same split into admin and catalog. Below we cover which files are needed, how the core finds them, what happens during installation, and where settings are stored. That way you can read other people's modules and write your own without guesswork.

Examples are for OpenCart 4.1; in 4.0.x, model triggers and event handling differ.

## What parts make up an OpenCart extension?

An extension in OpenCart is a regular set of MVC-L files: a [controller](https://opencartcode.com/en/wiki/glossary/e-commerce-glossary#controller), a model, a template, and a [language file](https://opencartcode.com/en/wiki/glossary/e-commerce-glossary#language-file). Two things set it apart from "just code." The first is the extension type. The second is a record in the `extension` table, without which the core does not consider the extension installed. How these layers relate to each other is described in detail in the article on MVC-L, see [how the controller, model, template, and language are connected](https://opencartcode.com/en/wiki/dev-mvc/opencart-mvc). Here we focus on what is specific to [extensions](https://opencartcode.com/en/wiki/glossary/e-commerce-glossary#extensions).

A typical module has two halves:

- **Admin side**: a controller with a settings form and `install()`/`uninstall()` methods, a form template, a language file, and, if needed, a model (for example, to create custom tables).
- **[Storefront](https://opencartcode.com/en/wiki/glossary/e-commerce-glossary#storefront) side** (catalog): a controller that renders a block on a page or handles payment or shipping, a model for data queries, a template, and a language file.

The type determines where the core "hooks" the extension in. A module is displayed in layout positions. A [payment method](https://opencartcode.com/en/wiki/glossary/e-commerce-glossary#payment-method) is called during checkout. A total takes part in calculating the order amount. A feed exports data outward. Each type is described in detail in a separate material in this section. For the anatomy, one thing matters: the type is the name of a subdirectory, and the core uses it to build paths to files.

In the admin, the list of extensions of a particular type is generated by a separate "dispatcher" controller. In **OpenCart 3.0** these are files such as `admin/controller/extension/extension/module.php`, `payment.php`, `shipping.php`. In **OpenCart 4.1** they are `admin/controller/extension/module.php`, `payment.php`, and so on. These dispatchers scan the directories, show the "Install"/"Uninstall" buttons, and write to the `extension` table.

## What extension types exist in 3.0 and 4.1?

The set of types in the two branches is almost the same, but not identical. The list below covers the main types, collected from the dispatchers of the clean core. The service dispatcher `marketplace.php` in 4.1 is not included in the table.

| Type | OpenCart 3.0 | OpenCart 4.1 | Purpose |
| --- | --- | --- | --- |
| module | yes | yes | Blocks in page layouts |
| payment | yes | yes | Payment methods |
| shipping | yes | yes | Shipping methods |
| total | yes | yes | Order total lines |
| feed | yes | yes | Feeds and exports |
| report | yes | yes | Admin reports |
| analytics, captcha, currency, dashboard, fraud, theme | yes | yes | Analytics, captcha, currency rates, dashboard widgets, anti-fraud, themes |
| advertise, menu, promotion | yes | no | Service types in 3.0 |
| language | no | yes | Language packs as extensions |
| other | no | yes | Extensions without a storefront role (service, integrations) |

The `other` type in 4.1 is especially handy. If a module shows nothing on the storefront but, say, only syncs stock with an accounting system or hooks into events, there's no need to disguise it as a module. In 3.0, such extensions were usually built as a module with no output, and they sat "empty" in the module list.

Extensions → Extensions, filter by type „Modules“: list of modules with install and edit buttons · OpenCart 4.1.0.4

## Where are the module files located in OpenCart 3.0?

In 3.0, an extension has no directory of its own. Its files are embedded into the core tree, and the file name (the extension code) is repeated in each of the branches. For a module with the code `price_badge`, the structure is as follows:

```bash
admin/controller/extension/module/price_badge.php
admin/model/extension/module/price_badge.php
admin/language/en-gb/extension/module/price_badge.php
admin/language/uk-ua/extension/module/price_badge.php
admin/view/template/extension/module/price_badge.twig

catalog/controller/extension/module/price_badge.php
catalog/model/extension/module/price_badge.php
catalog/language/en-gb/extension/module/price_badge.php
catalog/view/theme/default/template/extension/module/price_badge.twig
```

Key rules for 3.0:

- **The route matches the path.** The admin controller is opened via `route=extension/module/price_badge`, and the class is named after the path in CamelCase: `ControllerExtensionModulePriceBadge`. The model is `ModelExtensionModulePriceBadge`, and in the controller it is available as `$this->model_extension_module_price_badge`.
- **The storefront template lives in the theme.** The core looks for it in the active theme's directory, and if the file is not there, it takes it from `default`. So put the template in `default`, and a custom theme can override it if needed.
- **Extension code = file name.** This is what gets written to the `extension` table (columns `type` and `code`) and becomes the prefix for settings.

The main drawback of this scheme is that module files are mixed with core files and files from other extensions. You can remove a module "cleanly" only by using a list of paths. The 3.0 installer records this list in the `extension_path` table, but only for modules installed through it. If you copied files over FTP, you have to keep the list yourself. It's handy to keep the 3.0 directory map at hand: [OpenCart directory map for developers](https://opencartcode.com/en/wiki/dev-architecture/opencart-file-structure).

## How did the structure change in OpenCart 4.1?

In 4.1, each extension is a separate "package" in the site root: `extension/{код_пакета}/`. Inside, the familiar pair `admin/` and `catalog/` is repeated, but without the intermediate `extension/`. The core ships its standard extensions the same way, in the `extension/opencart/` package, and that is the best model to follow. Our example package `mystore` with the same module would look like this:

```bash
extension/mystore/
├── install.json
├── admin/
│   ├── controller/module/price_badge.php
│   ├── model/module/price_badge.php
│   ├── language/en-gb/module/price_badge.php
│   ├── language/uk-ua/module/price_badge.php
│   └── view/template/module/price_badge.twig
├── catalog/
│   ├── controller/module/price_badge.php
│   ├── model/module/price_badge.php
│   ├── language/en-gb/module/price_badge.php
│   └── view/template/module/price_badge.twig
└── system/            # за потреби: власні бібліотеки, config
```

What has fundamentally changed:

- **The route contains the package code:** `extension/mystore/module/price_badge`. Language files and templates are loaded the same way, for example `$this->load->language('extension/mystore/module/price_badge')`.
- **Namespaces instead of class prefixes.** The admin controller is the class `PriceBadge` in the namespace `Opencart\Admin\Controller\Extension\Mystore\Module`, extending `\Opencart\System\Engine\Controller`. The storefront one is in `Opencart\Catalog\Controller\Extension\Mystore\Module`.
- **Methods in the route.** In 4.1 the method is separated by a dot: `extension/mystore/module/price_badge.save`. The settings form is usually submitted via an AJAX request to `save` and receives a JSON response.
- **Storefront templates are not tied to the theme.** They live in the package under `catalog/view/template/`, not in `catalog/view/theme/…`.

One package can contain several extensions of different types. For example, `extension/mystore/` can hold `module/price_badge.php`, `payment/…`, and `other/…`. Each is installed separately in its own section of the admin, while the files all sit together. How the core parses the route and finds classes is explained in the article on [routing with route= in 3.0 and 4.1](https://opencartcode.com/en/wiki/dev-mvc/opencart-route).

> The package code (the folder name in `extension/`) must match the namespace segment. The folder `mystore` means `…\Extension\Mystore\…`. A mismatch in case or underscores is the most common cause of the "Could not load controller" error in 4.1. Use lowercase Latin letters without hyphens for the package code.

## What happens when a module is installed?

Installation is a two-stage process, and in both versions the stages are easy to confuse. The first stage delivers the files to the server. The second registers the extension in the database and runs its `install()`.

```mermaid
flowchart TD
A["Upload .ocmod.zip in Installer"] --> B{"Version?"}
B -->|"3.0"| C["Files from upload/ are copied to the root"]
B -->|"4.1"| D["Package is extracted to extension/code/"]
C --> E["Record in extension_install and extension_path"]
D --> E
E --> F["Extensions → type → Install"]
F --> G["Row in the extension table"]
G --> H["access/modify permissions for the admin group"]
H --> I["Controller install() is called"]
I --> J["Edit and save settings"]
```

1. **Uploading the package.** "Extensions → Installer." In 3.0, the archive contents are copied straight into the site tree. In 4.1, the archive first appears in the list of uploaded files, and the files are extracted to `extension/{код}/` after clicking "Install" in the same list.
2. **Registering the extension.** Next, "Extensions → Extensions," selecting the type in the filter, and the "Install" button next to the required row. The core adds a row to the `extension` table. In 3.0 this is the pair `type`/`code`. In 4.1 an extra column `extension` with the package code is added.
3. **Permissions.** The current user's group is granted access and modify rights on the extension's route. Other admin groups must have these rights added manually in "System → Users → User Groups." Details are in the article on [checking module access permissions](https://opencartcode.com/en/wiki/dev-mvc/opencart-module-access-permissions).
4. **Your `install()`.** Here the module creates tables, registers events, and writes default settings.

Installer: uploaded package and install button · OpenCart 4.1.0.4

Removal runs in reverse order: the "Uninstall" button deletes the row from `extension` and calls `uninstall()`. The files remain in place; only uninstalling the package in the installer removes them. This leads to a typical trap: the module was "removed," but its events or OCMOD modifications still work, because `uninstall()` does not clean them up.

## Where are module settings and instances stored?

Extensions have two places for storing configuration, and the choice between them depends on the type.

**The `setting` table** is for "single" settings. Keys are grouped by code with a type prefix: `module_price_badge_status`, `payment_liqpay_…`, `shipping_flat_cost`. This prefix is not cosmetic. Type dispatchers and storefront mechanisms (for example, selecting the available payment methods) read the status and sort order precisely from keys like `{тип}_{код}_status` and `{тип}_{код}_sort_order`. If you name the field differently, the extension is formally installed, but the core will consider it disabled. Saving goes through the `setting/setting` model with a group equal to the prefix. For details, see the article in the setting model section.

**The `module` table** is only for the module type with multiple instances (such as the standard "Featured" or "Slideshow"). Each instance is a row with `module_id`, a name, a code, and a JSON field `setting`. Layout positions are bound to a specific instance. The instance code in 3.0 looks like `price_badge`, and in 4.1 it also includes the package: `mystore.price_badge`. If one set of parameters is enough for the module, don't overcomplicate things: `setting` is simpler and doesn't require working with layouts.

> The core loads values from `setting` into `$this->config` at the start of the request, so the storefront doesn't need to read the database every time. `$this->config->get('module_price_badge_status')` is enough. How config loading works is explained in the article [about file-based configs and database settings](https://opencartcode.com/en/wiki/dev-architecture/opencart-config-php).

## How do you package a module for each version?

Both versions accept an `.ocmod.zip` archive, but the contents differ. A 3.0 package cannot simply be repacked for 4.1.

| Item | OpenCart 3.0 | OpenCart 4.1 |
| --- | --- | --- |
| Archive root | a folder `upload/` mirroring the site tree | directly `admin/`, `catalog/`, `system/` of the package |
| Metadata | optional; `install.xml` is an OCMOD modification | `install.json` with name, version, author, link |
| Package code | none, only codes of individual extensions | archive name without `.ocmod.zip` = folder in `extension/` |
| Modifying core files | OCMOD via `install.xml` | mainly events; OCMOD is limited |

A minimal `install.json` for 4.1 looks roughly like this (an example, not a core file; use `extension/opencart/install.json` in your copy of OpenCart as the reference):

```js
{
  "name": "Price Badge",
  "version": "1.0.0",
  "author": "My Store Dev",
  "link": "https://example.com"
}
```

Checklist before packing:

- the archive is named after the package code: `mystore.ocmod.zip`, not `mystore-v1.0-final.zip`;
- in 4.1 there is no extra nested folder at the first level of the archive;
- there are language files for every store language. In 3.0, `en-gb` loads first and serves as the fallback. In 4.1 there is no fallback `en-gb`, so the language file must exist for every store language (`en-gb`, `uk-ua`) with a complete set of keys;
- `uninstall()` removes events, settings, and, if agreed with the client, tables;
- in 3.0, verify that the files do not overwrite same-named files from other modules.

The details of `install.xml`, compatibility, and common installer errors are covered in a separate article in the packaging section. For how to build a whole module step by step, see the [step-by-step example of a first module for 3.0 and 4.1](https://opencartcode.com/en/wiki/dev-extensions/how-to-create-an-opencart-module).

## Summary

- In **OpenCart 3.0**, a module is scattered across `admin/…/extension/{тип}/` and `catalog/…/extension/{тип}/`. Classes are named after their path, and the storefront template lives in the theme.
- In **OpenCart 4.1**, a module lives in `extension/{пакет}/`. The route contains the package code, classes have namespaces, and methods are called via a dot in the route.
- Installation is two-stage: first the files (installer), then registration in the `extension` table, permissions, and your `install()`.
- Settings are stored in `setting` with the `{тип}_{код}_` prefix. Module instances for layouts are stored in the `module` table.
- 3.0 and 4.1 packages are incompatible in archive structure. For 4.1, a correct `install.json` and the package code in the archive name are mandatory.

Next, it's worth understanding how the extension controller interacts with the Loader and Registry: see [how load->controller, model, view, and language work](https://opencartcode.com/en/wiki/dev-architecture/opencart-loader). The remaining topics (types, settings form, install/uninstall, custom tables) are gathered on the section page [Creating OpenCart Modules](https://opencartcode.com/en/wiki/dev-extensions).

## FAQ

**Can I put a 4.1 module just in admin/controller/extension, as in 3.0?**

No. In 4.1, the type handlers look for extensions only in the extension/{package}/ folders, so a file in the old location won't appear in the list. It can't be installed the standard way.

**Why doesn't the module appear in Extensions → Modules after I copy its files over FTP?**

Most often the controller file is in the wrong folder or has a different name than the core expects. In 4.1, also check that the package folder name matches the namespace. The installer isn't required here, but the path must be exact.

**Do I need to delete the module files after clicking "Uninstall" in the extensions list?**

That button only removes the registration and calls uninstall(); the files stay. To remove them, delete the package in Extension Installer or manually by the list of paths.

**How many extensions can one 4.1 package contain?**

There is no limit: one extension/{пакет}/ folder can contain modules, payment methods, shipping methods, and service extensions such as other. Each of them is installed separately in its own section of the admin panel.

**Do I need Ukrainian localization if the store admin is in Ukrainian?**

Yes. Without the uk-ua language folder in the module's language files, the core will fall back to English strings, and the settings form will be mixed. Keep the en-gb reference files as a fallback.
