Commit f70b7cd2 authored by Reinhold Kainhofer's avatar Reinhold Kainhofer
Browse files

V6.1.3: Fix UK post codes

parent b13d3e59
......@@ -2,7 +2,7 @@ BASE=rules_shipping
BASE_ADV=rules_shipping_advanced
PLUGINTYPE=vmshipment
ZIPBASE=opentools_vm
VERSION=6.1.2
VERSION=6.1.3
PLUGINFILES=$(BASE).php $(BASE)_base.php $(BASE)_framework_joomla.php $(BASE).script.php $(BASE).xml index.html
PLUGINFILES_ADV=$(BASE_ADV).php $(BASE)_base.php $(BASE)_framework_joomla.php $(BASE_ADV).script.php $(BASE_ADV).xml index.html
......
......@@ -294,7 +294,7 @@ class RulesShippingFramework {
/**
* Extract information about non-numerical zip codes (UK and Canada) from the postal code
*/
protected function getAddressZIP ($zip) {
public function getAddressZIP ($zip) {
$values = array();
// Postal code Check for UK postal codes: Use regexp to determine if ZIP structure matches and also to extract the parts.
......@@ -336,10 +336,12 @@ class RulesShippingFramework {
protected function addCustomCartValues ($cart, $products, $method, &$values) {
// Pass all args through to the callback, if it exists
if (isset($this->callbacks['addCustomCartValues'])) {
return call_user_func_array($this->callbacks['addCustomCartValues'], func_get_args());
return call_user_func_array($this->callbacks['addCustomCartValues'], array($cart, $products, $method, &$values)/*func_get_args()*/);
}
return $values;
}
protected function addPluginCartValues($cart, $products, $method, &$values) {
return $values;
}
public function getCartValues ($cart, $products, $method) {
......
......@@ -6,7 +6,7 @@
<authorUrl>http://www.open-tools.net</authorUrl>
<copyright>Copyright (C) 2013-2014, Reinhold Kainhofer</copyright>
<license>GPL v3+</license>
<version>6.1.2</version>
<version>6.1.3</version>
<description>OTSHIPMENT_RULES_DESC</description>
<files>
<filename plugin="rules_shipping">rules_shipping.php</filename>
......
......@@ -34,49 +34,21 @@ class plgVmShipmentRules_Shipping_Advanced extends plgVmShipmentRules_Shipping_B
function __construct (& $subject, $config) {
parent::__construct ($subject, $config);
$this->helper->registerCallback('initRule', array($this, 'initRule'));
$this->helper->registerCallback('addCustomCartValues', array($this, 'addCustomCartValues'));
$this->helper->registerCallback('addCustomCartValues', array($this, 'addAdvancedCustomCartValues'));
}
public function initRule ($framework, $rulestring, $countries, $ruleinfo) {
return new ShippingRule_Advanced ($framework, $rulestring, $countries, $ruleinfo);
}
/** Allow child classes to add additional variables for the rules
*/
public function addCustomCartValues ($cart, $products, $method, &$values) {
public function addAdvancedCustomCartValues ($cart, $products, $method, &$values) {
$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 (isset($values['zip'])) {
$zip=strtoupper($values['zip']);
}
if (isset($zip) and preg_match('/^\s*(([A-Z]{1,2})(\d{1,2})([A-Z]?)|[A-Z]{4}|GIR)\s*(\d[A-Z]{2})\s*$/', $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 (isset($zip) and preg_match('/^\s*(([A-Za-z])(\d)([A-Za-z]))\s*(\d[A-Za-z]\d)\s*$/', $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>");
$values = array_replace($values, $this->helper->getAddressZIP($zip));
return $values;
}
/**
......
......@@ -6,7 +6,7 @@
<authorUrl>http://www.open-tools.net</authorUrl>
<copyright>Copyright (C) 2013-2014, Reinhold Kainhofer</copyright>
<license>GPL v3+</license>
<version>6.1.2</version>
<version>6.1.3</version>
<description>OTSHIPMENT_RULES_ADV_DESC</description>
<files>
<filename plugin="rules_shipping_advanced">rules_shipping_advanced.php</filename>
......
......@@ -325,8 +325,6 @@ class RulesShippingFrameworkJoomla extends RulesShippingFramework {
/** Allow child classes to add additional variables for the rules or modify existing one
*/
protected function addCustomCartValues ($cart, $products, $method, &$values) {
}
protected function addPluginCartValues($cart, $products, $method, &$values) {
// Finally, call the triger of vmshipmentrules plugins to let them add/modify variables
JPluginHelper::importPlugin('vmshipmentrules');
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment