Project

General

Profile

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

Valérie Isaksen, 12/21/2012 04:55 PM

1 9 Stephen Roberts
h1. Developing a module or plugin for VirtueMart 2
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
@if (!class_exists( 'VmConfig' )) require(JPATH_ADMINISTRATOR.DS.'components'.DS.'com_virtuemart'.DS.'helpers'.DS.'config.php');@
8
to load the configuration object in your extension. Then use
9
10 5 Max Milbers
@$config = VmConfig::loadConfig();@
11 1 Max Milbers
12
to load the configuration values, you can then easily access them with
13
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
25
construction, dont use require_once
26 1 Max Milbers
27 6 Max Milbers
Loading and instancing a model is very easy in Vm, just use 
28
$mynameModel = VmModel::getModel('myname');
29
30
for example: $currencyModel = VmModel::getModel('currency');
31
32 1 Max Milbers
When you want to access the js used in vm then load them with
33
34 4 Max Milbers
@$config->jQuery();
35
$config->jVm();@
36 1 Max Milbers
37
or for the  css use
38 4 Max Milbers
@$config->cssSite();@
39 1 Max Milbers
40 8 Patrick Kohl
*adding Virtuemart 2 menu to your component*
41 7 Patrick Kohl
IN view.php.html use
42
-----------------------------
43
if(!class_exists('VmView'))require(JPATH_VM_ADMINISTRATOR.DS.'helpers'.DS.'vmview.php');
44
class vmg_exportViewCategory extends  VmView 
45
-----------------------------
46
47
48
in tmpl/default.php for eg.
49
50
before your HTML codes
51
-----------------------------
52
@$lang = JFactory::getLanguage();
53
$extension = 'com_virtuemart';
54
$base_dir = JPATH_ADMINISTRATOR;
55
$lang->load($extension, $base_dir);
56
AdminUIHelper::startAdminArea();@
57
-----------------------------
58
59
After your HTML codes
60
-----------------------------
61
@ AdminUIHelper::endAdminArea(); @
62 1 Max Milbers
-----------------------------
63 8 Patrick Kohl
*
64 7 Patrick Kohl
65 8 Patrick Kohl
*to use vm2 tables*
66 7 Patrick Kohl
67
  @JTable::addIncludePath(JPATH_VM_ADMINISTRATOR.DS.'tables');@
68
69 10 Patrick Kohl
*Adding an entry to Virtuemart menu*
70
ON your installation SQL
71
@INSERT INTO `#__virtuemart_adminmenuentries` (`id`, `module_id`, `parent_id`, `name`, `link`, `depends`, `icon_class`, `ordering`, `published`, `tooltip`, `view`, `task`) VALUES
72
(null, 77, 0, 'COM_MYCOMPONENT', 'index?option=com_mycomponent', '', 'vmicon vmicon-16-to_do_list_cheked_1', 2, 1, '', 'myview', 'mytask');@
73
This exemple add an entry in 'tool' menu (module_id 77) with icon vmicon-16-to_do_list_cheked_1 
74
_result link is : index?option=com_mycomponent&view=myview&task=mytask_
75
76
77
78 7 Patrick Kohl
79 5 Max Milbers
For shipment, payment, or other plugin development please look here [[Plugin system]] or for modules here [[Modules system]]