### Example Override Path for TextInput Plugin Source: https://docs.virtuemart.net/tutorials/templating-layouts/how-to-overwrite-plugins This is an example of the specific path to use when overriding the 'textinput' plugin, demonstrating the structure for custom template overrides. ```text /templates/[yourtemplate]/html/vmcustom/textinput ``` -------------------------------- ### Layout Bootstrap Version Example Source: https://docs.virtuemart.net/tutorials/templating-layouts/fix-missing-token-in-checkout-virtuemart-4-6-x This example shows how to identify the active Bootstrap version used by Virtuemart, which determines the specific layout file to override (e.g., `bs5-default.php`). ```text bs5-default ``` -------------------------------- ### Cart View Title Example Source: https://docs.virtuemart.net/tutorials/templating-layouts/templates-for-payments This is an example of a cart title in the default.php file for the cart view. ```php
``` -------------------------------- ### VM Plugin Trigger Example Source: https://docs.virtuemart.net/virtuemart-technics/why-you-should-use-vmplugin Demonstrates a historical plugin trigger function for VirtueMart. This pattern was used in earlier versions and is shown for context. ```php function plgVmOnStoreInstallPaymentPluginTable ($jplugin_id) { return $this->onStoreInstallPluginTable ($jplugin_id); } ``` -------------------------------- ### Example Language File Entry Source: https://docs.virtuemart.net/manual/general-concepts/multilanguage-and-multlingual This is how a language key and its corresponding display text are stored in a VirtueMart language file. ```ini COM_VIRTUEMART_CART_ADD_TO="Add to Cart" ``` -------------------------------- ### VM2 DisplayInOrderBE Trigger Example Source: https://docs.virtuemart.net/tutorials/development/code-adjustments-for-virtuemart-3 This is an example of the 'plgVmDisplayInOrderBE' trigger function in VirtueMart 2, used for displaying order details in the backend. ```php function plgVmDisplayInOrderBE(&$item, $productCustom, &$html) { if(!empty($productCustom)){ $item->productCustom = $productCustom; } if (empty($item->productCustom->custom_element) or $item->productCustom->custom_element != $this->_name) return ''; $this->plgVmOnViewCart($item,$productCustom,$html); //same render as cart } ``` -------------------------------- ### Example of Setting a Hidden Configuration Parameter Source: https://docs.virtuemart.net/manual/general-concepts/hidden-configurations This example shows how to change a default value for a hidden configuration parameter within the virtuemart.cfg file. This is useful for expert settings or parameters without a GUI. ```ini myvalue=mydefaultvalue ``` -------------------------------- ### Language Key Lookup Example Source: https://docs.virtuemart.net/manual/general-concepts/multilanguage-and-multlingual Illustrates the lookup process for a backend message, combining a generic save message with a specific controller title. ```php vmText::sprintf('COM_VIRTUEMART_STRING_SAVED','COM_VIRTUEMART_CONTROLLER_PRODUCT'); ``` -------------------------------- ### Checkout VirtueMart Repository Source: https://docs.virtuemart.net/tutorials/development/svn-download Use this SVN command to fetch the entire VirtueMart repository to your local computer. Ensure you have an SVN client installed. ```bash svn co https://dev.virtuemart.net/svn/virtuemart virtuemart ``` -------------------------------- ### Simple JavaScript Addition Source: https://docs.virtuemart.net/virtuemart-technics/the-vm-javascript-handler A basic example of adding a JavaScript component by its name. This is typically used for pre-registered scripts. ```php vmJsApi::addJScript('facebox'); ``` -------------------------------- ### VM3 DisplayInOrderBEVM3 Trigger Example Source: https://docs.virtuemart.net/tutorials/development/code-adjustments-for-virtuemart-3 This is an example of the 'plgVmDisplayInOrderBEVM3' trigger function in VirtueMart 3, used for displaying order details in the backend. It now calls the VM3 cart function. ```php function plgVmDisplayInOrderBEVM3(&$item, &$productCustom, &$html) { $this->plgVmOnViewCartVM3($item,$productCustom,$html); } ``` -------------------------------- ### Change Directory to Build Scripts Source: https://docs.virtuemart.net/tutorials/development/svn-download Navigate to the SVN build scripts directory using the 'cd' command in the terminal. This is the starting point for running Ant. ```bash > cd C:\joomla\VirtueMart\svn\build_scripts ``` -------------------------------- ### Plugin Overridable Pattern Example Source: https://docs.virtuemart.net/tutorials/templating-layouts/how-to-overwrite-plugins Check if a plugin is overridable by looking for a second folder with the same name within its directory. This indicates the plugin uses the overridable pattern. ```text /plugins/vmcustom/textinput /plugins/vmcustom/textinput/textinput ``` -------------------------------- ### SQL Language Fallback Example Source: https://docs.virtuemart.net/virtuemart-technics/the-vmlanguage-system-under-the-hood This SQL query demonstrates the fallback mechanism, prioritizing a specific language field over the default language field when data is missing. It's crucial for maintaining data consistency across different languages. ```sql SELECT IFNULL(l.'.$langField.','ld.'.$langField) FROM lang1 as l LEFT JOIN langDefault as ld ON l.$idField=ld.$idField WHERE $idField = "id" ``` -------------------------------- ### VmPlugin Constructor Configuration Source: https://docs.virtuemart.net/virtuemart-technics/why-you-should-use-vmplugin Illustrates how to configure parameters and data handling within the vmPlugin constructor. Use this to define which variables to push, core variable additions, and data conversion rules. ```php $varsToPush = $this->getVarsToPush (); $this->addVarsToPushCore($varsToPush,1); $this->setConfigParameterable ($this->_configTableFieldName, $varsToPush); $this->setConvertable(array('min_amount','max_amount','cost_per_transaction','cost_min_transaction')); ``` -------------------------------- ### Best Practice for Loading VirtueMart Configuration Source: https://docs.virtuemart.net/tutorials/development/how-to-fix-fatal-error-cannot-declare-class-name-is-already-in-use This code block demonstrates the recommended best practice for loading the VirtueMart configuration, including a check for the existence of the config file and error handling. ```php if (file_exists(JPATH_ROOT.DS.'administrator/components/com_virtuemart/helpers/config.php')) { if (!class_exists( 'VmConfig' )) require(JPATH_ROOT .'/administrator/components/com_virtuemart/helpers/config.php'); VmConfig::loadConfig(); } else { $app = JFactory::getApplication(); $app->enqueueMessage('Virtuemart not installed for'.get_class($this).', return','error'); return false; } ``` -------------------------------- ### VM2 OnViewCart Trigger Example Source: https://docs.virtuemart.net/tutorials/development/code-adjustments-for-virtuemart-3 This is an example of the 'plgVmOnViewCart' trigger function in VirtueMart 2, used for displaying custom product details in the cart. ```php function plgVmOnViewCart($product,$row,&$html) { if (empty($product->productCustom->custom_element) or $product->productCustom->custom_element != $this->_name) return ''; if (!$plgParam = $this->GetPluginInCart($product)) return '' ; foreach($plgParam as $k => $item){ if(!empty($item['comment']) ){ if($product->productCustom->virtuemart_customfield_id==$k){ $html .=''.JText::_($product->productCustom->custom_title).' '.$item['comment'].''; } } } return true; } ``` -------------------------------- ### VM3 OnViewCartVM3 Trigger Example Source: https://docs.virtuemart.net/tutorials/development/code-adjustments-for-virtuemart-3 This is an example of the 'plgVmOnViewCartVM3' trigger function in VirtueMart 3, used for displaying custom product details in the cart. Note the changed parameters and data access. ```php function plgVmOnViewCartVM3(&$product, &$productCustom, &$html) { if (empty($productCustom->custom_element) or $productCustom->custom_element != $this->_name) return false; if(empty($product->customProductData[$productCustom->virtuemart_custom_id][$productCustom->virtuemart_customfield_id])) return false; foreach( $product->customProductData[$productCustom->virtuemart_custom_id] as $k =>$item ) { if($productCustom->virtuemart_customfield_id == $k) { if(isset($item['comment'])){ $html .=''.JText::_($productCustom->custom_title).' '.$item['comment'].''; } } } return true; } ``` -------------------------------- ### Backward Compatible checkConditions for VM 3.6+ Source: https://docs.virtuemart.net/tutorials/development/236-update-payment-shipment-plugin-using-new-core-restrictions.html Simplifies the 'checkConditions' function for VM 3.6+ core by directly calling the parent function if 'getST' method exists. ```php if(method_exists($cart,'getST')){ return parent::checkConditions($cart, $method, $cart_prices); } ``` -------------------------------- ### Run Ant for Complete Package Build Source: https://docs.virtuemart.net/tutorials/development/svn-download Execute the Ant build script to create a complete VirtueMart package. Ensure the Ant executable path is correct. ```bash >"C:\Program Files\apache-ant\bin\ant.bat" virtuemart_complete ``` -------------------------------- ### Get Already Loaded JavaScript Source: https://docs.virtuemart.net/virtuemart-technics/the-vm-javascript-handler Retrieves a list of all JavaScript that has already been loaded. This can be useful for debugging or modifying existing scripts. ```php $js = vmJsApi::getJScripts(); ``` -------------------------------- ### Correctly Load VirtueMart Configuration Source: https://docs.virtuemart.net/tutorials/development/how-to-fix-fatal-error-cannot-declare-class-name-is-already-in-use Add this line to your main file or constructor to properly load the VirtueMart configuration, ensuring correct autoloading and preventing class conflicts. ```php VmConfig::loadConfig(); ``` -------------------------------- ### VmExtendedPlugin Constructor Source: https://docs.virtuemart.net/tutorials/development/extension-plugins The constructor for VmExtendedPlugin initializes the plugin, sets its path, and loads the language file. This is a base class for all extension plugins. ```php public function __construct (&$subject, $config=array()) { parent::__construct($subject, $config); $this->_path = JPATH_PLUGINS.DS.$this->getName(); JPlugin::loadLanguage('plg_vmextended_'.$this->getName()); } ``` -------------------------------- ### Constructor Parameter Handling for VM2 vs VM3 Source: https://docs.virtuemart.net/tutorials/development/code-adjustments-for-virtuemart-3 Use this switch in your custom plugin's constructor to handle configuration parameters differently based on the VirtueMart version. VM3 uses 'customfield_params' while VM2 uses 'custom_params'. ```php if(!defined('VM_VERSION') or VM_VERSION < 3){ $this->setConfigParameterable ('custom_params', $varsToPush); } else { $this->setConfigParameterable ('customfield_params', $varsToPush); } ``` -------------------------------- ### Update checkConditions for PayPal Plugin Source: https://docs.virtuemart.net/tutorials/development/236-update-payment-shipment-plugin-using-new-core-restrictions.html Example of updating the 'checkConditions' function for plugins like PayPal, which have specific extra restrictions to test before calling the parent function. ```php protected function checkConditions($cart, $activeMethod, $cart_prices) { //Check method publication start if ($activeMethod->publishup) { $nowDate = JFactory::getDate(); $publish_up = JFactory::getDate($activeMethod->publishup); if ($publish_up->toUnix() > $nowDate->toUnix()) { return FALSE; } } if ($activeMethod->publishdown) { $nowDate = JFactory::getDate(); $publish_down = JFactory::getDate($activeMethod->publishdown); if ($publish_down->toUnix() <= $nowDate->toUnix()) { return FALSE; } } return parent::checkConditions($cart, $activeMethod, $cart_prices); } ```