How To Create An OpenCart Extension

Creating an OpenCart 2.x extension is a fairly simple process and there are many different resources available out there to help you with this.

Today I would like to share the MultiMerch way of doing this. This is how we create our OpenCart extensions and MultiMerch addons.

I'll try to make it as simple and easy to understand as possible.

Displaying a custom page in OpenCart is fairly easy, but in most cases you'll need more than that. We usually need our OpenCart extensions to have at least the following parts (in addition to the main logic):

  • a simple way to install and remove them
  • configuration/settings (and a simple interface to change them)
  • database tables to store and retrieve data (and a way to create and delete them without asking the user to run SQL scripts manually)
  • support for multiple languages (OpenCart has quite a multilingual user base)

Let's create a simple extension skeleton that will allow us to do all of this. Today we'll cover the admin-area part of the extension without settings (I'll talk about them in Part 2).

You most likely already know that OpenCart is based on a fairly straight forward MVC architecture plus a set of language files. The Models store the database procedures, the Views hold the HTML code of pages and Controllers fetch the data using Models and use it to render Views.

In addition to this, OpenCart's main code is split in two separate parts (admin/ and catalog/, each containing an MVC structure) along with common files and libraries under system/.

Today, we only need the admin/ part. OpenCart usually stores its extension files under the module/ subfolder inside each of the MVCL folders. Let's stick to this and create the following folder structure in our workspace:

OpenCart Extension Folder Structure

Great! This structure will hold our models, views, controllers and languages.

Note that we've placed our structure inside a separate upload/ folder with a readme.txt file outside of it. This isn't mandatory, but it makes it easy to separate what needs to be uploaded to OpenCart installation from everything else.

Now let's start adding files.

Most users expect the newly uploaded extensions to appear under Admin > Extensions > Modules. OpenCart will display our new extension on this page automatically, but it needs two files to be able to do it: language file (to display the title) and controller file.

Let's start with the language file.

Create a new file called multimerch_skeleton.php under admin/language/english/module/ and add the following code to it:

$_['heading_title'] = 'MultiMerch Skeleton';

Now create a file named multimerch_skeleton.php under admin/controller/module/ consisting of this empty class:

class ControllerModuleMultimerchSkeleton extends Controller {

Make sure that file names and class names match. OpenCart uses this to determine what to load and where to find it.

You can now upload the contents of the upload/ folder (not the folder itself!) over to your OpenCart setup root and look into Admin > Extensions > Modules:

opencart extension skeleton admin

Neat, our Skeleton is there! It doesn't do much more than that, but it's already visible in the admin area and can be installed and uninstalled through OpenCart's own system.

Now, what if we also need a table in the database for our extension? Let's make OpenCart helps us do it!

First, we need the following multimerch_skeleton.php model file inside admin/model/module/:

class ModelModuleMultimerchSkeleton extends Model {
public function createSchema() {
CREATE TABLE IF NOT EXISTS " . DB_PREFIX . "multimerch_skeleton (
public function deleteSchema() {
$this->db->query("DROP TABLE IF EXISTS " . DB_PREFIX . "multimerch_skeleton");

Here we have a simple database table with a single field that we want created and removed when Skeleton is installed/uninstalled. The DB_PREFIX constant holds the table prefix that was selected during OpenCart installation. Don't forget it when working with the database!

Now we need to tell OpenCart to call these functions. Let's add the following code to the multimerch_skeleton.php controller file inside our ControllerModuleMultimerchSkeleton class:

class ControllerModuleMultimerchSkeleton extends Controller {
public function install() {
public function uninstall() {

These two controller functions are called by OpenCart automatically when you install and uninstall the module through Admin > Extensions > Modules.

Now we can upload our files and test them out!

Let's try installing MultiMerch Skeleton via Admin > Extensions > Modules to see what happens.

opencart extension successfully installed

opencart extension skeleton table

Awesome! Now our Skeleton extension is installed and the table is there. It will be removed if Skeleton is uninstalled via Admin > Extensions > Modules.

That's it for today, hopefully this helped you learn something new about OpenCart extensions.

Meanwhile, let me know in the comments if I've forgotten something or if you have any questions!

Need an OpenCart extension? Hire us!

We offer a wide range of professional OpenCart & MultiMerch services. Find out more!


Build a multi vendor marketplace with MultiMerch

Martin Boss

Martin is the founder of MultiMerch, an ex-OpenCart developer and an e-commerce enthusiast.You can also find him on LinkedIn, Twitter and Quora.