Project

General

Profile

Developing a module or plugin for Virtuemart 2 » History » Version 16

Max Milbers, 10/25/2017 10:40 AM

1 16 Max Milbers
h1. Developing a module or plugin for VirtueMart 2/3
2 1 Max Milbers
3 12 Valérie Isaksen
Documentation for the VirtueMart 2  API : http://docs.virtuemart.net/api-vm2
4 9 Stephen Roberts
When you want to develop your own extension for VirtueMart, then these hints should help you get started:
5 1 Max Milbers
6
Use
7 16 Max Milbers
@if (!class_exists( 'VmConfig' )) require(JPATH_ADMINISTRATOR .'/components/com_virtuemart/helpers/config.php');@
8 14 Max Milbers
to load the configuration object in your extension. Now you have loaded the *main API* of VirtueMart 2. To be sure that the vm config is loaded, you may use
9 1 Max Milbers
10 5 Max Milbers
@$config = VmConfig::loadConfig();@
11 1 Max Milbers
12 13 Max Milbers
You can then easily access them with
13 1 Max Milbers
14
@VmConfig::get('yourVariable','default');@
15
16 2 Max Milbers
After loading the VmConfig you should always use the vm path constants to access files
17
18
@JPATH_VM_SITE = JPATH_ROOT.DS.'components'.DS.'com_virtuemart' );
19
JPATH_VM_ADMINISTRATOR = JPATH_ROOT.DS.'administrator'.DS.'components'.DS.'com_virtuemart' );@
20
21
For performance reasons you should always use the 
22
23
@if (!class_exists( 'MyClass' )) require (JPATH_VM_ADMINISTRATOR.DS....)@
24 1 Max Milbers
25 13 Max Milbers
construction, *dont use require_once*
26 2 Max Milbers
27 14 Max Milbers
*Loading and instancing a model* is very easy in Vm, just use
28 13 Max Milbers
 
29 6 Max Milbers
$mynameModel = VmModel::getModel('myname');
30
31
for example: $currencyModel = VmModel::getModel('currency');
32
33 1 Max Milbers
When you want to access the js used in vm then load them with
34
35 4 Max Milbers
@$config->jQuery();
36
$config->jVm();@
37 1 Max Milbers
38
or for the  css use
39 4 Max Milbers
@$config->cssSite();@
40 1 Max Milbers
41 8 Patrick Kohl
*adding Virtuemart 2 menu to your component*
42 7 Patrick Kohl
IN view.php.html use
43
-----------------------------
44
if(!class_exists('VmView'))require(JPATH_VM_ADMINISTRATOR.DS.'helpers'.DS.'vmview.php');
45
class vmg_exportViewCategory extends  VmView 
46
-----------------------------
47
48
49
in tmpl/default.php for eg.
50
51
before your HTML codes
52
-----------------------------
53
@$lang = JFactory::getLanguage();
54
$extension = 'com_virtuemart';
55
$base_dir = JPATH_ADMINISTRATOR;
56
$lang->load($extension, $base_dir);
57
AdminUIHelper::startAdminArea();@
58
-----------------------------
59
60
After your HTML codes
61
-----------------------------
62
@ AdminUIHelper::endAdminArea(); @
63 1 Max Milbers
-----------------------------
64 8 Patrick Kohl
*
65 7 Patrick Kohl
66 8 Patrick Kohl
*to use vm2 tables*
67 7 Patrick Kohl
68
  @JTable::addIncludePath(JPATH_VM_ADMINISTRATOR.DS.'tables');@
69
70 10 Patrick Kohl
*Adding an entry to Virtuemart menu*
71
ON your installation SQL
72
@INSERT INTO `#__virtuemart_adminmenuentries` (`id`, `module_id`, `parent_id`, `name`, `link`, `depends`, `icon_class`, `ordering`, `published`, `tooltip`, `view`, `task`) VALUES
73 15 Matt Lewis-Garner
(null, 77, 0, 'COM_MYCOMPONENT', 'index.php?option=com_mycomponent', '', 'vmicon vmicon-16-to_do_list_cheked_1', 2, 1, '', 'myview', 'mytask');@
74
This example add an entry in 'tool' menu (module_id 77) with icon vmicon-16-to_do_list_cheked_1 
75 10 Patrick Kohl
_result link is : index?option=com_mycomponent&view=myview&task=mytask_
76
77
78
79 7 Patrick Kohl
80 5 Max Milbers
For shipment, payment, or other plugin development please look here [[Plugin system]] or for modules here [[Modules system]]