OpenCart Basics
OpenCart structure is split into 2 separate applications. One is the catalog (store front) and admin (administration). Each application structure is based on the Model View Controller (MVC) paradigm and includes a shared library.
MVC is basically the splitting of the data, logic and UI into separate parts to make building applications more structured and easier to manage.
The functions for data storing, editing and retrieval. This can be done via a database, file, remote storing etc..
In web based MVC the view is normally where the templates are stored.
The bit in the middle where logic is used to choose which models to load and push the data into the view / template.
The front and the admin are spit into two separate folders and the shared library folder.
- admin - Administration Area
- catalog - Store Front
- system - Shared System Files
In the two application directories you will find the controller, model, view and a language folder. This so each of component that makes up the OpenCart application can be easily managed.
- controller/
- language/
- model/
- view/
- config/
- engine/
- helper/
- library/
- storage/
It's very important that you move the storage directory outside of the web directory as the files stored here can contain information that can compromise the security of a users web site.
- cache/
- download/
- logs/
- modification/
- session/
- upload/
- vendor/
Its important to understand about how parts of the OpenCart system are loaded before describing the file structure and coding structure.
Controllers can be directly called by users visiting the web site and also be accessed via the code using the loader class.
The route URL variable in the address bar will need to match up with the path of the controller being called.
URL
https://www.yourstore.com/index.php?route=account/login
Path to file
/catalog/controller/account/login.php
Path to controller method
the last part of the route will either be the file name or the
So
The loader class is used to load the different components of OpenCart. Only the library classes can be auto loaded upon Object Initialization.
$this->load->controller('directory/filename');
$this->load->model('directory/filename');
Models can be access directory in the code using:
$this->load->model('directory/filename');
$this->load->view('directory/filename');
$this->load->helper('directory/filename');
$this->load->language('directory/filename');
$this->load->config('filename');
Please refer to the loader class for the class API.
Components Description
Controller Description
So for example a blog extension structure maybe
<?php
class ControllerCmsBlog extends ***Controller*** {
// If no method is called index is called by default
public function index() {
}
}
OpenCart tries to detect the language your browser is using even if the database is down it will use the directory name to see
The language directory should be named after Web browser language identification codes in lowercase.
Language | Code | Language | Code | Language | Code |
---|---|---|---|---|---|
Afrikaans | af | Croatian | hr | Greek | el |
Albanian | sq |
Language files are basically just arrays and are broken into a few different parts.
<?php
// Heading
$_['heading_title'] = 'My Heading';
// Text
$_['text_account'] = 'General';
// Entry``
$_['entry_firstname'] = 'First Name';
$_['entry_lastname'] = 'Last Name';
$_['entry_email'] = 'E-Mail';
$_['entry_telephone'] = 'Telephone';
// Error
$_['error_exists'] = 'Warning: E-Mail address is already registered!';
$_['error_firstname'] = 'First Name must be between 1 and 32 characters!';
$_['error_lastname'] = 'Last Name must be between 1 and 32 characters!';
$_['error_email'] = 'E-Mail Address does not appear to be valid!';
$_['error_telephone'] = 'Telephone must be between 3 and 32 characters!';
$_['error_custom_field'] = '%s required!';
Description
<?php
class ModelCmsBlog extends Model {
public function getBlogs($data = array()) {
}
}
Description
Admin
- view/
- view/image/
- view/stylesheets/
- view/sass/
- view/template/
Catalog
- catalog/controller/
- catalog/language/
- catalog/model/
- catalog/view/theme/template
(Description)
Helper function runs a specific task with no dependence on other functions. You could create multiple helper functions for different tasks (ex. URL helper, File helper).
A complete list of available library is here.
OpenCart homepage | OpenCart forums | OpenCart blog | How to documents | Newsletter
OpenCart is created under the GNU General Public License version 3 (GPLv3)