Unlimited Plugins, WordPress themes, videos & courses! Unlimited asset downloads! From $16.50/m
  1. Code
  2. OpenCart

Create a Dashboard Module in OpenCart


In this article, I'll demonstrate how to create a custom dashboard module in OpenCart. The dashboard modules provide a high-level view of the happenings and statistics of the store. Although you'll find certain useful dashboard modules already in the core itself, sometimes you want to be more specific about the information which is going to be displayed. Thus, you end up creating your custom dashboard module.

Today, we'll create an example dashboard module and integrate it with the admin dashboard display. To keep things simple, we'll make a block of the most recent customers available in the store. We'll use the latest version of OpenCart, and I assume that you're familiar with the basic module development process in OpenCart.

What Is a Dashboard Module?

Once you're logged in to the back-end of OpenCart, you'll be redirected to the screen where you'll see the blocks like "Total Orders", "Total Sales", "World Map", etc. These blocks are the different dashboard modules which provide useful information about what's going on in the store. One of the most common uses of any dashboard module is to provide some kind of statistics.

Dashboard Modules

Technically, the dashboard module is similar to the other modules in OpenCart and follows the same structure and conventions as any OpenCart module. But what makes them special is the way they are attached to the dashboard display in the back-end.

So we'll start with the usual custom module development process for our custom dashboard module. Finally, we'll attach our module to the dashboard section.

Create a Custom Dashboard Module

Go ahead and create a file admin/controller/dashboard/recentcustomers.php with the following contents. We'll use recentcustomers as our module name.

It's a fairly straightforward controller setup! The important thing to note here is that we're loading the recentcustomers model and calling the getRecentCustomers method to fetch the recent customers.

Let's go ahead and quickly create a language file at admin/language/english/dashboard/recentcustomers.php.

Again, this is nothing more than setting up the labels which will be used in the view file.

Further, create a model file at admin/model/report/recentcustomers.php with the following contents.

In the model file, we've defined a  getRecentCustomers method which will simply fetch the five most recent customers in the store.

Finally, we'll go ahead and create a view file at admin/view/template/dashboard/recentcustomers.tpl.

In the view, we're iterating over the customer records and displaying it in a nice, responsive table format.

So, that's it as far as our custom module is concerned! You should have noticed that the procedure is exactly the same as that of any custom module development process. In the next section, we'll see exactly how our custom module will be attached to the dashboard section!

Attach Our Module to the Dashboard

To attach our custom module to the dashboard, we'll have to change a couple of core files in the back-end. For the sake of simplicity, we'll look at the changes required in the core files. Having said that, you should strictly avoid altering the core files directly and instead use OCMOD, which allows you to do that in a much better way.

Go ahead and open the admin/controller/common/dashboard.php file in your favorite text editor. Find the $data['recent'] = $this->load->controller('dashboard/recent'); snippet and add the following snippet just next to that line.

It's used to initialize our "Recent Customers" block.

Further, edit the file located at admin/view/template/common/dashboard.tpl. Find the <div class="col-lg-8 col-md-12 col-sm-12 col-sx-12"><?php echo $recent; ?></div> snippet in that file and add the following code after that line.

So, we've almost done it! Now, refresh your dashboard and you should be able to see a nice-looking Recent Customers module as shown in the following screenshot.

Recent Customers Block


Today, we've learned how to create a custom dashboard module in OpenCart. It's a nice way to display the aggregated information in the store and keep an eye on what's going on in the store. 

We have a lot of extensions for OpenCart available in the market that will help to expand your implementation beyond what the platform offers out-of-the-box, too.

I'm sure that it'll be useful to you, and don't forget to share your feedback and suggestions!

Looking for something to help kick start your next project?
Envato Market has a range of items for sale to help get you started.