| |
Categories
|
Home - SP-Cart 2.0 architecture peculiarities -
SP-Cart 2.0 architecture
SP-Cart 2.0 architecture
SP-Cart 2.0 architecture. Basic principles.
The architecture of the new version has been completely changed, while preserving the functional approach to programming. Special emphasis was placed on the ability to improve and extend software functionality without any (or with minimum) interference in the source code.
SP-Cart 2.0 concept is to use the so-called addons to enhance the software functionality.
The following architecture tools, allowing to improve the existing and implement new features of the program, are introduced in version 2.0:
- Code hooks
- Precontrollers and postcontrollers
- Template hooks
Also, additional ways of enhancement are provided in the program:
Let's consider each of the listed tools in detail.
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
Code hooks (CH)
CH or hook is a specially defined part in the program code that can transfer control to an addon. Hook is declared in advance by calling a special function in the necessary part of code - fn_set_hook('hook_name', $params, [$param2], [$paramN]);.
Example 1.
Knowing the hook name, any addon can intercept execution of the program code, perform necessary manipulations and then return the execution process to the Main program (MP). When calling a certain hook, all variables directly defined in this hook become available for the addon.
Call of the hook within the addon is carried out by defining the function which name consists of the prefix "fn_", addon name, underscore and the full name of the called hook.
1. |
fn_set_hook('get_gift_certificate_info', $_certificate, $certificate, $type) |
Example 2.
1. |
fn_gift_certificates_get_certificate_info($_certificate, $certificate, $type) |
|
| |
|
Precontrollers and postcontrollers (precont, postcont)
Precont and postcont are special PHP files of the addon, which (depending on their names and location in the file structure of the addon) are called before or after executing one or another standard controller.
Example 1.
- The addon Attachments has the file /addons/attachments/controllers/products.post.php in its structure. The directory controllers indicates that the files in this directory are either controllers of the addon or precont/postcont for standard controllers.
- The first part of the file name "products" defines the controller name. As a controller with the name "products" is a standard one, the addon can only declare precont or postcont for it.
- ".post" in the file name indicates that the file will be connected and executed after the standard controller "products" is performed. To set it in motion prior to the standard controller execution, ".post" should be changed to ".pre".
|
| |
|
Template hook (TH)
Template hooks are parts of a template enclosed in the tags "{hook name="section:hook_name"}{/hook}" that can be supplemented or completely redefined by any addon.
Example 1.
1. 2. 3. 4. 5. |
{hook name="order_management:product_info"}
{if $cp.product_code}
<p>{$lang.sku}: {$cp.product_code}</p>
{/if}
{/hook} |
|
| |
|
|
| |
|
<< Read Previous Read Next>> |
| |
|
|
Copyright © 2009 SP-CART.COM. All Rights Reserved.
|
|