From 0ef19dceddf17369cade56702ff648878d0f1df9 Mon Sep 17 00:00:00 2001 From: Reinhold Kainhofer <reinhold@kainhofer.com> Date: Sun, 17 Nov 2013 19:33:28 +0100 Subject: [PATCH] When NoShipping is used, print rule Name as error message to inform the user. Special care is taken (using a global array of messages...) to ensure that the message is not printed twice... --- .../en-GB/en-GB.plg_vmshipment_rules_shipping.ini | 2 ++ rules_shipping_base.php | 14 ++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/language/en-GB/en-GB.plg_vmshipment_rules_shipping.ini b/language/en-GB/en-GB.plg_vmshipment_rules_shipping.ini index 35b3253..1c19d7b 100644 --- a/language/en-GB/en-GB.plg_vmshipment_rules_shipping.ini +++ b/language/en-GB/en-GB.plg_vmshipment_rules_shipping.ini @@ -56,3 +56,5 @@ VMSHIPMENT_RULES_EVALUATE_UNKNOWN_VALUE="Evaluation yields unknown value while e VMSHIPMENT_RULES_EVALUATE_LISTFUNCTION_ARGS="List function '%s' requires all arguments to be lists. (Full rule: '%s')" VMSHIPMENT_RULES_EVALUATE_LISTFUNCTION_UNKNOWN="Unknown list function '%s' encountered. (Full rule: '%s')" + +VMSHIPMENT_RULES_NOSHIPPING_MESSAGE="%s" diff --git a/rules_shipping_base.php b/rules_shipping_base.php index 422b795..c2e233b 100644 --- a/rules_shipping_base.php +++ b/rules_shipping_base.php @@ -29,6 +29,9 @@ if (class_exists ('plgVmShipmentRules_Shipping_Base')) { return; } +// Keep track of warning messages, so we don't print them twice: +$printed_warnings = array(); + /** Shipping costs according to general rules. * Supported Variables: Weight, ZIP, Amount, Products (1 for each product, even if multiple ordered), Articles * Assignable variables: Shipping, Name @@ -58,6 +61,16 @@ class plgVmShipmentRules_Shipping_Base extends vmPSPlugin { public function getVmPluginCreateTableSQL () { return $this->createTableSQL ('Shipment Rules Table'); } + + public function printWarning($message) { + global $printed_warnings; +// JFactory::getApplication()->enqueueMessage("<pre>warnings so far are:".print_r($printed_warnings,1). ", new warning: |$message|</pre>", 'warning'); + if (!in_array($message, $printed_warnings)) { + JFactory::getApplication()->enqueueMessage($message, 'error'); + $printed_warnings[] = $message; + } + + } /** * @return array @@ -534,6 +547,7 @@ class plgVmShipmentRules_Shipping_Base extends vmPSPlugin { $method->rule_name = $r->getRuleName($cartvals); // If NoShipping is set, this method should NOT offer any shipping at all, so return FALSE, otherwise TRUE if ($r->isNoShipping()) { + $this->printWarning(JText::sprintf('VMSHIPMENT_RULES_NOSHIPPING_MESSAGE', $method->rule_name)); vmdebug('checkConditions '.$method->shipment_name.' indicates NoShipping for rule "'.$method->rule_name.'" ('.$r->rulestring.').'); return FALSE; } else { -- GitLab