OpenCart is a popular open-source e-commerce platform that allows store owners to create an online store and manage their products, orders, customers, and other store settings. By default, OpenCart provides an admin dashboard where store owners can manage their store settings. However, sometimes you may need to create a custom admin page to manage specific aspects of your store that are not available in the default dashboard. In this case, you can create a custom admin page using the following steps:
Step 1: Create a new controller In your OpenCart installation, navigate to the admin/controller
directory and create a new PHP file with a unique name for your controller. For example, if you want to create a page to manage your store’s social media links, you could name the file social_links.php
.
Step 2: Define the controller class In the newly created file, define the controller class by extending the Controller
class. For example, your controller class could look like this:
class ControllerCustomSocialLinks extends Controller { public function index() { // Your code to manage the social links page goes here } }
Step 3: Define the view file
In the admin/view/template directory, create a new directory with the same name as your controller class, followed by the word “view”. For example, if your controller class is named ControllerCustomSocialLinks, create a new directory called custom_social_links_view.
In the newly created directory, create a new PHP file with the name social_links.tpl. This file will contain the HTML code for your custom admin page.
Step 4: Load the view in the controller
In your controller class, use the $this->response->setOutput() method to load the view file you just created. For example, your controller class could look like this:
class ControllerCustomSocialLinks extends Controller { public function index() { $this->response->setOutput($this->load->view('custom_social_links_view/social_links.tpl')); } }
Step 5: Add the controller to the admin menu In the admin/view/template/common
directory, open the file menu.tpl
. Add a new menu item to the list of existing menu items, pointing to your new controller. For example:
<li><a href="<?php echo $custom_social_links; ?>"> <i class="fa fa-link"></i> <span>Social Links</span></a></li>
where $custom_social_links is the URL to your custom admin page.
That’s it! You should now be able to access your custom admin page by clicking on the menu item you just created. From there, you can manage your store’s social media links (or whatever else your custom admin page is for).