diff --git a/Makefile b/Makefile index 39e416764dc585c6b9c54612cf0535799ec5d7cf..b5a8095595ca47ed928529ff864fb3a0c24a7acc 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ BASE=rules_shipping BASE_ADV=rules_shipping_advanced PLUGINTYPE=vmshipment -VERSION=2.2.2 +VERSION=2.3.0 PLUGINFILES=$(BASE).php $(BASE)_base.php $(BASE).script.php $(BASE).xml index.html PLUGINFILES_ADV=$(BASE_ADV).php $(BASE)_base.php $(BASE_ADV).script.php $(BASE_ADV).xml index.html 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 ae6f35a7200531138b1dc0568c0db19588b09535..643576e13ecc160b2e21f5634ac867a51035f8fe 100644 --- a/language/en-GB/en-GB.plg_vmshipment_rules_shipping.ini +++ b/language/en-GB/en-GB.plg_vmshipment_rules_shipping.ini @@ -10,8 +10,8 @@ VMSHIPMENT_RULES_ADV_DESC="" VMSHIPMENT_RULES_PLUGIN="<b>Shipment based on general rules (weight, products, amount) per country-zones</b>" VMSHIPMENT_RULES_PLUGIN_ADV="<b>Shipment based on general rules (weight, products, amount) per country-zones, including arithmetic expression</b>" -VMSHIPMENT_RULES_HELP="<div style='background: #DDDDDD; padding:5px; margin:3px;'><h2>Overview of the Rules Syntax</h2><ul><li>Each line contains one rule consisting of several <b>conditions and assignments in arbitrary order and separated by semicolons</b>. </li><li>The <b>first matching rule is used</b> to calculate the shipping costs.</li><li>All rule parts with <b>comparison operators (<, <=, =<, ==, !=, <>, >=, =>, >)</b> are conditions.</li><li> Supported <b>variables (case-insensitive)</b>: <b><tt>Amount</tt></b>, <b><tt>Weight</tt></b>, <b><tt>ZIP</tt></b>, <b><tt>Products</tt></b> (number of different products), <b><tt>Articles</tt></b> (counted with quantity), <b><tt>Volume</tt></b> (total volume of the order) and <b><tt>MinVolume</tt>, <tt>MinLength</tt>, <tt>MinWidth</tt>, <tt>MinHeight</tt></b> as well as the same variables with <tt>Max</tt> instead of <tt>Min</tt>.</li><li>A condition can consist of multiple chained comparisons.</li><li>All rule parts of the form <b><tt>[VARIABLE]=VALUE</tt> are assignments</b>, with <tt>[VARIABLE]</tt> being one of <b><tt>Name</tt></b> (optional name of the rule, displayed in the cart and invoice), <b><tt>Shipping</tt></b> (shipping cost without tax if the rule matches) and <b><tt>ShippingWithTax</tt></b> (shipping cost including taxes if the rule matches). The <tt>Shipping=</tt> can be left out (<tt>ShippingWithTax=</tt> can not be left out). I.e. a rule part consisting only of a numerical value is understood as net shipping cost without tax.</li></ul><p>EXAMPLE: A rule named "Europe" that sets shipping costs of 4.50 for order amounts from 50 to less than 100, and free shipping from 100€ on would be:</p><blockquote><tt>Name=Europe; 50<=Amount<100; Shipping=4.50<br>Name=Free Shipping; 100<= Amount; 0</tt></blockquote></div>" -VMSHIPMENT_RULES_HELP_ADV="<div style='background: #DDDDDD; padding:5px; margin:3px;'><h2>Overview of the Rules Syntax</h2><ul><li>Each line contains one rule consisting of several <b>conditions and assignments in arbitrary order and separated by semicolons</b>. </li><li>The <b>first matching rule is used</b> to calculate the shipping costs.</li><li>All rule parts with <b>comparison operators (<, <=, =<, ==, !=, <>, >=, =>, >)</b> are conditions.</li><li> Supported <b>variables (case-insensitive)</b>: <b><tt>Amount</tt></b>, <b><tt>Weight</tt></b>, <b><tt>ZIP</tt></b>, <b><tt>Products</tt></b> (number of different products), <b><tt>Articles</tt></b> (counted with quantity), <b><tt>Volume</tt></b> (total volume of the order) and <b><tt>MinVolume</tt>, <tt>MinLength</tt>, <tt>MinWidth</tt>, <tt>MinHeight</tt></b> as well as the same variables with <tt>Max</tt> instead of <tt>Min</tt>.</li><li>A condition can consist of multiple chained comparisons.</li><li>All rule parts of the form <b><tt>[VARIABLE]=VALUE</tt> are assignments</b>, with <tt>[VARIABLE]</tt> being one of <b><tt>Name</tt></b> (optional name of the rule, displayed in the cart and invoice), <b><tt>Shipping</tt></b> (shipping cost without tax if the rule matches) and <b><tt>ShippingWithTax</tt></b> (shipping cost including taxes if the rule matches). The <tt>Shipping=</tt> can be left out (<tt>ShippingWithTax=</tt> can not be left out). I.e. a rule part consisting only of a numerical value is understood as net shipping cost without tax.</li><li>In the advanced version, all expressions (conditions and shipping costs) may contain <b>arbitrary basic arithmetic expressions (+, -, *, /, %, ^ and parentheses)</b> of the above variables.</li></ul><p>EXAMPLE: A rule named "Europe" that sets shipping costs of 5€ plus 1.50€ per article for order amounts from 50 to less than 100, and free shipping from 100€ on would be:</p><blockquote><tt>Name=Europe; 50<=Amount<100; Shipping=5+1.50*Articles<br>Name=Free Shipping; 100<= Amount; 0</blockquote></div>" +VMSHIPMENT_RULES_HELP="<div style='background: #DDDDDD; padding:5px; margin:3px;'><h2>Overview of the Rules Syntax</h2><ul><li>Each line contains one rule consisting of several <b>conditions and assignments in arbitrary order and separated by semicolons</b>. </li><li>The <b>first matching rule is used</b> to calculate the shipping costs. If its shipping cost is set to <tt>NoShipping</tt>, then this method will not offer any shipping at all.</li><li>All rule parts with <b>comparison operators (<, <=, =<, ==, !=, <>, >=, =>, >)</b> are conditions.</li><li> Supported <b>variables (case-insensitive)</b>: <b><tt>Amount</tt></b>, <b><tt>Weight</tt></b>, <b><tt>ZIP</tt></b>, <b><tt>Products</tt></b> (number of different products), <b><tt>Articles</tt></b> (counted with quantity), <b><tt>Volume</tt></b> (total volume of the order) and <b><tt>MinVolume</tt>, <tt>MinLength</tt>, <tt>MinWidth</tt>, <tt>MinHeight</tt></b> as well as the same variables with <tt>Max</tt> instead of <tt>Min</tt>.</li><li>A condition can consist of multiple chained comparisons.</li><li>All rule parts of the form <b><tt>[VARIABLE]=VALUE</tt> are assignments</b>, with <tt>[VARIABLE]</tt> being one of <b><tt>Name</tt></b> (optional name of the rule, displayed in the cart and invoice), <b><tt>Shipping</tt></b> (shipping cost without tax if the rule matches) and <b><tt>ShippingWithTax</tt></b> (shipping cost including taxes if the rule matches). The <tt>Shipping=</tt> can be left out (<tt>ShippingWithTax=</tt> can not be left out). I.e. a rule part consisting only of a numerical value is understood as net shipping cost without tax.</li></ul><p>EXAMPLE: A rule named "Europe" that sets shipping costs of 4.50 for order amounts from 50 to less than 100, and free shipping from 100€ on would be:</p><blockquote><tt>Name=Europe; 50<=Amount<100; Shipping=4.50<br>Name=Free Shipping; 100<= Amount; 0</tt></blockquote></div>" +VMSHIPMENT_RULES_HELP_ADV="<div style='background: #DDDDDD; padding:5px; margin:3px;'><h2>Overview of the Rules Syntax</h2><ul><li>Each line contains one rule consisting of several <b>conditions and assignments in arbitrary order and separated by semicolons</b>. </li><li>The <b>first matching rule is used</b> to calculate the shipping costs. If its shipping cost is set to <tt>NoShipping</tt>, then this method will not offer any shipping at all.</li><li>All rule parts with <b>comparison operators (<, <=, =<, ==, !=, <>, >=, =>, >)</b> are conditions.</li><li> Supported <b>variables (case-insensitive)</b>: <b><tt>Amount</tt></b>, <b><tt>Weight</tt></b>, <b><tt>ZIP</tt></b>, <b><tt>Products</tt></b> (number of different products), <b><tt>Articles</tt></b> (counted with quantity), <b><tt>Volume</tt></b> (total volume of the order) and <b><tt>MinVolume</tt>, <tt>MinLength</tt>, <tt>MinWidth</tt>, <tt>MinHeight</tt></b> as well as the same variables with <tt>Max</tt> instead of <tt>Min</tt>.</li><li>A condition can consist of multiple chained comparisons. In the advanced version, the OR operator is available, too.</li><li>All rule parts of the form <b><tt>[VARIABLE]=VALUE</tt> are assignments</b>, with <tt>[VARIABLE]</tt> being one of <b><tt>Name</tt></b> (optional name of the rule, displayed in the cart and invoice), <b><tt>Shipping</tt></b> (shipping cost without tax if the rule matches) and <b><tt>ShippingWithTax</tt></b> (shipping cost including taxes if the rule matches). The <tt>Shipping=</tt> can be left out (<tt>ShippingWithTax=</tt> can not be left out). I.e. a rule part consisting only of a numerical value is understood as net shipping cost without tax.</li><li>In the advanced version, all expressions (conditions and shipping costs) may contain <b>arbitrary basic arithmetic expressions (+, -, *, /, %, ^ and parentheses)</b> of the above variables.</li></ul><p>EXAMPLE: A rule named "Europe" that sets shipping costs of 5€ plus 1.50€ per article for order amounts from 50 to less than 100, and free shipping from 100€ on would be:</p><blockquote><tt>Name=Europe; 50<=Amount<100; Shipping=5+1.50*Articles<br>Name=Free Shipping; 100<= Amount; 0</blockquote></div>" VMSHIPMENT_RULES_LENGTH_UNIT="Length Unit" VMSHIPMENT_RULES_LENGTH_UNIT_DESC="The length unit, in which the length, width and heights are given, and from which the volume is calculated." diff --git a/releases/plg_vmshipment_rules_shipping_advanced_v2.3.0.zip b/releases/plg_vmshipment_rules_shipping_advanced_v2.3.0.zip new file mode 100644 index 0000000000000000000000000000000000000000..a938c487013227e5aa6f4301efeb15288b60aefe Binary files /dev/null and b/releases/plg_vmshipment_rules_shipping_advanced_v2.3.0.zip differ diff --git a/releases/plg_vmshipment_rules_shipping_v2.3.0.zip b/releases/plg_vmshipment_rules_shipping_v2.3.0.zip new file mode 100644 index 0000000000000000000000000000000000000000..1769f79c271b08da9b07222aa473c95c6424a124 Binary files /dev/null and b/releases/plg_vmshipment_rules_shipping_v2.3.0.zip differ diff --git a/rules_shipping.xml b/rules_shipping.xml index a2c3f8cfd804521ba2c27e26958577097bd3b9fb..59da7a8ece466ea3151a72755b79f1afad8c938a 100644 --- a/rules_shipping.xml +++ b/rules_shipping.xml @@ -6,7 +6,7 @@ <authorUrl>http://www.kainhofer.com</authorUrl> <copyright>Copyright (C) 2013, Reinhold Kainhofer</copyright> <license>GPL v3+</license> - <version>2.2.2</version> + <version>2.3.0</version> <description>VMSHIPMENT_RULES_DESC</description> <files> <filename plugin="rules_shipping">rules_shipping.php</filename> diff --git a/rules_shipping_advanced.php b/rules_shipping_advanced.php index 14dd0e710ebda21b5e3eb6ee753fffe58db4a962..206bff6f7e6fa3306b02190701feb8a06d8f486b 100644 --- a/rules_shipping_advanced.php +++ b/rules_shipping_advanced.php @@ -146,8 +146,6 @@ class ShippingRule_Advanced extends ShippingRule { $is_condition = false; $is_assignment = false; - if (count($atoms)==1) return $atoms[0]; - $stack = array (); // 1) $rpn = array (); foreach ($atoms as $a) { // 2) diff --git a/rules_shipping_advanced.xml b/rules_shipping_advanced.xml index b50b16db90941ae6ff74f8ee4c11003805fff555..208fbb19f9757c6e43199b4f483e5f84b94b14de 100644 --- a/rules_shipping_advanced.xml +++ b/rules_shipping_advanced.xml @@ -6,7 +6,7 @@ <authorUrl>http://www.kainhofer.com</authorUrl> <copyright>Copyright (C) 2013, Reinhold Kainhofer</copyright> <license>GPL v3+</license> - <version>2.2.2</version> + <version>2.3.0</version> <description>VMSHIPMENT_RULES_ADV_DESC</description> <files> <filename plugin="rules_shipping_advanced">rules_shipping_advanced.php</filename> diff --git a/rules_shipping_base.php b/rules_shipping_base.php index 37d3d03610e041b6e8387a43721c83412fd4f5b2..2f5ddf4120aef726e44a2e4397ba780dbe3a2487 100644 --- a/rules_shipping_base.php +++ b/rules_shipping_base.php @@ -221,6 +221,7 @@ class plgVmShipmentRules_Shipping_Base extends vmPSPlugin { foreach ($method->rules as $r) { if ($r->matches($cartvals)) { + vmdebug('Rule '.$r->name.' ('.$r->rulestring.') matched.'); $method->tax_id = $r->tax_id; $method->matched_rule = $r; $method->rule_name = $r->name; @@ -451,10 +452,16 @@ class plgVmShipmentRules_Shipping_Base extends vmPSPlugin { if ($r->matches($cartvals)) { $method->matched_rule = $r; $method->rule_name = $r->name; - return TRUE; + // If NoShipping is set, this method should NOT offer any shipping at all, so return FALSE, otherwise TRUE + if ($r->isNoShipping()) { + vmdebug('checkConditions '.$method->shipment_name.' indicates NoShipping for rule "'.$r->name.'" ('.$r->rulestring.').'); + return FALSE; + } else { + return TRUE; + } } } - vmdebug('checkConditions '.$method->name.' does not fit'); + vmdebug('checkConditions '.$method->shipment_name.' does not fit'); return FALSE; } @@ -544,12 +551,6 @@ class plgVmShipmentRules_Shipping_Base extends vmPSPlugin { return $this->setOnTablePluginParams ($name, $id, $table); } - /** - * @author Max Milbers - * @param $data - * @param $table - * @return bool - */ function plgVmSetOnTablePluginShipment(&$data,&$table){ $name = $data['shipment_element']; @@ -779,6 +780,11 @@ class ShippingRule { function getShippingCosts($vals) { return $this->calculateShipping($vals); } + + function isNoShipping() { + // NoShipping is set, so if the rule matches, this method should not offer any shipping at all + return (is_string($this->shipping) && (strtolower($this->shipping)=="noshipping")); + } }