OpenCart v1.x Framework Explanation
شنبه, ۱۵ آذر ۱۳۹۳، ۱۲:۳۴ ق.ظ
OpenCart v1.x Framework Explanation
by Qphoria » Fri Feb 20, 2009 8:46 pm
OpenCart 1.x is a cart application built on top of its own in-house framework. The framework uses an MVC style design pattern. The language piece of opencart is an additional variable layer and isn't part of the pattern persay, but it is important to understand the localization and how text for different languages is used:
First off, OpenCart's root directory looks something like this:
admin - the admin directory path is all the code on the backend of your site. This is completely separate from the catalog area and can even be stored on a different host if you prefer.
catalog - the catalog directory path stores all the code on the front end of your site
image - the image directory path is where all the product images are stored
download - the download directory path is where all the downloads are stored
system - the system path has all the common libraries and engine code. Both admin and catalog use this folder, so if storing admin on another server, you will also need to copy the system folder there.
In the catalog and admin directories, a common tree based on the MVC architecture is formed:
Model - Database layer - All calls to the database are done here, referenced from the controller. The purpose of a model is to always have structured db calls so that all other files have access to the same db queries.
View - Template display - This is where the HTML and designing is done in the respective tpl files.
Controller - Main controlling code base - This is where the functional code logic is processed and variables for the view are setup
Language - Localization/Language - This is where you set which constants translate to text for things like heading titles, static links and text, etc. Note that this is not part of MVC, just another variable layer that makes using multiple language easier.
Most files follow the naming pattern of the main controller...
So for example, for the product page on the frontend, there are 4 main files:
M: \catalog\model\catalog\product.php
V: \catalog\view\theme\default\template\product\product.tpl
C: \catalog\controller\product\product.php
Language: \catalog\language\english\product\product.php
Similarly, on the admin side, to set those fields, there are 4 main files as well:
M: \admin\model\catalog\product.php
V: \admin\view\template\catalog\product_form.tpl
C: \admin\controller\catalog\product.php
Language: \admin\language\english\catalog\product.php
Try to follow those files for existing fields, like 'model number' and see if you can duplicate all the places you find model number being used and replace it with your new field(s). Don't forget to also add the new columns to the product table in the database.
First off, OpenCart's root directory looks something like this:
admin - the admin directory path is all the code on the backend of your site. This is completely separate from the catalog area and can even be stored on a different host if you prefer.
catalog - the catalog directory path stores all the code on the front end of your site
image - the image directory path is where all the product images are stored
download - the download directory path is where all the downloads are stored
system - the system path has all the common libraries and engine code. Both admin and catalog use this folder, so if storing admin on another server, you will also need to copy the system folder there.
In the catalog and admin directories, a common tree based on the MVC architecture is formed:
Model - Database layer - All calls to the database are done here, referenced from the controller. The purpose of a model is to always have structured db calls so that all other files have access to the same db queries.
View - Template display - This is where the HTML and designing is done in the respective tpl files.
Controller - Main controlling code base - This is where the functional code logic is processed and variables for the view are setup
Language - Localization/Language - This is where you set which constants translate to text for things like heading titles, static links and text, etc. Note that this is not part of MVC, just another variable layer that makes using multiple language easier.
Most files follow the naming pattern of the main controller...
So for example, for the product page on the frontend, there are 4 main files:
M: \catalog\model\catalog\product.php
V: \catalog\view\theme\default\template\product\product.tpl
C: \catalog\controller\product\product.php
Language: \catalog\language\english\product\product.php
Similarly, on the admin side, to set those fields, there are 4 main files as well:
M: \admin\model\catalog\product.php
V: \admin\view\template\catalog\product_form.tpl
C: \admin\controller\catalog\product.php
Language: \admin\language\english\catalog\product.php
Try to follow those files for existing fields, like 'model number' and see if you can duplicate all the places you find model number being used and replace it with your new field(s). Don't forget to also add the new columns to the product table in the database.