VirtueMart - 1.0 開発者ガイド

ページ / 19
Core modules are listed in the table mos_vm_modules.
Calling
index.php?com_virtuemart&page=shop.browse
in your Joomla site would let VM include
the file
/administrator/components/com_virtuemart/html/shop.browse.php
.
3.3. Core Modules & their Functions, Environment
Variables
3.3.1. Core Modules
In order to ease with which new features can be added to mp, the concept of using modules has been introduced.
A module defines a feature set of VM by providing class files and html layouts related to that particular module.
It is very important to understand how modules work since everything, including the shop, is a module.
Each module is defined and set in the VM module register. The module definition form allows the site adminis-
trator to define the information for each module, e.g. the module name, the perms of this module and its descrip-
tion.
You can reach the module list in the administrative interface using "Admin" => "List Modules".
Example: The core module "product" is one entry in the table mos_vm_module. Its pages must be called using
"..&page=product. ....". If the user has appropriate permissions, the page is loaded - if not, an error message is
generated.
3.3.2. func
Each core module has a list of functions that can be executed. For example, to add a product into the system, a
function called productAdd exists in the table
mos_vm_function
.
When you add a product, you pass the hidden variable
func
with a value of productAdd to the system (besides
all the other form fields).
If the current user has the permissions to execute the function (permissions can be set for each function sepa-
rately), the file
virtuemart_parser.php
looks for the class file name and the function name mapped in
the table
mos_vm_function
for that specific function name (productAdd). In this case we get ps_product
as the class name and add as the function name.
After having fetched this information, we can start to execute the real function, which is done in this part of
virtuemart_parser.php:
// Load class definition file
require_once( CLASSPATH.$db->f("function_class").".php" );
// create an object
$string = "\$" . $func_class . " = new " . $func_class . ";";
eval( $string );
// RUN THE FUNCTION
$cmd = "\$ok = \$" . $func_class . "->" . $func_method . "(\$vars);";
eval( $cmd );
First, the file
ps_product.php
is loaded, then an object of the class
ps_product
is created and the func-
tion add is called on that object. The function returns
true
on success and
false
on failure. The variable
$ok
stores the function result. All this code is exectuted using the PHP eval command for creating and executing
PHP code on-the-fly.
VirtueMart Developer Manual
6