Skip to content
Snippets Groups Projects
Commit c4556fcb authored by Reinhold Kainhofer's avatar Reinhold Kainhofer
Browse files

Add plugin framework for custom variables: trigger...

Add plugin framework for custom variables: trigger onVmOrdernumberGetVariables(&$reps, $fmt, $nrtype, $details)
parent ff2185d7
No related branches found
No related tags found
No related merge requests found
BASE=ordernumber
PLUGINTYPE=vmshopper
VERSION=2.0
VERSION=2.1
PLUGINFILES=$(BASE).php $(BASE).script.php $(BASE).xml index.html $(BASE)/
......
......@@ -182,6 +182,8 @@ class plgVmShopperOrdernumber extends vmShopperPlugin {
if (isset($details->name)) $reps["[name]"] = $details->name;
if (isset($details->user_is_vendor)) $reps["[user_is_vendor]"] = $details->user_is_vendor;
}
JPluginHelper::importPlugin('vmshopper');
JDispatcher::getInstance()->trigger('onVmOrdernumberGetVariables',array(&$reps, $fmt, $nrtype, $details));
return str_ireplace (array_keys($reps), array_values($reps), $fmt);
}
......
......@@ -7,8 +7,8 @@
<authorUrl>http://www.open-tools.net/</authorUrl>
<copyright>Copyright (C) 2012-2014 Reinhold Kainhofer. All rights reserved.</copyright>
<license>http://www.gnu.org/licenses/gpl-3.0.html GNU/GPLv3</license>
<version>1.90</version>
<releaseDate>2014-10-05</releaseDate>
<version>2.1</version>
<releaseDate>2014-12-07</releaseDate>
<releaseType>Minor update</releaseType>
<downloadUrl>http://www.open-tools.net/virtuemart-2-extensions/vm2-ordernumber-plugin.html</downloadUrl>
......
BASE=YOUR_PLUGIN_NAME
PLUGINTYPE=vmshipmentrules
ZIPBASE=opentools_vmshipmentrules
VERSION=1.0
PLUGINFILES=$(BASE).php $(BASE).script.php $(BASE).xml index.html
TRANSLATIONS=$(call wildcard,language/en*/*.plg_$(PLUGINTYPE)_$(BASE).*ini)
INDEXFILES=language/index.html $(call wildcard,language/**/index.html)
ZIPFILE=plg_$(ZIPBASE)_$(BASE)_v$(VERSION).zip
all: zip
zip: $(PLUGINFILES) $(TRANSLATIONS) $(ADVANCEDFILES) $(INDEXFILES)
@echo "Packing all files into distribution file $(ZIPFILE):"
@zip -r $(ZIPFILE) $(PLUGINFILES) $(TRANSLATIONS) $(INDEXFILES)
clean:
rm -f $(ZIPFILE)
<?php
defined ('_JEXEC') or die('Restricted access');
/**
* Plugin providing Custom variables for the VM Ordernumber plugin
*
* @subpackage Plugins - VmShipmentRules
* @copyright Copyright (C) 2014 Reinhold Kainhofer, office@open-tools.net
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
* VirtueMart is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See administrator/components/com_virtuemart/COPYRIGHT.php for copyright notices and details.
*
* http://open-tools.net/
*
*/
if (!class_exists ('VmPlugin')) {
require(JPATH_VM_PLUGINS . DS . 'vmplugin.php');
}
/** Extension plugin for the Odernumber plugin for VirtueMart
*/
class plgVmShopperYOUR_PLUGIN_NAME extends VmPlugin {
/** Trigger to add variables to be used in the number formats
* You can add new variables to the $cartvals array or modify existing ones. They will be directly
* available in all formats. This trigger will be called whenever the ordernumber plugin creates a
* number. All built-in variables are already set in the $reps variable, so you can even override
* the built-in variables by changing $reps accordingly.
* $nrtype is 0 for ordernumber, 1 for invoice number, 2 for customer number and 3 for order password
* $details contains the order details
*/
function onVmOrdernumberGetVariables(&$reps, $fmt, $nrtype, $details) {
// As an example add a variable [type] that contains the number type:
switch ($nrtype) {
case 0: $reps['type'] = "Order"; break;
case 1: $reps['type'] = "Invoice"; break;
case 2: $reps['type'] = "Customer"; break;
case 3: $reps['type'] = "OrderPassword"; break;
}
// Another example: set the ip address:
if (isset($details->ip_address)) $reps["[ipaddress]"] = $details->ip_address;
// You can also modify existing variables:
$reps['[second]'] = $reps['[second]'] + 15;
}
}
// No closing tag
<?php
defined('_JEXEC') or die('Restricted access');
/**
* Installation script for the plugin
*
* @copyright Copyright (C) 2014 Reinhold Kainhofer, office@open-tools.net
* @license GPL v3+, http://www.gnu.org/copyleft/gpl.html
*/
// Adjust the class name. It has to be of the form:
// plgVmShopperYOUR_PLUGIN_NAMEInstallerScript
class plgVmShopperYOUR_PLUGIN_NAMEInstallerScript
{
/**
* Constructor
*
* @param JAdapterInstance $adapter The object responsible for running this script
*/
// public function __constructor(JAdapterInstance $adapter);
/**
* Called before any type of action
*
* @param string $route Which action is happening (install|uninstall|discover_install)
* @param JAdapterInstance $adapter The object responsible for running this script
*
* @return boolean True on success
*/
// public function preflight($route, JAdapterInstance $adapter);
/**
* Called after any type of action
*
* @param string $route Which action is happening (install|uninstall|discover_install)
* @param JAdapterInstance $adapter The object responsible for running this script
*
* @return boolean True on success
*/
// public function postflight($route, JAdapterInstance $adapter);
/**
* Called on installation
*
* @param JAdapterInstance $adapter The object responsible for running this script
*
* @return boolean True on success
*/
public function install(JAdapterInstance $adapter)
{
// enabling plugin upon installation
$db =& JFactory::getDBO();
$db->setQuery('update #__extensions set enabled = 1 where type = "plugin" and element = "YOUR_PLUGIN_NAME" and folder = "vmshopper"');
$db->query();
return True;
}
/**
* Called on update
*
* @param JAdapterInstance $adapter The object responsible for running this script
*
* @return boolean True on success
*/
// public function update(JAdapterInstance $adapter)
// {
// jimport( 'joomla.filesystem.file' );
// $file = JPATH_ROOT . DS . "administrator" . DS . "language" . DS . "en-GB" . DS . "en-GB.plg_vmshipmentrules_YOUR_PLUGIN_NAME.sys.ini";
// if (JFile::exists($file)) JFile::delete($file);
// $file = JPATH_ROOT . DS . "administrator" . DS . "language" . DS . "de-DE" . DS . "de-DE.plg_vmshipmentrules_YOUR_PLUGIN_NAME.sys.ini";
// if (JFile::exists($file)) JFile::delete($file);
// return true;
// }
/**
* Called on uninstallation
*
* @param JAdapterInstance $adapter The object responsible for running this script
*/
// public function uninstall(JAdapterInstance $adapter)
// {
// // Remove plugin table
// $db =& JFactory::getDBO();
// $db->setQuery('DROP TABLE IF EXISTS `#__virtuemart_vmshipmentrulesles_YOUR_PLUGIN_NAME`;');
// $db->query();
// }
}
<?xml version="1.0" encoding="UTF-8" ?>
<extension version="2.5" type="plugin" group="vmshopper" method="upgrade">
<name>VMORDERNUMBER_TEMPLATE</name>
<creationDate>2014-12-10</creationDate>
<author>Reinhold Kainhofer, Open Tools</author>
<authorUrl>http://www.open-tools.net</authorUrl>
<copyright>Copyright (C) 2014, Reinhold Kainhofer</copyright>
<license>GPL v3+</license>
<version>1.0</version>
<description>VMORDERNUMBER_TEMPLATE_DESC</description>
<files>
<filename plugin="YOUR_PLUGIN_NAME">YOUR_PLUGIN_NAME.php</filename>
<folder>language</folder>
</files>
<languages folder="language">
<language tag="en-GB">en-GB/en-GB.plg_vmshopper_YOUR_PLUGIN_NAME.ini</language>
<language tag="en-GB">en-GB/en-GB.plg_vmshopper_YOUR_PLUGIN_NAME.sys.ini</language>
</languages>
<scriptfile>YOUR_PLUGIN_NAME.script.php</scriptfile>
<!-- VM 3.x support (fields rather than params): -->
<vmconfig></vmconfig>
<!-- VM 2.0 support (params rather than fields): -->
<params></params>
</extension>
#!/bin/bash
SRCDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
ARGC=$#
if [ $ARGC -lt 1 ]; then
echo "Usage: $0 YourPluginName"
echo "Create a proper plugin for the Ordernumber plugin from the provided template"
exit -1;
fi
name=$1
pluginname=${name,,}
pLUGINNAME=${name,}
Pluginname=${name^}
PLUGINNAME=${name^^}
echo "Plugin name=$name, pluginname=$pluginname, pLUGINNAME=$pLUGINNAME, Pluginname=$Pluginname, PLUGINNAME=$PLUGINNAME"
mkdir -p $pluginname/language/en-GB/
sed "s/YOUR_PLUGIN_NAME/$Pluginname/g" $SRCDIR/YOUR_PLUGIN_NAME.php > $pluginname/$pluginname.php
sed "s/YOUR_PLUGIN_NAMEInstaller/${Pluginname}Installer/g; s/YOUR_PLUGIN_NAME/$pluginname/g" $SRCDIR/YOUR_PLUGIN_NAME.script.php > $pluginname/$pluginname.script.php
sed "s/YOUR_PLUGIN_NAME/$pluginname/g; s/VMORDERNUMBER_TEMPLATE/VMORDERNUMBER_$PLUGINNAME/g" $SRCDIR/YOUR_PLUGIN_NAME.xml > $pluginname/$pluginname.xml
sed "s/YOUR_PLUGIN_NAME/$pluginname/g" $SRCDIR/Makefile > $pluginname/Makefile
for i in $SRCDIR/language/en-GB/*.ini; do
sed "s/YOUR_PLUGIN_NAME/$pluginname/g; s/VMORDERNUMBER_TEMPLATE/VMORDERNUMBER_$PLUGINNAME/g" $i > $pluginname/${i#$SRCDIR}
done
rename "s/YOUR_PLUGIN_NAME/$pluginname/g" $pluginname/language/en-GB/*
for i in `find $SRCDIR/ -name index.html`; do
cp $i $pluginname/${i#$SRCDIR}
done
echo "Created new plugin '$pluginname' for the Ordernumber plugin. Please adjust the plugin's onVmOrdernumberGetVariables, all copyright statements and the translations"
\ No newline at end of file
; VM Ordernumber plugin: Template for extension plugins
; Copyright (C) 2014 Reinhold Kainhofer, Open Tools. All rights reserved.
; License http://www.gnu.org/licenses/gpl.html GNU/GPL
; Note : All ini files need to be saved as UTF-8 - No BOM
VMORDERNUMBER_TEMPLATE="VM Ordernumber Extension Template"
VMORDERNUMBER_TEMPLATE_DESC="This plugin is just a demo template that highlights how one can extend the Ordernumber plugin with a plugin of type vmshopper. If installed, it does not do anything useful or harmful."
; VM Ordernumber plugin: Template for extension plugins
; Copyright (C) 2014 Reinhold Kainhofer, Open Tools. All rights reserved.
; License http://www.gnu.org/licenses/gpl.html GNU/GPL
; Note : All ini files need to be saved as UTF-8 - No BOM
VMORDERNUMBER_TEMPLATE="VM Ordernumber Extension Template"
VMORDERNUMBER_TEMPLATE_DESC="This plugin is just a demo template that highlights how one can extend the Ordernumber plugin with a plugin of type vmshopper. If installed, it does not do anything useful or harmful."
<!DOCTYPE html><title></title>
<!DOCTYPE html><title></title>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment