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

Version 2.4: Implement handling of alphanumeric postal codes for UK and Canada

parent a20f2017
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.3.0 VERSION=2.4.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,20 +10,20 @@ VMSHIPMENT_RULES_ADV_DESC="" ...@@ -10,20 +10,20 @@ 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. 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="<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>><p>See also the the <a href="http://www.kainhofer.com/component/content/article/22-virtuemart-2-extensions/45-vm2-shipping-by-rules.html">Plugin's documentation</a> and <a href="http://www.kainhofer.com/component/content/article.html?id=46">Rules Examples</a>.</p></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_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 <strong>conditions and assignments in arbitrary order and separated by semicolons</strong>.</li><li>The <strong>first matching rule is used</strong> 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 <strong>comparison operators (&lt;, &lt;=, =&lt;, ==, !=, &lt;&gt;, &gt;=, =&gt;, &gt;)</strong> are conditions.</li><li>Supported <strong>variables (case-insensitive)</strong>: <strong><tt>Amount</tt></strong>, <strong><tt>Weight</tt></strong>, <strong><tt>ZIP</tt></strong>, <strong><tt>Products</tt></strong> (number of different products), <strong><tt>Articles</tt></strong> (counted with quantity), <strong><tt>Volume</tt></strong> (total volume of the order) and <strong><tt>MinVolume</tt>, <tt>MinLength</tt>, <tt>MinWidth</tt>, <tt>MinHeight</tt></strong> 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.</li><li>All rule parts of the form <strong><tt>[VARIABLE]=VALUE</tt> are assignments</strong>; allowed variables are <strong><tt>Name</tt></strong> (of the rule), <strong><tt>Shipping</tt></strong> and <strong><tt>ShippingWithTax</tt></strong>. The "<tt>Shipping="</tt> can be left out.</li><li>In the advanced version, all expressions may contain <strong>arbitrary basic arithmetic expressions (+, -, *, /, %, ^ and parentheses)</strong> of the above variables.</li><li><strong>Alphanumeric postal codes</strong> are supported by the variables <tt>UK_Outward, UK_Area, UK_District, UK_Subdistrict, Canada_FSA, Canada_Area, Canada_Urban, Canada_Subarea, ZIP1, ZIP2, ZIP3, ZIP4, ZIP5</tt> and <tt>ZIP6</tt> in the advanced version.</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&lt;=Amount&lt;100; Shipping=5+1.50*Articles<br />Name=Free Shipping; 100&lt;= Amount; 0</tt></blockquote><p>See also the the <a href="http://www.kainhofer.com/component/content/article/22-virtuemart-2-extensions/45-vm2-shipping-by-rules.html">Plugin's documentation</a> and <a href="http://www.kainhofer.com/component/content/article.html?id=46">Rules Examples</a>.</p></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."
VMSHIPMENT_RULES_COUNTRIES1_LABEL="<b>Rules for country set 1</b>" VMSHIPMENT_RULES_COUNTRIES1_LABEL="<b>Rules for country zone 1</b>"
VMSHIPMENT_RULES_COUNTRIES2_LABEL="<b>Rules for country set 2</b>" VMSHIPMENT_RULES_COUNTRIES2_LABEL="<b>Rules for country zone 2</b>"
VMSHIPMENT_RULES_COUNTRIES3_LABEL="<b>Rules for country set 3</b>" VMSHIPMENT_RULES_COUNTRIES3_LABEL="<b>Rules for country zone 3</b>"
VMSHIPMENT_RULES_COUNTRIES4_LABEL="<b>Rules for country set 4</b>" VMSHIPMENT_RULES_COUNTRIES4_LABEL="<b>Rules for country zone 4</b>"
VMSHIPMENT_RULES_COUNTRIES5_LABEL="<b>Rules for country set 5</b>" VMSHIPMENT_RULES_COUNTRIES5_LABEL="<b>Rules for country zone 5</b>"
VMSHIPMENT_RULES_COUNTRIES6_LABEL="<b>Rules for country set 6</b>" VMSHIPMENT_RULES_COUNTRIES6_LABEL="<b>Rules for country zone 6</b>"
VMSHIPMENT_RULES_COUNTRIES7_LABEL="<b>Rules for country set 7</b>" VMSHIPMENT_RULES_COUNTRIES7_LABEL="<b>Rules for country zone 7</b>"
VMSHIPMENT_RULES_COUNTRIES8_LABEL="<b>Rules for country set 8</b>" VMSHIPMENT_RULES_COUNTRIES8_LABEL="<b>Rules for country zone 8</b>"
VMSHIPMENT_RULES_COUNTRIES="Countries" VMSHIPMENT_RULES_COUNTRIES="Countries"
VMSHIPMENT_RULES_COUNTRIES_DESC="Select the countries to which the following rules should be restricted. If left empty, the rules will apply to all countries." VMSHIPMENT_RULES_COUNTRIES_DESC="Select the countries to which the following rules should be restricted. If left empty, the rules will apply to all countries."
VMSHIPMENT_RULES_TAX="Tax" VMSHIPMENT_RULES_TAX="Tax"
......
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.3.0</version> <version>2.4.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>
......
...@@ -43,6 +43,37 @@ class plgVmShipmentRules_Shipping_Advanced extends plgVmShipmentRules_Shipping_B ...@@ -43,6 +43,37 @@ class plgVmShipmentRules_Shipping_Advanced extends plgVmShipmentRules_Shipping_B
*/ */
protected function addCustomCartValues (VirtueMartCart $cart, $cart_prices, &$values) { protected function addCustomCartValues (VirtueMartCart $cart, $cart_prices, &$values) {
$values['coupon'] = $cart->couponCode; $values['coupon'] = $cart->couponCode;
// Postal code Check for UK postal codes: Use regexp to determine if ZIP structure matches and also to extract the parts.
// Also handle UK overseas areas/islands that use four-letter outward codes rather than "A{1,2}0{1,2}A{0,1} 0AA"
if ($values['zip'] and preg_match('/^\s*(([A-Za-z]{1,2})(\d{1,2})([A-Za-z]?)|[A-Za-z]{4})\s+(\d[A-Za-z]{2})\s*$/', $values['zip'], $match)) {
$values['uk_outward'] = $match[1];
$values['uk_area'] = $match[2];
$values['uk_district'] = $match[3];
$values['uk_subdistrict'] = $match[4];
$values['uk_inward'] = $match[5];
} else {
$values['uk_outward'] = NULL;
$values['uk_area'] = NULL;
$values['uk_district'] = NULL;
$values['uk_subdistrict'] = NULL;
$values['uk_inward'] = NULL;
}
// Postal code Check for Canadian postal codes: Use regexp to determine if ZIP structure matches and also to extract the parts.
if ($values['zip'] and preg_match('/^\s*(([A-Za-z])(\d)([A-Za-z]))\s+(\d[A-Za-z]\d)\s*$/', $values['zip'], $match)) {
$values['canada_fsa'] = $match[1];
$values['canada_area'] = $match[2];
$values['canada_urban'] = $match[3];
$values['canada_subarea'] = $match[4];
$values['canada_ldu'] = $match[5];
} else {
$values['canada_fsa'] = NULL;
$values['canada_area'] = NULL;
$values['canada_urban'] = NULL;
$values['canada_subarea'] = NULL;
$values['canada_ldu'] = NULL;
}
// print("<pre>values: ".print_r($values,1)."</pre>");
} }
} }
......
...@@ -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.3.0</version> <version>2.4.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>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment