Project

General

Profile

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

Patrick Kohl, 02/16/2012 02:07 PM

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