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

Version 2.3.0: Add NoShipping to not offer any shipping at all; fix shipping...

Version 2.3.0: Add NoShipping to not offer any shipping at all; fix shipping costs when Shipping= is omitted
parent 7e92d9f6
No related branches found
No related tags found
No related merge requests found
BASE=rules_shipping BASE=rules_shipping
BASE_ADV=rules_shipping_advanced BASE_ADV=rules_shipping_advanced
PLUGINTYPE=vmshipment PLUGINTYPE=vmshipment
VERSION=2.2.2 VERSION=2.3.0
PLUGINFILES=$(BASE).php $(BASE)_base.php $(BASE).script.php $(BASE).xml index.html 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 PLUGINFILES_ADV=$(BASE_ADV).php $(BASE)_base.php $(BASE_ADV).script.php $(BASE_ADV).xml index.html
......
...@@ -10,8 +10,8 @@ VMSHIPMENT_RULES_ADV_DESC="" ...@@ -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="<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_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 (&lt;, &lt;=, =&lt;, ==, !=, &lt;&gt;, &gt;=, =&gt;, &gt;)</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 &quot;Europe&quot; 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&lt;=Amount&lt;100; Shipping=4.50<br>Name=Free Shipping; 100&lt;= Amount; 0</tt></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 (&lt;, &lt;=, =&lt;, ==, !=, &lt;&gt;, &gt;=, =&gt;, &gt;)</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 &quot;Europe&quot; 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&lt;=Amount&lt;100; Shipping=4.50<br>Name=Free Shipping; 100&lt;= 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 (&lt;, &lt;=, =&lt;, ==, !=, &lt;&gt;, &gt;=, =&gt;, &gt;)</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 &quot;Europe&quot; 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&lt;=Amount&lt;100; Shipping=5+1.50*Articles<br>Name=Free Shipping; 100&lt;= Amount; 0</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 (&lt;, &lt;=, =&lt;, ==, !=, &lt;&gt;, &gt;=, =&gt;, &gt;)</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 &quot;Europe&quot; 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&lt;=Amount&lt;100; Shipping=5+1.50*Articles<br>Name=Free Shipping; 100&lt;= Amount; 0</blockquote></div>"
VMSHIPMENT_RULES_LENGTH_UNIT="Length Unit" 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." VMSHIPMENT_RULES_LENGTH_UNIT_DESC="The length unit, in which the length, width and heights are given, and from which the volume is calculated."
......
File added
File added
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
<authorUrl>http://www.kainhofer.com</authorUrl> <authorUrl>http://www.kainhofer.com</authorUrl>
<copyright>Copyright (C) 2013, Reinhold Kainhofer</copyright> <copyright>Copyright (C) 2013, Reinhold Kainhofer</copyright>
<license>GPL v3+</license> <license>GPL v3+</license>
<version>2.2.2</version> <version>2.3.0</version>
<description>VMSHIPMENT_RULES_DESC</description> <description>VMSHIPMENT_RULES_DESC</description>
<files> <files>
<filename plugin="rules_shipping">rules_shipping.php</filename> <filename plugin="rules_shipping">rules_shipping.php</filename>
......
...@@ -146,8 +146,6 @@ class ShippingRule_Advanced extends ShippingRule { ...@@ -146,8 +146,6 @@ class ShippingRule_Advanced extends ShippingRule {
$is_condition = false; $is_condition = false;
$is_assignment = false; $is_assignment = false;
if (count($atoms)==1) return $atoms[0];
$stack = array (); // 1) $stack = array (); // 1)
$rpn = array (); $rpn = array ();
foreach ($atoms as $a) { // 2) foreach ($atoms as $a) { // 2)
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
<authorUrl>http://www.kainhofer.com</authorUrl> <authorUrl>http://www.kainhofer.com</authorUrl>
<copyright>Copyright (C) 2013, Reinhold Kainhofer</copyright> <copyright>Copyright (C) 2013, Reinhold Kainhofer</copyright>
<license>GPL v3+</license> <license>GPL v3+</license>
<version>2.2.2</version> <version>2.3.0</version>
<description>VMSHIPMENT_RULES_ADV_DESC</description> <description>VMSHIPMENT_RULES_ADV_DESC</description>
<files> <files>
<filename plugin="rules_shipping_advanced">rules_shipping_advanced.php</filename> <filename plugin="rules_shipping_advanced">rules_shipping_advanced.php</filename>
......
...@@ -221,6 +221,7 @@ class plgVmShipmentRules_Shipping_Base extends vmPSPlugin { ...@@ -221,6 +221,7 @@ class plgVmShipmentRules_Shipping_Base extends vmPSPlugin {
foreach ($method->rules as $r) { foreach ($method->rules as $r) {
if ($r->matches($cartvals)) { if ($r->matches($cartvals)) {
vmdebug('Rule '.$r->name.' ('.$r->rulestring.') matched.');
$method->tax_id = $r->tax_id; $method->tax_id = $r->tax_id;
$method->matched_rule = $r; $method->matched_rule = $r;
$method->rule_name = $r->name; $method->rule_name = $r->name;
...@@ -451,10 +452,16 @@ class plgVmShipmentRules_Shipping_Base extends vmPSPlugin { ...@@ -451,10 +452,16 @@ class plgVmShipmentRules_Shipping_Base extends vmPSPlugin {
if ($r->matches($cartvals)) { if ($r->matches($cartvals)) {
$method->matched_rule = $r; $method->matched_rule = $r;
$method->rule_name = $r->name; $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; return FALSE;
} }
...@@ -544,12 +551,6 @@ class plgVmShipmentRules_Shipping_Base extends vmPSPlugin { ...@@ -544,12 +551,6 @@ class plgVmShipmentRules_Shipping_Base extends vmPSPlugin {
return $this->setOnTablePluginParams ($name, $id, $table); return $this->setOnTablePluginParams ($name, $id, $table);
} }
/**
* @author Max Milbers
* @param $data
* @param $table
* @return bool
*/
function plgVmSetOnTablePluginShipment(&$data,&$table){ function plgVmSetOnTablePluginShipment(&$data,&$table){
$name = $data['shipment_element']; $name = $data['shipment_element'];
...@@ -779,6 +780,11 @@ class ShippingRule { ...@@ -779,6 +780,11 @@ class ShippingRule {
function getShippingCosts($vals) { function getShippingCosts($vals) {
return $this->calculateShipping($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"));
}
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment