Developing a module or plugin for Virtuemart 2 » History » Version 7
Patrick Kohl, 02/16/2012 01:13 AM
| 1 | 1 | Max Milbers | h1. Developing a module or plugin for Virtuemart 2 |
|---|---|---|---|
| 2 | |||
| 3 | When you want to develop your own extension for virtuemart, then this hints should you help to get started: |
||
| 4 | |||
| 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 | 7 | Patrick Kohl | adding Virtuemart 2 menu to your component |
| 40 | 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 | ----------------------------- |
||
| 62 | |||
| 63 | in controllers if model are wanted |
||
| 64 | |||
| 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 | to use vm2 tables |
||
| 76 | |||
| 77 | @JTable::addIncludePath(JPATH_VM_ADMINISTRATOR.DS.'tables');@ |
||
| 78 | |||
| 79 | |||
| 80 | 5 | Max Milbers | For shipment, payment, or other plugin development please look here [[Plugin system]] or for modules here [[Modules system]] |