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

Add Plugins (a template and awocoupon) for custom variables

parent 422d5b50
No related branches found
No related tags found
No related merge requests found
Showing
with 433 additions and 0 deletions
BASE=awocoupon
PLUGINTYPE=vmshipmentrules
ZIPBASE=opentools_$(PLUGINTYPE)
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');
/**
* AwoCoupon variables for VM Shipping by Rules
*
* @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 "Shipping by Rules" shipping plugin for VirtueMart
*/
class plgVmShipmentRulesRules_AwoCoupon extends VmPlugin {
/** Trigger to add variables to the cart values
* You can add new variables to the $cartvals array or modify existing ones. They will be directly
* available in all rules.
* Please notice that this function might also be called for only a subset of products of the cart.
*/
function onVmShippingRulesGetCartValues(&$cartvals, $cart, $products, $method, $cart_prices) {
$coupon_discount = 0;
$session = JFactory::getSession();
$coupon_row = $session->get('coupon', '', 'awocoupon');
if(!empty($coupon_row)) {
$coupon_row = unserialize($coupon_row);
$coupon_discount = $coupon_row['product_discount'] + $coupon_row['shipping_discount'];
}
$cartvals['awodiscount'] = $coupon_discount;
}
}
// No closing tag
<?php
defined('_JEXEC') or die('Restricted access');
// TODO: Adjust your plugin name:
$pluginname='awocoupon';
$plugintype='vmshipmentrules';
/**
* 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
*/
// TODO: Adjust the class name. It has to be of the form:
// plgVmShipmentYOUR_PLUGIN_NAMEInstallerScript
class plgVmShipmentRulesAwoCouponInstallerScript
{
/**
* 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 = "'.$pluginname.'" and folder = "'.$plugintype.'"');
$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_".$plugintype."_".$pluginname.".sys.ini";
// if (JFile::exists($file)) JFile::delete($file);
// $file = JPATH_ROOT . DS . "administrator" . DS . "language" . DS . "de-DE" . DS . "de-DE.plg_".$plugintype."_".$pluginname.".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_'.$plugintype.'_plg_'.$pluginname.'`;');
// $db->query();
// }
}
<?xml version="1.0" encoding="UTF-8" ?>
<extension version="1.5" type="plugin" group="vmshipmentrules" method="upgrade">
<name>VMSHIPMENTRULES_AWOCOUPON</name>
<creationDate>2014-11-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>VMSHIPMENTRULES_AWOCOUPON_DESC</description>
<files>
<filename plugin="awocoupon">awocoupon.php</filename>
<folder>language</folder>
</files>
<languages folder="language">
<language tag="en-GB">en-GB/en-GB.plg_vmshipmentrules_awocoupon.ini</language>
<language tag="en-GB">en-GB/en-GB.plg_vmshipmentrules_awocoupon.sys.ini</language>
</languages>
<scriptfile>awocoupon.script.php</scriptfile>
<!-- VM 3.x support (fields rather than params): -->
<vmconfig></vmconfig>
<!-- VM 2.0 support (params rather than fields): -->
<params></params>
</extension>
; VM Rule-based Shipping plugin: Access to AwoCoupon variables
; 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
VMSHIPMENTRULES_AWOCOUPON="AwoCoupon variables for VM Shipping by Rules"
VMSHIPMENTRULES_AWOCOUPON_DESC="This plugin provides access to the AwoCoupon discounts in the Shipping by Rules plugin for VirtueMart."
; VM Rule-based Shipping plugin: Access to AwoCoupon variables
; 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
VMSHIPMENTRULES_AWOCOUPON="AwoCoupon variables for VM Shipping by Rules"
VMSHIPMENTRULES_AWOCOUPON_DESC="This plugin provides access to the AwoCoupon discounts in the Shipping by Rules plugin for VirtueMart."
<!DOCTYPE html><title></title>
<!DOCTYPE html><title></title>
File added
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 VM Shipping by Rules
*
* @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 "Shipping by Rules" shipping plugin for VirtueMart
*/
class plgVmShipmentRulesYOUR_PLUGIN_NAME extends VmPlugin {
/** Trigger to add variables to the cart values
* You can add new variables to the $cartvals array or modify existing ones. They will be directly
* available in all rules.
* Please notice that this function might also be called for only a subset of products of the cart.
*/
function onVmShippingRulesGetCartValues(&$cartvals, $cart, $products, $method, $cart_prices) {
$cartvals['template_example'] = 123456789;
}
/** Trigger to register custom functions for the Shipping by Rules plugin
* The onVmShippingRulesRegisterCustomFunctions() trigger is expected to return an array of the form:
* array ('functionname1' => 'function_to_be_called',
* 'functionname2' => array($classobject, 'memberfunc')),
* ...);
* The functions referenced here are called with exactly one array argument, that holds
* all function arguments, i.e. the function signature should be
* function function_to_be_called($args) {....}
*/
function onVmShippingRulesRegisterCustomFunctions() {
return array('customTestFunction' => array($this, 'custom_test_function'));
}
function custom_test_function($args) {
return 'Test return value...';
}
}
// 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:
// plgVmShipmentYOUR_PLUGIN_NAMEInstallerScript
class plgVmShipmentRulesYOUR_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 = "vmshipmentrules"');
$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="1.5" type="plugin" group="vmshipmentrules" method="upgrade">
<name>VMSHIPMENTRULES_TEMPLATE</name>
<creationDate>2014-11-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>VMSHIPMENTRULES_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_vmshipmentrules_YOUR_PLUGIN_NAME.ini</language>
<language tag="en-GB">en-GB/en-GB.plg_vmshipmentrules_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 Shipping by Rules 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/VMSHIPMENTRULES_TEMPLATE/VMSHIPMENTRULES_$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/VMSHIPMENTRULES_TEMPLATE/VMSHIPMENTRULES_$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 Shipping for Rules plugin. Please adjust the plugin's onVmShippingRulesGetCartValues, all copyright statements and the translations"
\ No newline at end of file
; VM Rule-based Shipping 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
VMSHIPMENTRULES_TEMPLATE="VM Shipping by Rules Extension Template"
VMSHIPMENTRULES_TEMPLATE_DESC="This plugin is just a demo template that highlights how one can extend the Shipping by Rules plugin with a plugin of type vmshipmentrules. If installed, it does not do anything useful or harmful."
; VM Rule-based Shipping 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
VMSHIPMENTRULES_TEMPLATE="VM Shipping by Rules Extension Template"
VMSHIPMENTRULES_TEMPLATE_DESC="This plugin is just a demo template that highlights how one can extend the Shipping by Rules plugin with a plugin of type vmshipmentrules. 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