diff --git a/Makefile b/Makefile index 7ebf7a4013140b5a65b5023ca8f49f6d8444f3c3..55c67b4cea5b79489351d318d045bb556c03d6dd 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,7 @@ -BASE=donation +BASE=nametheprice PLUGINTYPE=vmcustom -VERSION=1.1.0 +VERSION=1.2 +FILEBASE=opentools_vm2 PLUGINFILES=$(BASE).php $(BASE).script.php $(BASE).xml index.html @@ -8,7 +9,7 @@ TRANSLATIONS=$(call wildcard,language/*/*.plg_$(PLUGINTYPE)_$(BASE).*ini) INDEXFILES=language/index.html $(call wildcard,language/*/index.html) TMPLFILES=$(call wildcard,$(BASE)/tmpl/*.php) $(call wildcard,$(BASE)/tmpl/index.html) $(call wildcard,$(BASE)/index.html) ASSETS= -ZIPFILE=plg_$(PLUGINTYPE)_$(BASE)_v$(VERSION).zip +ZIPFILE=plg_$(FILEBASE)_$(BASE)_v$(VERSION).zip zip: $(PLUGINFILES) $(TRANSLATIONS) $(ELEMENTS) $(INDEXFILES) $(TMPLFILES) $(ASSETS) diff --git a/donation.php b/donation.php deleted file mode 100644 index 4c85ac6fdd41e887cc49bc02675341cf79e89ff3..0000000000000000000000000000000000000000 --- a/donation.php +++ /dev/null @@ -1,175 +0,0 @@ -<?php -/**------------------------------------------------------------------------ -# donation.php - VirtueMart 2 plugin for donations -# ------------------------------------------------------------------------ -# @author Reinhold Kainhofer, The Open Tools Association -# @copyright Copyright (C) 2013 Reinhold Kainhofer, open-tools.net. All Rights Reserved. -# @license - http://www.gnu.org/licenses/gpl.html GNU/GPL -* @package VirtueMart -* @subpackage vmcustom -# Websites: http://www.open-tools.net/ -# Technical Support: Forum - http://www.open-tools.net/forum/index.html --------------------------------------------------------------------------*/ -// no direct access -defined('_JEXEC') or die( 'Direct Access to ' . basename( __FILE__ ) . ' is not allowed.' ) ; - -if (!class_exists('vmCustomPlugin')) require(JPATH_VM_PLUGINS . DS . 'vmcustomplugin.php'); -// if(!class_exists('VmTable'))require(JPATH_VM_ADMINISTRATOR.DS.'helpers'.DS.'vmtable.php'); - -if (JVM_VERSION === 2) { - if (!defined('VMDONATION_PLUGINPATH')) define('VMDONATION_PLUGINPATH', JPATH_SITE.DS.'plugins'.DS.'vmcustom'.DS.'donation'); - if (!defined('VMDONATION_PLUGINWEBROOT')) define('VMDONATION_PLUGINWEBROOT', 'plugins/vmcustom/donation'); -} else { - if (!defined('VMDONATION_PLUGINPATH')) define('VMDONATION_PLUGINPATH', JPATH_SITE.DS.'plugins'.DS.'vmcustom'); - if (!defined('VMDONATION_PLUGINWEBROOT')) define('VMDONATION_PLUGINWEBROOT', 'plugins/vmcustom'); -} - -class plgVmCustomDonation extends vmCustomPlugin { - - function __construct(& $subject, $config) { - parent::__construct($subject, $config); - $varsToPush = array( - 'min_amount'=>array('0.0', 'char'), - 'max_amount'=>array('', 'char'), - ); - $this->setConfigParameterable('custom_params',$varsToPush); - } - - /** - * @see Form displayed in the product edit page in the BE, configure the download file - * @author Reinhold Kainhofer - */ - function plgVmOnProductEdit($field, $product_id, &$row,&$retValue) { - if ($field->custom_element != $this->_name) return ''; - - $this->parseCustomParams($field); - $html =' - <fieldset> - <legend>'. JText::_('VMCUSTOM_DONATION') .'</legend> - <table class="admintable"> - '.VmHTML::row('input','VMCUSTOM_DONATION_MIN','custom_param['.$row.'][min_amount]',$field->min_amount). - VmHTML::row('input','VMCUSTOM_DONATION_MAX','custom_param['.$row.'][max_amount]',$field->max_amount). - '<tr> - </table> - </fieldset>'; - $retValue .= $html; - $row++; - return true ; - } - - /** - * plgVmOnDisplayProductVariantFE ... Called for product variant custom fields to display on the product details page - */ - function plgVmOnDisplayProductVariantFE($field,&$row,&$group) { - // default return if it's not this plugin - if ($field->custom_element != $this->_name) return ''; - $this->getCustomParams($field); - $group->display .= $this->renderByLayout('default',array($field,&$idx,&$group ) ); - return true; - } - - /** - * @see components/com_virtuemart/helpers/vmCustomPlugin::plgVmOnViewCartModule() - * @author Patrick Kohl - */ - function plgVmOnViewCartModule( $product,$row,&$html) { - return $this->plgVmOnViewCart($product,$row,$html); - } - - /** - * @see components/com_virtuemart/helpers/vmCustomPlugin::plgVmOnViewCart() - * @author Patrick Kohl - */ - 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['customprice']) && ($product->productCustom->virtuemart_customfield_id==$k)){ - $currency = CurrencyDisplay::getInstance (); - $html .='<span>'.JText::_($product->productCustom->custom_title).' '.$currency->priceDisplay($item['customprice']).'</span>'; - } - } - return true; - } - - - /** - * vendor order display BE - */ - function plgVmDisplayInOrderBE($item, $row, &$html) { - if (empty($item->productCustom->custom_element) or $item->productCustom->custom_element != $this->_name) return ''; - $this->plgVmOnViewCart($item,$row,$html); //same render as cart - } - - /** - * - * shopper order display FE - */ - function plgVmDisplayInOrderFE($item, $row, &$html) { - if (empty($item->productCustom->custom_element) or $item->productCustom->custom_element != $this->_name) return ''; - $this->plgVmOnViewCart($item,$row,$html); //same render as cart - } - - /** - * We must reimplement this triggers for joomla 1.7 - * vmplugin triggers note by Max Milbers - */ - public function plgVmOnStoreInstallPluginTable($psType, $name) { - //Should the textinput use an own internal variable or store it in the params? - //Here is no getVmPluginCreateTableSQL defined -// return $this->onStoreInstallPluginTable($psType); - } - - - function plgVmDeclarePluginParamsCustom($psType,$name,$id, &$data){ - return $this->declarePluginParams('custom', $name, $id, $data); - } - - function plgVmSetOnTablePluginParamsCustom($name, $id, &$table){ - return $this->setOnTablePluginParams($name, $id, $table); - } - - /** - * Custom triggers note by Max Milbers - */ - function plgVmOnDisplayEdit($virtuemart_custom_id,&$customPlugin){ - return $this->onDisplayEditBECustom($virtuemart_custom_id,$customPlugin); - } - - public function plgVmCalculateCustomVariant($product, &$productCustomsPrice, $selected){ - if ($productCustomsPrice->custom_element !==$this->_name) return ; - $customVariant = $this->getCustomVariant($product, $productCustomsPrice, $selected); - // TODO: Implement bounds for "donation": max/min value. - if (!empty($customVariant['customprice'])) { - if (!empty($productCustomsPrice->min_amount) && ($customVariant['customprice']<$productCustomsPrice->min_amount)) { - $customVariant['customprice'] = $productCustomsPrice->min_amount; - } - if (!empty($productCustomsPrice->max_amount) && ($customVariant['customprice']<$productCustomsPrice->max_amount)) { - $customVariant['customprice'] = $productCustomsPrice->max_amount; - } - -// if ($customVariant['customprice']<0) { -// $customVariant['customprice'] = 0; -// } - $productCustomsPrice->custom_price = $customVariant['customprice']; - } else { - $productCustomsPrice->custom_price = 0.0; - } - return true; - } - - public function plgVmDisplayInOrderCustom(&$html,$item, $param,$productCustom, $row ,$view='FE'){ - $this->plgVmDisplayInOrderCustom($html,$item, $param,$productCustom, $row ,$view); - } - - public function plgVmCreateOrderLinesCustom(&$html,$item,$productCustom, $row ){ -// $this->createOrderLinesCustom($html,$item,$productCustom, $row ); - } - function plgVmOnSelfCallFE($type,$name,&$render) { - $render->html = ''; - } - -} - -// No closing tag \ No newline at end of file diff --git a/donation.xml b/donation.xml deleted file mode 100644 index 52b44f0f7066bf177b640a7f5ac9ea568092cad6..0000000000000000000000000000000000000000 --- a/donation.xml +++ /dev/null @@ -1,28 +0,0 @@ -<?xml version="1.0" encoding="UTF-8" ?> -<install version="1.5" type="plugin" group="vmcustom" method="upgrade"> - <name>VMCUSTOM_DONATION</name> - <creationDate>2013-03-02</creationDate> - <author>Reinhold Kainhofer</author> - <authorUrl>http://www.open-tools.net/</authorUrl> - <copyright>Copyright (C) 2013 Reinhold Kainhofer. All rights reserved.</copyright> - <license>http://www.gnu.org/licenses/gpl.html GNU/GPL v3+</license> - <version>1.1.0</version> - <description>VMCUSTOM_DONATION_DESC</description> - <files> - <filename plugin="donation">donation.php</filename> - <filename>donation.script.php</filename> - <folder>language</folder> - <folder>donation</folder> - <filename>index.html</filename> - </files> - <languages folder="language"> - <language tag="en-GB">en-GB/en-GB.plg_vmcustom_donation.ini</language> - <language tag="en-GB">en-GB/en-GB.plg_vmcustom_donation.sys.ini</language> - <language tag="de-DE">de-DE/de-DE.plg_vmcustom_donation.ini</language> - <language tag="de-DE">de-DE/de-DE.plg_vmcustom_donation.sys.ini</language> - </languages> - <scriptfile>donation.script.php</scriptfile> - <params addpath="/administrator/components/com_virtuemart/elements"> - <param type="vmjpluginwarning" /> - </params> -</install> diff --git a/donation/tmpl/default.php b/donation/tmpl/default.php deleted file mode 100644 index 13c65c316e7af9dce0e2e6881ab632c584f5727c..0000000000000000000000000000000000000000 --- a/donation/tmpl/default.php +++ /dev/null @@ -1,35 +0,0 @@ -<?php -/*------------------------------------------------------------------------ -# default.php - template for the donation input box -# ------------------------------------------------------------------------ -# author Reinhold Kainhofer, The Open Tools Association -# copyright Copyright (C) 2013 open-tools.net. All Rights Reserved. -# @license - http://www.gnu.org/licenses/gpl.html GNU/GPL -# Websites: http://www.open-tools.net/ -# Technical Support: Forum - http://www.open-tools.net/forum/index.html --------------------------------------------------------------------------*/ -// no direct access -defined( '_JEXEC' ) or die( 'Restricted access' ); - - $class='vmcustom-settext'; ?> - - <input class="<?php echo $class ?>" type="text" value="" size="4" name="customPlugin[<?php echo $viewData[0]->virtuemart_customfield_id ?>][<?php echo $this->_name?>][customprice]"><?php echo CurrencyDisplay::getInstance ()->getSymbol(); ?><br /> -<?php - // preventing 2 x load javascript - static $textinputjs; - if ($textinputjs) return true; - $textinputjs = true ; - //javascript to update price - $document = JFactory::getDocument(); - $document->addScriptDeclaration(' -/* <![CDATA[ */ -jQuery(document).ready( function($) { - jQuery(".vmcustom-textinput").keyup(function() { - formProduct = $(this).parents("form.product"); - virtuemart_product_id = formProduct.find(\'input[name="virtuemart_product_id[]"]\').val(); - Virtuemart.setproducttype(formProduct,virtuemart_product_id); - }); - -}); -/* ]]> */ - '); \ No newline at end of file diff --git a/images/donation_-_cart.png b/images/nameyourprice_-_cart.png similarity index 100% rename from images/donation_-_cart.png rename to images/nameyourprice_-_cart.png diff --git a/images/donation_-_customfield_product.png b/images/nameyourprice_-_customfield_product.png similarity index 100% rename from images/donation_-_customfield_product.png rename to images/nameyourprice_-_customfield_product.png diff --git a/images/donation_-_customfield_setup.png b/images/nameyourprice_-_customfield_setup.png similarity index 100% rename from images/donation_-_customfield_setup.png rename to images/nameyourprice_-_customfield_setup.png diff --git a/images/donation_-_icon.png b/images/nameyourprice_-_icon.png similarity index 100% rename from images/donation_-_icon.png rename to images/nameyourprice_-_icon.png diff --git a/images/donation_-_icon.xcf b/images/nameyourprice_-_icon.xcf similarity index 100% rename from images/donation_-_icon.xcf rename to images/nameyourprice_-_icon.xcf diff --git a/images/donation_-_productdetails.png b/images/nameyourprice_-_productdetails.png similarity index 100% rename from images/donation_-_productdetails.png rename to images/nameyourprice_-_productdetails.png diff --git a/images/donate.png b/images/nameyourpricedonate.png similarity index 100% rename from images/donate.png rename to images/nameyourpricedonate.png diff --git a/language/de-DE/de-DE.plg_vmcustom_donation.ini b/language/de-DE/de-DE.plg_vmcustom_donation.ini deleted file mode 100644 index 8f197810eece551c8a3f52e4db6de9afec85dc30..0000000000000000000000000000000000000000 --- a/language/de-DE/de-DE.plg_vmcustom_donation.ini +++ /dev/null @@ -1,12 +0,0 @@ -; Virtuemart! Project -; Copyright (C) 2011 Virtuemart Team. All rights reserved. -; License http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL, see LICENSE.php -; Note : All ini files need to be saved as UTF-8 - No BOM - -VMCUSTOM_DONATION="Spenden für VirtueMart" -VMCUSTOM_DONATION_DESC="VirtueMart Benutzerfeld Erweiterung, die Benutzern einen Spendenbetrag zum Produktpreis hinzufügen oder den Preis des Produktes selbst festlegen lässt." - -VMCUSTOM_DONATION_MIN="Minimaler Betrag" -VMCUSTOM_DONATION_MIN_TIP="Dies ist der minimale Betrag, der eingegeben werden kann. Kleinere Beträge werden auf diesen Wert gesetzt. Leer lassen (nicht auf 0 setzen!), um keine untere Schranke zu setzen. Auf 0 setzen, um negative Werte zu verhindern (Standardeinstellung)." -VMCUSTOM_DONATION_MAX="Maximaler Betrag" -VMCUSTOM_DONATION_MAX_TIP="Dies ist der maximale Betrag, der eingegeben werden kann. Größere Betrage werden auf diesen Wert gesetzt. Leer lassen (nicht auf 0 setzen!), um keine obere Schranke zu setzen. Auf 0 setzen, um nur negative Werte zu erlauben." diff --git a/language/de-DE/de-DE.plg_vmcustom_donation.sys.ini b/language/de-DE/de-DE.plg_vmcustom_donation.sys.ini deleted file mode 100644 index c82ed1dc372340ce3414a5b0aa044de80d7c868f..0000000000000000000000000000000000000000 --- a/language/de-DE/de-DE.plg_vmcustom_donation.sys.ini +++ /dev/null @@ -1,7 +0,0 @@ -; Virtuemart! Project -; Copyright (C) 2011 Virtuemart Team. All rights reserved. -; License http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL, see LICENSE.php -; Note : All ini files need to be saved as UTF-8 - No BOM - -VMCUSTOM_DONATION="Spenden für VirtueMart" -VMCUSTOM_DONATION_DESC="VirtueMart Benutzerfeld Erweiterung, die Benutzern einen Spendenbetrag zum Produktpreis hinzufügen oder den Preis des Produktes selbst festlegen lässt." diff --git a/language/de-DE/de-DE.plg_vmcustom_nametheprice.ini b/language/de-DE/de-DE.plg_vmcustom_nametheprice.ini new file mode 100644 index 0000000000000000000000000000000000000000..3771a092d8f0d607e6abf2b4ab3f0218387ccfd7 --- /dev/null +++ b/language/de-DE/de-DE.plg_vmcustom_nametheprice.ini @@ -0,0 +1,15 @@ +; Virtuemart! Project +; Copyright (C) 2011 Virtuemart Team. All rights reserved. +; License http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL, see LICENSE.php +; Note : All ini files need to be saved as UTF-8 - No BOM + +VMCUSTOM_NAMETHEPRICE="Nenn den Preis für VirtueMart" +VMCUSTOM_NAMETHEPRICE_DESC="VirtueMart Benutzerfeld Erweiterung, die Benutzern den Preis des Produktes selbst festlegen lässt (z.B. für Spenden oder Gutscheine)" + +VMCUSTOM_NAMETHEPRICE_MIN="Minimaler Betrag" +VMCUSTOM_NAMETHEPRICE_MIN_TIP="Dies ist der minimale Betrag, der eingegeben werden kann. Kleinere Beträge werden auf diesen Wert gesetzt. Leer lassen (nicht auf 0 setzen!), um keine untere Schranke zu setzen. Auf 0 setzen, um negative Werte zu verhindern (Standardeinstellung)." +VMCUSTOM_NAMETHEPRICE_MAX="Maximaler Betrag" +VMCUSTOM_NAMETHEPRICE_MAX_TIP="Dies ist der maximale Betrag, der eingegeben werden kann. Größere Betrage werden auf diesen Wert gesetzt. Leer lassen (nicht auf 0 setzen!), um keine obere Schranke zu setzen. Auf 0 setzen, um nur negative Werte zu erlauben." + +VMCUSTOM_NAMETHEPRICE_ERROR_MAX_EXCEEDED="Der angegebene Wert %d übersteigt das erlaubte Maximum, es wird stattdessen das Maximum %d benutzt."; +VMCUSTOM_NAMETHEPRICE_ERROR_MIN_EXCEEDED="Der angegebene Wert %d unterschreitet das erlaubte Minimum, es wird stattdessen das Minimum %d benutzt."; diff --git a/language/de-DE/de-DE.plg_vmcustom_nametheprice.sys.ini b/language/de-DE/de-DE.plg_vmcustom_nametheprice.sys.ini new file mode 100644 index 0000000000000000000000000000000000000000..d6ab8ae94dbef6c83fca1d35336327abf53790f1 --- /dev/null +++ b/language/de-DE/de-DE.plg_vmcustom_nametheprice.sys.ini @@ -0,0 +1,7 @@ +; Virtuemart! Project +; Copyright (C) 2011 Virtuemart Team. All rights reserved. +; License http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL, see LICENSE.php +; Note : All ini files need to be saved as UTF-8 - No BOM + +VMCUSTOM_NAMETHEPRICE="Nenn den Preis für VirtueMart" +VMCUSTOM_NAMETHEPRICE_DESC="VirtueMart Benutzerfeld Erweiterung, die Benutzern den Preis des Produktes selbst festlegen lässt (z.B. für Spenden oder Gutscheine)" diff --git a/language/en-GB/en-GB.plg_vmcustom_donation.ini b/language/en-GB/en-GB.plg_vmcustom_donation.ini deleted file mode 100644 index 79c20cea4a591896d9ba750877eefb4b5045ab7e..0000000000000000000000000000000000000000 --- a/language/en-GB/en-GB.plg_vmcustom_donation.ini +++ /dev/null @@ -1,13 +0,0 @@ -; Virtuemart! Project -; Copyright (C) 2011 Virtuemart Team. All rights reserved. -; License http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL, see LICENSE.php -; Note : All ini files need to be saved as UTF-8 - No BOM - -VMCUSTOM_DONATION="Donations for VirtueMart" -VMCUSTOM_DONATION_DESC="VirtueMart customfield plugin to let the user add a donation or set the price of a product." - -VMCUSTOM_DONATION_MIN="Minimal amount allowed" -VMCUSTOM_DONATION_MIN_TIP="This is the minimum amount that the user is allowed to enter. Values smaller than this value will be reset to this value. Leave this field empty if you don't want to set any lower limit. Set this value to 0 to prohibit negative values (default)." -VMCUSTOM_DONATION_MAX="Maximum amount allowed" -VMCUSTOM_DONATION_MAX_TIP="This is the maximum amount that the user is allowed to enter. Values larger than this value will be reset to this value. Leave this field empty if you don't want to impose any upper limit." - diff --git a/language/en-GB/en-GB.plg_vmcustom_nametheprice.ini b/language/en-GB/en-GB.plg_vmcustom_nametheprice.ini new file mode 100644 index 0000000000000000000000000000000000000000..c4b85479622e915711718f6cf8e26e54aff1ece5 --- /dev/null +++ b/language/en-GB/en-GB.plg_vmcustom_nametheprice.ini @@ -0,0 +1,15 @@ +; Virtuemart! Project +; Copyright (C) 2011 Virtuemart Team. All rights reserved. +; License http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL, see LICENSE.php +; Note : All ini files need to be saved as UTF-8 - No BOM + +VMCUSTOM_NAMETHEPRICE="Name Your Price Plugin for VirtueMart" +VMCUSTOM_NAMETHEPRICE_DESC="VirtueMart customfield plugin to let the user determine the price of a product (e.g. for donations or vouchers)." + +VMCUSTOM_NAMETHEPRICE_MIN="Minimal amount allowed" +VMCUSTOM_NAMETHEPRICE_MIN_TIP="This is the minimum amount that the user is allowed to enter. Values smaller than this value will be reset to this value. Leave this field empty if you don't want to set any lower limit. Set this value to 0 to prohibit negative values (default)." +VMCUSTOM_NAMETHEPRICE_MAX="Maximum amount allowed" +VMCUSTOM_NAMETHEPRICE_MAX_TIP="This is the maximum amount that the user is allowed to enter. Values larger than this value will be reset to this value. Leave this field empty if you don't want to impose any upper limit." + +VMCUSTOM_NAMETHEPRICE_ERROR_MAX_EXCEEDED="The value %d you entered is larger than the largest allowed value, using the maximum value %d instead."; +VMCUSTOM_NAMETHEPRICE_ERROR_MIN_EXCEEDED="The value %d you entered is smaller than the lowest allowed value, using the minimum value %d instead."; diff --git a/language/en-GB/en-GB.plg_vmcustom_donation.sys.ini b/language/en-GB/en-GB.plg_vmcustom_nametheprice.sys.ini similarity index 50% rename from language/en-GB/en-GB.plg_vmcustom_donation.sys.ini rename to language/en-GB/en-GB.plg_vmcustom_nametheprice.sys.ini index 100e72e132b5e2ceef2c70c3b4657ed279d07bb4..3b41017b07fd86cb72f88a653c12044d9b157238 100644 --- a/language/en-GB/en-GB.plg_vmcustom_donation.sys.ini +++ b/language/en-GB/en-GB.plg_vmcustom_nametheprice.sys.ini @@ -3,5 +3,5 @@ ; License http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL, see LICENSE.php ; Note : All ini files need to be saved as UTF-8 - No BOM -VMCUSTOM_DONATION="Donations for VirtueMart" -VMCUSTOM_DONATION_DESC="VirtueMart customfield plugin to let the user add a donation or set the price of a product." +VMCUSTOM_NAMETHEPRICE="Name Your Price Plugin for VirtueMart" +VMCUSTOM_NAMETHEPRICE_DESC="VirtueMart customfield plugin to let the user determine the price of a product (e.g. for donations or vouchers)." diff --git a/nametheprice.php b/nametheprice.php new file mode 100644 index 0000000000000000000000000000000000000000..e4bf6bee1b71dc64cf7963e4544bb91a046d38b1 --- /dev/null +++ b/nametheprice.php @@ -0,0 +1,230 @@ +<?php +/**------------------------------------------------------------------------ +# nametheprice.php - VirtueMart 2 plugin to let customers give the price they want to pay (e.g. for donations or vouchers) +# ------------------------------------------------------------------------ +# @author Reinhold Kainhofer, The Open Tools Association +# @copyright Copyright (C) 2013 Reinhold Kainhofer, open-tools.net. All Rights Reserved. +# @license - http://www.gnu.org/licenses/gpl.html GNU/GPL +* @package VirtueMart +* @subpackage vmcustom +# Websites: http://www.open-tools.net/ +# Technical Support: Forum - http://www.open-tools.net/forum/index.html +-------------------------------------------------------------------------*/ +// no direct access +defined('_JEXEC') or die( 'Direct Access to ' . basename( __FILE__ ) . ' is not allowed.' ) ; + +if (!class_exists('vmCustomPlugin')) require(JPATH_VM_PLUGINS . DS . 'vmcustomplugin.php'); +// if(!class_exists('VmTable'))require(JPATH_VM_ADMINISTRATOR.DS.'helpers'.DS.'vmtable.php'); + +if (!defined('VMNAMETHEPRICE_PLUGINPATH')) + define ('VMNAMETHEPRICE_PLUGINPATH', JPATH_SITE.DS.'plugins'.DS.'vmcustom'.DS.'nametheprice'); +if (!defined('VMNAMETHEPRICE_PLUGINWEBROOT')) + define ('VMNAMETHEPRICE_PLUGINWEBROOT', 'plugins/vmcustom/nametheprice'); + +class plgVmCustomNameThePrice extends vmCustomPlugin { + + function __construct(& $subject, $config) { + parent::__construct($subject, $config); + $varsToPush = array( + 'min_amount'=>array('0.0', 'char'), + 'max_amount'=>array('', 'char'), + ); + if(!defined('VM_VERSION') or VM_VERSION < 3){ + $this->setConfigParameterable('custom_params', $varsToPush); + } else { + $this->setConfigParameterable('customfield_params', $varsToPush); + } + } + + /** + * @see Form displayed in the product edit page in the BE, configure the download file + * @author Reinhold Kainhofer + */ + function plgVmOnProductEdit($field, $product_id, &$row,&$retValue) { + if ($field->custom_element != $this->_name) return ''; + + if (!defined('VM_VERSION') or VM_VERSION < 3) { + $this->parseCustomParams ($field); // Not needed in VM3! + $paramName = 'custom_param'; + } else { + $paramName = 'customfield_params'; + } + $html =' + <fieldset> + <legend>'. JText::_('VMCUSTOM_NAMETHEPRICE') .'</legend> + <table class="admintable"> + '.VmHTML::row('input','VMCUSTOM_NAMETHEPRICE_MIN', $paramName.'['.$row.'][min_amount]',$field->min_amount). + VmHTML::row('input','VMCUSTOM_NAMETHEPRICE_MAX', $paramName.'['.$row.'][max_amount]',$field->max_amount). + '<tr> + </table> + </fieldset>'; + $retValue .= $html; + $row++; + return true ; + } + + // VM3 + function plgVmOnDisplayProductFEVM3(&$product, &$field) { + + if ($field->custom_element != $this->_name) return ''; + $field->display .= $this->renderByLayout('default',array($field) ); + + return true; + } + + // VM2 legacy + function plgVmOnDisplayProductVariantFE($field,&$idx,&$group) { + // default return if it's not this plugin + if ($field->custom_element != $this->_name) return ''; + $this->getCustomParams($field); + $group->display .= $this->renderByLayout('default',array($field ) ); + return true; + } + + // VM2 legacy + 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['customprice']) && ($product->productCustom->virtuemart_customfield_id==$k)){ + $currency = CurrencyDisplay::getInstance (); + $html .='<span>'.JText::_($product->productCustom->custom_title).' '.$currency->priceDisplay($item['customprice']).'</span>'; + } + } + return true; + } + + 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; + $item = $product->customProductData[$productCustom->virtuemart_custom_id][$productCustom->virtuemart_customfield_id]; + if(isset($item['customprice'])){ + $currency = CurrencyDisplay::getInstance (); + $html .='<span>'.vmText::_($productCustom->custom_title).' '.$currency->priceDisplay($item['customprice']).'</span>'; + } + return true; + } + + function plgVmOnViewCartModuleVM3( &$product, &$productCustom, &$html) { + return $this->plgVmOnViewCartVM3($product,$productCustom,$html); + } + + function plgVmDisplayInOrderBEVM3( &$product, &$productCustom, &$html) { + $this->plgVmOnViewCartVM3($product,$productCustom,$html); + } + + function plgVmDisplayInOrderFEVM3( &$product, &$productCustom, &$html) { + $this->plgVmOnViewCartVM3($product,$productCustom,$html); + } + + function plgVmOnViewCartModule($product,$row,&$html) { + return $this->plgVmOnViewCart($product,$row,$html); + } + + function plgVmDisplayInOrderBE($item, $row, &$html) { + return $this->plgVmOnViewCart($item,$row,$html); //same render as cart + } + function plgVmDisplayInOrderFE($item, $row, &$html) { + return $this->plgVmOnViewCart($item,$row,$html); //same render as cart + } + + /** + * We must reimplement this triggers for joomla 1.7 + * vmplugin triggers note by Max Milbers + */ + public function plgVmOnStoreInstallPluginTable($psType) { + //Should the textinput use an own internal variable or store it in the params? + //Here is no getVmPluginCreateTableSQL defined +// return $this->onStoreInstallPluginTable($psType); + } + + + // VM2 legacy + function plgVmDeclarePluginParamsCustom($psType,$name,$id, &$data){ + return $this->declarePluginParams('custom', $name, $id, $data); + } + + // VM3 + function plgVmDeclarePluginParamsCustomVM3 (&$data) { + return $this->declarePluginParams ('custom', $data); + } + + function plgVmGetTablePluginParams($psType, $name, $id, &$xParams, &$varsToPush){ + return $this->getTablePluginParams($psType, $name, $id, $xParams, $varsToPush); + } + function plgVmSetOnTablePluginParamsCustom($name, $id, &$table){ + return $this->setOnTablePluginParams($name, $id, $table); + } + + /** + * Custom triggers note by Max Milbers + */ + function plgVmOnDisplayEdit($virtuemart_custom_id,&$customPlugin){ + return $this->onDisplayEditBECustom($virtuemart_custom_id,$customPlugin); + } + + // VM2 legacy + public function plgVmCalculateCustomVariant($product, &$productCustomsPrice, $selected){ + if ($productCustomsPrice->custom_element !==$this->_name) return ; + $customVariant = $this->getCustomVariant($product, $productCustomsPrice, $selected); + // bounds for "nametheprice": max/min value. + if (!empty($customVariant['customprice'])) { + // Error handling to display errors to the user, e.g. when the amount exceeds the min/max values + // This does not yet work for the AJAX calls, because in VM2 the json can only contain the prices + if (!empty($productCustomsPrice->min_amount) && ($customVariant['customprice']<$productCustomsPrice->min_amount)) { + JFactory::getApplication()->enqueueMessage(JText::sprintf('VMCUSTOM_NAMETHEPRICE_ERROR_MIN_EXCEEDED', $selected['customprice'], $customfield->min_amount), 'warning'); + $customVariant['customprice'] = $productCustomsPrice->min_amount; + } + if (!empty($productCustomsPrice->max_amount) && ($customVariant['customprice']>$productCustomsPrice->max_amount)) { + JFactory::getApplication()->enqueueMessage(JText::sprintf('VMCUSTOM_NAMETHEPRICE_ERROR_MAX_EXCEEDED', $selected['customprice'], $customfield->max_amount), 'warning'); + $customVariant['customprice'] = $productCustomsPrice->max_amount; + } + + $productCustomsPrice->custom_price = $customVariant['customprice']; + } else { + $productCustomsPrice->custom_price = 0.0; + } + return true; + } + + // VM3 + public function plgVmPrepareCartProduct(&$product, &$customfield, $selected, &$modificatorSum){ + if ($customfield->custom_element !==$this->_name) return ; + + if (!empty($selected['customprice'])) { + // Error handling to display errors to the user, e.g. when the amount exceeds the min/max values + if (!empty($customfield->min_amount) && ($selected['customprice']<$customfield->min_amount)) { + JFactory::getApplication()->enqueueMessage(JText::sprintf('VMCUSTOM_NAMETHEPRICE_ERROR_MIN_EXCEEDED', $selected['customprice'], $customfield->min_amount), 'warning'); + $selected['customprice'] = $customfield->min_amount; + } + if (!empty($customfield->max_amount) && ($selected['customprice']>$customfield->max_amount)) { + JFactory::getApplication()->enqueueMessage(JText::sprintf('VMCUSTOM_NAMETHEPRICE_ERROR_MAX_EXCEEDED', $selected['customprice'], $customfield->max_amount), 'warning'); + $selected['customprice'] = $customfield->max_amount; + } + + $modificatorSum += $selected['customprice']; + } else { + $modificatorSum += 0.0; + } + + return true; + } + + + public function plgVmDisplayInOrderCustom(&$html,$item, $param,$productCustom, $row ,$view='FE'){ + $this->plgVmDisplayInOrderCustom($html,$item, $param,$productCustom, $row ,$view); + } + + public function plgVmCreateOrderLinesCustom(&$html,$item,$productCustom, $row ){ +// $this->createOrderLinesCustom($html,$item,$productCustom, $row ); + } + function plgVmOnSelfCallFE($type,$name,&$render) { + $render->html = ''; + } + +} + +// No closing tag \ No newline at end of file diff --git a/donation.script.php b/nametheprice.script.php similarity index 88% rename from donation.script.php rename to nametheprice.script.php index 5ebeb553941604edfb45038527e78592239b5026..703ffebcf5eae3b9cff26a0a4c89c2e2864447e1 100644 --- a/donation.script.php +++ b/nametheprice.script.php @@ -1,9 +1,9 @@ <?php /**------------------------------------------------------------------------ -# donation.script.php - VirtueMart 2 plugin for donations, installation script +# donation.script.php - VirtueMart 2 and 3 plugin to let customers determine the price of a product, installation script # ------------------------------------------------------------------------ # @author Reinhold Kainhofer, The Open Tools Association -# @copyright Copyright (C) 2013 Reinhold Kainhofer, open-tools.net. All Rights Reserved. +# @copyright Copyright (C) 2013-2014 Reinhold Kainhofer, open-tools.net. All Rights Reserved. # @license - http://www.gnu.org/licenses/gpl.html GNU/GPL * @package VirtueMart * @subpackage vmcustom @@ -15,11 +15,11 @@ defined('_JEXEC') or die('Restricted access'); /** * Installation script for the plugin * - * @copyright Copyright (C) 2013 Reinhold Kainhofer, office@open-tools.net + * @copyright Copyright (C) 2013-2014 Reinhold Kainhofer, office@open-tools.net * @license GPL v3+, http://www.gnu.org/copyleft/gpl.html */ -class plgVmCustomDonationInstallerScript +class plgVmCustomNameThePriceInstallerScript { /** * Constructor @@ -59,7 +59,7 @@ class plgVmCustomDonationInstallerScript { // enabling plugin $db =& JFactory::getDBO(); - $db->setQuery('update #__extensions set enabled = 1 where type = "plugin" and element = "donation" and folder = "vmcustom"'); + $db->setQuery('update #__extensions set enabled = 1 where type = "plugin" and element = "nametheprice" and folder = "vmcustom"'); $db->query(); return True; diff --git a/nametheprice.xml b/nametheprice.xml new file mode 100644 index 0000000000000000000000000000000000000000..72177e6ca561a2b8018087cf3e066478bf0a5d36 --- /dev/null +++ b/nametheprice.xml @@ -0,0 +1,30 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<extension version="2.5" type="plugin" group="vmcustom" method="upgrade"> + <name>VMCUSTOM_NAMETHEPRICE</name> + <creationDate>2013-03-02</creationDate> + <author>Reinhold Kainhofer</author> + <authorUrl>http://www.open-tools.net/</authorUrl> + <copyright>Copyright (C) 2013-2014 Reinhold Kainhofer. All rights reserved.</copyright> + <license>http://www.gnu.org/licenses/gpl.html GNU/GPL v3+</license> + <version>1.2</version> + <description>VMCUSTOM_NAMETHEPRICE_DESC</description> + <files> + <filename plugin="nametheprice">nametheprice.php</filename> + <filename>nametheprice.script.php</filename> + <folder>language</folder> + <folder>nametheprice</folder> + <filename>index.html</filename> + </files> + <languages folder="language"> + <language tag="en-GB">en-GB/en-GB.plg_vmcustom_nametheprice.ini</language> + <language tag="en-GB">en-GB/en-GB.plg_vmcustom_nametheprice.sys.ini</language> + <language tag="de-DE">de-DE/de-DE.plg_vmcustom_nametheprice.ini</language> + <language tag="de-DE">de-DE/de-DE.plg_vmcustom_nametheprice.sys.ini</language> + </languages> + <scriptfile>nametheprice.script.php</scriptfile> + <vmconfig> + </vmconfig> + <params addpath="/administrator/components/com_virtuemart/elements"> + <param type="vmjpluginwarning" /> + </params> +</extension> diff --git a/donation/index.html b/nametheprice/index.html similarity index 100% rename from donation/index.html rename to nametheprice/index.html diff --git a/nametheprice/tmpl/default.php b/nametheprice/tmpl/default.php new file mode 100644 index 0000000000000000000000000000000000000000..8b7103f55a53513ceed93295f9cf76dd346121bf --- /dev/null +++ b/nametheprice/tmpl/default.php @@ -0,0 +1,45 @@ +<?php +/*------------------------------------------------------------------------ +# default.php - template for the name the price (previously donation) input box +# ------------------------------------------------------------------------ +# author Reinhold Kainhofer, The Open Tools Association +# copyright Copyright (C) 2013 open-tools.net. All Rights Reserved. +# @license - http://www.gnu.org/licenses/gpl.html GNU/GPL +# Websites: http://www.open-tools.net/ +# Technical Support: Forum - http://www.open-tools.net/forum/index.html +-------------------------------------------------------------------------*/ +// no direct access +defined( '_JEXEC' ) or die( 'Restricted access' ); + + $class='vmcustom-nametheprice'; +$field = $viewData[0]; +if (!defined('VM_VERSION') or VM_VERSION < 3) { // VM2: + $name = 'customPlugin['.$field->virtuemart_customfield_id.']['.$field->custom_element.'][customprice]'; +} else { + $name = 'customProductData['.$field->virtuemart_product_id.']['.$field->virtuemart_custom_id.']['.$field->virtuemart_customfield_id .'][customprice]'; +} +?> + + <input class="<?php echo $class ?>" type="text" value="" size="6" name="<?php echo $name?>"><?php echo CurrencyDisplay::getInstance ()->getSymbol(); ?><br /> +<?php + // preventing 2 x load javascript + static $namethepricejs; + if ($namethepricejs) return true; + $namethepricejs = true ; + + //javascript to update price + $script = ' +/* <![CDATA[ */ +var namethepricefunc = function($) { + jQuery(".vmcustom-nametheprice").keyup(function() { + formProduct = $(this).parents("form.product"); + virtuemart_product_id = formProduct.find(\'input[name="virtuemart_product_id[]"]\').val(); + Virtuemart.setproducttype(formProduct,virtuemart_product_id); + }); +}; +jQuery("body").on("updateVirtueMartProductDetail", namethepricefunc); +jQuery(document).ready(namethepricefunc); +/* ]]> */ + '; +$document = JFactory::getDocument()->addScriptDeclaration($script); + diff --git a/donation/tmpl/index.html b/nametheprice/tmpl/index.html similarity index 100% rename from donation/tmpl/index.html rename to nametheprice/tmpl/index.html