Hi everyone, me Rupak Nepali. In our fifth video, we describe OpenCart objects and a list of methods. Today, in our sixth video we are going to describe OpenCart framework code flow and how requests and responses are handled by OpenCart. Describe how MVCL works in OpenCart which will create a good foundation to start programming in OpenCart.

 “OpenCart theme and Module development” book say “OpenCart is an e-commerce shopping cart application built with its own in-house framework which uses MVCL (Model, view, controller, and language)pattern. Thus, each module in OpenCart also follows the MVCL pattern. The controller creates logic and gathers data from the model and it passes data to display in the view.”

OpenCart is based on this MVCL pattern. Let’s see what is MVCL pattern:

  • The user request to the controller through URL,
  • The controller loads the language and set the variable for any text used in the data.
  • If data is needed from the database controller loads the model, ask for results and model send back results, then controller set results to data.
  • All these data are sent to View which renders and shows the output.
MVCL pattern
From OpenCart.com

In the catalog and admin directories, you can see a tree structure of MVCL so whenever we create modules or pages we follow these directories structure:

  • Controller – The controller loads the language and set the variable for any text used in the data. If data is needed from the database controller loads the model, ask for results and model send back results, then controller set results to data.
  • Model – Database layer – All calls to the database are done. It is to structure DB calls so that all other files have access to the same DB queries.
  • View – Presentation/Template/display layer – This is where the HTML and designing are done in the respective tpl files.
  • Language – Localization/Language – This is layer is to make the translation easy, variables and text are assigned and these folder files are translated to the respective language with the same variables name.

OpenCart handles each request with a simple pattern for every incoming request are interpreted by the routing URL “route=” and passed to controller class matching the URL route part which returns Response objects. The controller is the only file in the MVC-L framework to be accessed by URL in OpenCart. The controller is where all logic goes: it’s where you interpret the request and create a response.

It’s that easy! Yes!

  • Each request executes a front controller file
  • The routing system determines which Controller class index method will be executed based on information from the request and routing URL you’ve passed.
  • Returns the appropriate Response object.

Let’s see some example
http://webocreation.loc/index.php?route=account/login
Here “route=account/login”, it means that the controller to find in Opencart is catalog/controller/account/login.php as there is no third one so by default the method is index().

http://webocreation.loc/index.php?route=account/return/add
Here “route=account/return/add”, it means that the controller to find in Opencart is catalog/controller/account/return.php and method is add().

  • The controller name must be like Controller + directory path+ filename
  • If your file name contains (_) underscore then no need to add in controller name.
  • The controller class must extend the parent class i.e.Controller

Let’s check the code. Let say the user request the same URL http://webocreation.loc/index.php?route=account/login
With route=account/login, the controller to process is ControllerAccountLoginclass and index method.

Request and response flow in Opencart
MVCL Opencart 3 defined

So, by defining MVCL we completed our fifth video, we hope you liked it. As always please don’t forget to post your questions or comments so that I can add extra topics or things that I need to develop which will help to develop the quality of videos series. You can follow at my twitter account rupaknpl and subscribe to our youtube channel opencart tutorials. Similarly, keep on visiting my personal blog https://webocreation.com where you will find lots of free modules.

In the next video, the real fun program begins the “Hello World” Opencart module. So, see you in the next video and happy learning and thanks for watching videos.
See you.

LEAVE A REPLY

Please enter your comment!
Please enter your name here