As described in “OpenCart theme and Module development” book, it says “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.”
User request to the controller through website URL,
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 result and model send back results, then controller set results to data.
All these data are sent to View which renders and show the output
https://webocreation.com/blog/describing-files-folder-opencart-framework
2. What this video series covers
Making hello world module
Workflow or markup to make hello world module
-- Installing a module
-- Configuration of module
-- Managing layout and position
-- Uninstalling the module
Admin files created to make hello world module
-- Controller creation
-- Language file creation
-- Template file creation
Front end files created to make hello world
-- Controller creation
-- Language file creation
-- Template file creation
OpenCart Flow
• Introduction
• Why OpenCart?
• Features of OpenCart
• Prerequisites
• Downloading example code
• Installing OpenCart
-Steps to create custom URL to work locally
• Describing folders and files of OpenCart
• OpenCart Code flow, Request and Response in
OpenCart
• Database table schema
• OpenCart Library Global Methods
3. From Opencart.com documentation
• As described in “OpenCart theme and Module development”
book, it says “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.”
• User request to the controller through website URL,
• 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 result and model send back results, then
controller set results to data.
• All these data are sent to View which renders and show the
output
OpenCart for Developer
4. OpenCart directories structure of MVCL
• Controller - 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
result 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 – Here we
write the html and inserted variables that we get from
the controller, we use twig here.
• Language - Localization/Language - This is layer is to
make the translation easy, variables and text are
assigned and this folder files are translated to the
respective language with the same variables name.
5. Request and Response in OpenCart
• OpenCart handles each request with simple pattern of URL requested
• Incoming requests are interpreted by the routing URL “route=“ and passed
to controller class method matching the URL route part which perform
business logics, loads respective data to returns Response objects to view.
• Each requested URL “route=” helps on finding respective folder and then
controller file.
• The routing system determines which Controller class method will be
executed based on information from the request and routing URL you've
passed.
• The term controller is a word you'll hear a lot, regardless of the language or
framework you use. It refers simply to the area of your code that processes
user input and prepares the response.
• Returns the appropriate Response object.
6. It’s that easy
• YES
• Each request executes a front controller file
• The routing system determines which Controller class method
will be executed based on information from the request and
routing URL you've passed.
• Returns the appropriate Response object.
7. Still confused
• 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().
8. For Opencart Programmer
Controller
View
Model
Database
Request: GET value in URL
route=account/login
Response->output
$this->load->language('account/login');
$this->document->setTitle($this->language->get('heading_title’));
//loads the language file and assign to the data variable
$this->load->model(‘account/customer’);
// Check how many login attempts have been made.
$login_info = $this->model_account_customer->getLoginAttempts($this->request->post['email']);
//Controller logics here and set into a data variables
$data[‘email'] = ‘webocreation.com@gmail.com’;
$data['password'] = ‘’; // you can pass “Array, String, language string etc”
//Structure
$data['column_left'] = $this->load->controller('common/column_left');
$data['header'] = $this->load->controller('common/header');
$data['footer'] = $this->load->controller('common/footer’);
$this->response->setOutput($this->load->view(‘account/login', $data));
catalog/model/account/customer.php
public function getLoginAttempts($email) {
$query = $this->db->query("SELECT
* FROM `" . DB_PREFIX . "customer_login`
addCustomer($data) $this->db->query(INSERT)
editCustomer($customer_id, $data)
$this->db->query(UPDATE)
deleteCustomer($customer_id)
$this->db->query(DELETE)
getCustomer($customer_id)
$this->db->query(SELECT)
And many more
Catalog/view/theme/default*/template/account/l
ogin.twig
{{ header }}
<div>
{{ column_left }}
<div>
<div>
{{ text_new_customer }}
{{ email }}
<div>
{{ footer }}
Other html and css included
Which file? catalog/controller/account/login.php
Which controller? ControllerAccountLogin Which method? index
Request result
Response result
Language
$_['heading_title’] = 'Account Login’;
$_['text_new_customer’] = 'New Customer’;
//all of these variables are directly available in template
or twig files in OpenCart 3 but in OpenCart 2 you have to
assign for every variable in controller
Which file? cataloglanguageen-gbaccount/login.php
Which variable? heading_title