How To Create Your First Module On OpenCart

How To Create Your First Module On OpenCart

Amigoways Explain how to create your first module on OpenCart with these easy step-by-step instructions.

We need to create our extension folder in the folder extensions which is located in the root folder.

The folder structure will be shown below.

No alt text provided for this image
{

"name": "Module name - Module Name",

"version": "1.0",

"author": "amigoways",

"link": "https://www.amigoways.com"

}        

Admin

The admin folder is for the admin panel functionalities. As OpenCart is an MVC framework, it contains a model, view and controller as usual.

No alt text provided for this image

Controller

We should give a namespace for each controller we created.


namespace Opencart\Admin\Controller\Extension\Modulename;        
class ClassName extends \Opencart\System\Engine\Controller {

The controller will contain install and uninstall functions to install/uninstall the extension.

?

public function install() {        
//to do code
}
public function uninstall() {        
//to do code
}

To load the model and call the ?model function in the controller, code goes like this

?

$this->load->model('extension/modulename/foldername/modelfilename');
$this->model_extension_modulename_foldername_modelfilename->function_name();        

View

To load the view file the code should be like below.

$this->response->setOutput($this->load->view('extension/module/$filepath', $data));        

Style

To add style , the style.css file should be in the folder ?/extension/module/admin/view/css/.

$this->document->addStyle(HTTP_CATALOG . '/extension/module/admin/view/css/style.css');        

Model

To register the model into the system, the namespace should be like this

namespace Opencart\Admin\Model\Extension\Modulename;        
class ClassName extends \Opencart\System\Engine\Model {

View

The view file format should be twig i.e. filename.twig

And the file location should be ?/extension/module/admin/view/filename.twig

Catalog

The same procedure is going for the catalog i.e. frontend side functionality.

But the namespace and location will vary from the admin.

Controller

namespace Opencart\Catalog\Controller\Extension\Modulename;
class ClassName extends \Opencart\System\Engine\Controller {        

Model

namespace Opencart\Catalog\Model\Extension\Modulename;
class ClassName extends \Opencart\System\Engine\Model {        

System

The folder system is for loading any third-party library.

Build

Finally, to build the module, files should be compressed and named as module name.ocmod

Conclusion

Amigoways publishes tutorial blog posts on Module & Plugin development. Stay tuned for updates and advanced module-building tips.

Morteza Oboudi

General Manager & Co-founder - Retrina

1 年

Dear Senthil, We made A Professional Drag & Drop Page builder for OpenCart like Elementor in WordPress. It will help you to design and customize faster. I invite you to check it at https://retrina.com/ronixa

回复
Muhammad Usama

UI/Web Developer ???? | Next.js/React Expert | WordPress | Crafting Engaging User Experiences with Every Pixel

1 年

This looks like a great guide for OpenCart module developers! I'm definitely going to check it out.

回复
Muhammad Usama

UI/Web Developer ???? | Next.js/React Expert | WordPress | Crafting Engaging User Experiences with Every Pixel

1 年

Thanks for sharing this!

回复

要查看或添加评论,请登录

Senthil Murugeasan的更多文章

社区洞察

其他会员也浏览了