Developing a module or plugin for Virtuemart 2 » History » Revision 15
Revision 14 (Max Milbers, 05/22/2013 02:57 PM) → Revision 15/16 (Matt Lewis-Garner, 12/22/2013 12:26 PM)
h1. Developing a module or plugin for VirtueMart 2 Documentation for the VirtueMart 2 API : http://docs.virtuemart.net/api-vm2 When you want to develop your own extension for VirtueMart, then these hints should help you get started: Use @if (!class_exists( 'VmConfig' )) require(JPATH_ADMINISTRATOR.DS.'components'.DS.'com_virtuemart'.DS.'helpers'.DS.'config.php');@ 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 @$config = VmConfig::loadConfig();@ You can then easily access them with @VmConfig::get('yourVariable','default');@ After loading the VmConfig you should always use the vm path constants to access files @JPATH_VM_SITE = JPATH_ROOT.DS.'components'.DS.'com_virtuemart' ); JPATH_VM_ADMINISTRATOR = JPATH_ROOT.DS.'administrator'.DS.'components'.DS.'com_virtuemart' );@ For performance reasons you should always use the @if (!class_exists( 'MyClass' )) require (JPATH_VM_ADMINISTRATOR.DS....)@ construction, *dont use require_once* *Loading and instancing a model* is very easy in Vm, just use $mynameModel = VmModel::getModel('myname'); for example: $currencyModel = VmModel::getModel('currency'); When you want to access the js used in vm then load them with @$config->jQuery(); $config->jVm();@ or for the css use @$config->cssSite();@ *adding Virtuemart 2 menu to your component* IN view.php.html use ----------------------------- if(!class_exists('VmView'))require(JPATH_VM_ADMINISTRATOR.DS.'helpers'.DS.'vmview.php'); class vmg_exportViewCategory extends VmView ----------------------------- in tmpl/default.php for eg. before your HTML codes ----------------------------- @$lang = JFactory::getLanguage(); $extension = 'com_virtuemart'; $base_dir = JPATH_ADMINISTRATOR; $lang->load($extension, $base_dir); AdminUIHelper::startAdminArea();@ ----------------------------- After your HTML codes ----------------------------- @ AdminUIHelper::endAdminArea(); @ ----------------------------- * *to use vm2 tables* @JTable::addIncludePath(JPATH_VM_ADMINISTRATOR.DS.'tables');@ *Adding an entry to Virtuemart menu* ON your installation SQL @INSERT INTO `#__virtuemart_adminmenuentries` (`id`, `module_id`, `parent_id`, `name`, `link`, `depends`, `icon_class`, `ordering`, `published`, `tooltip`, `view`, `task`) VALUES (null, 77, 0, 'COM_MYCOMPONENT', 'index.php?option=com_mycomponent', 'index?option=com_mycomponent', '', 'vmicon vmicon-16-to_do_list_cheked_1', 2, 1, '', 'myview', 'mytask');@ This example exemple add an entry in 'tool' menu (module_id 77) with icon vmicon-16-to_do_list_cheked_1 _result link is : index?option=com_mycomponent&view=myview&task=mytask_ For shipment, payment, or other plugin development please look here [[Plugin system]] or for modules here [[Modules system]]