If, like me, you develop modules for OpenCart, a OpenCart 4 starter module can be really handy. You can’t deny that every new module starts with the same routine work: creating folders, copying templates, forming controllers and models for both admin and catalog, preparing language files and Twig templates, and then packaging all of this into a .ocmod.zip for installation.
Honestly, it’s tedious and time-consuming, especially if you need to start new projects frequently. As a developer, I often wondered how to automate this process and make it as convenient as possible. That’s how the starter template for creating an OpenCart 4 module came to life.
The idea was simple: create a tool that generates in a minute:
- a fully prepared module structure for OpenCart 4;
- correctly named controllers, models, and language files;
- Twig templates and associated CSS/JS files for the module;
- a ZIP archive for quick installation.
I designed it so that you only need to call the script with the new module name, for example:
php start.php my_module
And as a result, you immediately get a ready-to-use module with the correct structure and files. All placeholders %name% and %ModuleName% are automatically replaced, so the module can be tested and installed right away.
From that moment on, every new project becomes a snap: no more wasting hours on routine work — the script does everything for you. For me, as an OpenCart developer, it’s not just a time-saver — it’s a way to maintain quality standards and consistency across modules.
How does the OpenCart 4 starter module generator script work?
The first thing the script does is take the new module name from the command line arguments. For example, if you call:
php start.php my_module
The script automatically:
- replaces dashes with underscores;
- forms a proper class name for controllers and models (
MyModuleinstead ofmy_module).
This is important because OpenCart requires strict class and file name matching.
This approach saves you from manually renaming files and classes, giving you a module ready for use immediately.
Source template structure
For the generator, I prepared a source template, where all files already exist but contain placeholders %name% and %ModuleName%.
Example of the Source folder structure:
%name%/
├─ admin/
│ ├─ controller/
│ │ ├─ module/
│ │ │ └─ %name%.php
│ │ └─ event/
│ │ └─ %name%.php
│ ├─ model/
│ │ └─ module/
│ │ └─ %name%.php
│ ├─ view/
│ │ └─ template/
│ │ └─ module/
│ │ └─ %name%.twig
│ └─ language/
│ ├─ en-gb/
│ │ └─ module/
│ │ └─ %name%.php
│ └─ ru-ru/
│ └─ module/
│ └─ %name%.php
├─ catalog/
│ ├─ controller/
│ │ ├─ module/
│ │ │ └─ %name%.php
│ │ └─ event/
│ │ └─ %name%.php
│ ├─ model/
│ │ └─ module/
│ │ └─ %name%.php
│ ├─ view/
│ │ ├─ template/
│ │ │ └─ module/
│ │ │ └─ %name%.twig
│ │ ├─ javascript/
│ │ │ └─ %name%.js
│ │ └─ stylesheet/
│ │ └─ %name%.css
│ └─ language/
│ ├─ en-gb/
│ │ └─ module/
│ │ └─ %name%.php
│ └─ ru-ru/
│ └─ module/
│ └─ %name%.php
├─ README.md
├─ install.json
└─ LICENSE
All files are ready to use — the script simply copies them into a new folder named after your module and replaces the placeholders with the correct values.
Copying and replacing placeholders
The heart of the generator is the recurseCopy() and replacePlaceholders() functions.
recurseCopy()goes through all template folders and copies them into the new module.replacePlaceholders()takes all files and replaces%name%and%ModuleName%with your module name and class.
Example in the script:
$nameRaw = $argv[1];
$name = str_replace('-', '_', $nameRaw);
$moduleName = str_replace(['_', '-'], ' ', $name);
$moduleName = str_replace(' ', '', ucwords($moduleName));
After this, all files and folders automatically get proper names, and the module is ready for OpenCart 4.
Creating the ZIP archive
The final step of the generator is creating the .ocmod.zip archive.
Why is this important? OpenCart installs modules only via ZIP or the Extensions system. The script places all files into the archive without extra nested folders, so it can be uploaded directly to the admin panel.
Example:
$zipFile = $rootDir . '/' . $name . '.ocmod.zip';
zipFolder($innerDir, $zipFile);
As a result, you get a fully ready module that can be installed, tested, and extended.
The start.php script turns creating a starter OpenCart 4 module from a routine task into an automatic operation:
- no manual work with folders or files;
- correct class and file names;
- frontend and admin support;
- ready ZIP for installation.
As a developer, I can say: this saves a lot of time for every new module and allows me to focus on functionality rather than structure.
Structure of the generated starter OpenCart 4 module
After running the Start script, you get a fully ready module with the correct structure. For example, if your module name is my_module, the structure looks like this:
my_module/
├─ my_module/
│ ├─ admin/
│ │ ├─ controller/
│ │ │ └─ …
│ │ ├─ model/
│ │ │ └─ …
│ │ ├─ view/
│ │ │ └─ …
│ │ └─ language/
│ │ └─ …
│ ├─ catalog/
│ │ ├─ controller/
│ │ │ └─ …
│ │ ├─ model/
│ │ │ └─ …
│ │ ├─ view/
│ │ │ └─ …
│ │ └─ language/
│ │ └─ …
│ ├─ README.md
│ ├─ LICENSE
│ └─ install.json
└─ my_module.ocmod.zip
1. Admin and Frontend
Inside the admin/ folder are all files necessary for the admin panel:
- Controllers — module logic in admin.
- Models — database operations and module settings.
- Twig templates — module interface.
- Language files — English and Russian support.
In the catalog/ folder are similar files for the frontend: controllers, models, templates, JS, and CSS for the client side.
This organization follows OpenCart 4 standards, so the module is ready to install without any edits.
2. ZIP archive for quick installation
Immediately after generation, the script creates the file my_module.ocmod.zip.
Why this is awesome:
- OpenCart installs modules only via ZIP or Extensions.
- No need to manually zip files.
- All files go to the root of the archive — no extra nested folders.
This means that after running the script, you can instantly install the module via Admin → Extensions → Modules → Upload Module.
3. Practical benefits
Why I structured it this way:
- Speed — creating a starter OpenCart 4 module now takes seconds instead of hours.
- Standardization — all modules have the same file organization.
- Easy enhancement — easily add new features, JS, and CSS for frontend without breaking anything.
- Multilanguage support — English and Russian built-in.
In my experience, starting a project with the proper structure makes it much easier to maintain and scale the module. No messy folders or files, everything is logical and predictable.
P.S. Create modules faster, develop your projects with quality, and stop wasting time on routine tasks — start.php is ready to give you a starter template instantly.
Download the script for generating OpenCart 4 module starter templates from the public GitHub repository: https://github.com/Webpolka/oc_module_generator_4.1.0.3