Re: ZipShip - Support Thread
Here's a radical experiment.
1. For pattern matching, I wonder if we can skip using the *'s idea and just assume a "prefix". That is, for M***** just list M, and for L4**** just use L4.
2. In any listed postal code, if you add a "!" at the beginning or end of the code, it will exclude that one. eg: M4B1Y! or !M4B1Y would exclude all M4B1Y* codes.
3. I also added stripping of hyphens ... so in theory this can also work for US zip codes where someone wants to add specificity in zip-plus-four format. (The original code trimmed all zips to the "minimum allowed length" in order to do matching, which kills the ability to do pattern-matching and negation.)
One caveat to note: if a postalcode pattern is present in more than one zone, the "last" non-excluded match will be used for calculating rates. (eg: if it matches in zones 1 and 3, then the rates from zone 3 will apply, ignoring its existence in zone 1).
Here's the updated code which does all this.
Code:
$this->dest_zone = false;
$this->default_zone = false;
// $this->dest_zipcode = substr(strtoupper($order->delivery['postcode']), 0, (int)ENTRY_POSTCODE_MIN_LENGTH);
$this->dest_zipcode = strtoupper(str_replace([' ', '-'], '', $order->delivery['postcode']));
for ($i = 1; $i <= $this->num_zones; $i++) {
$current_table = "MODULE_SHIPPING_ZIPSHIP_CODES_$i";
if (defined($current_table)) {
$zipcode_table = constant($current_table);
if ($zipcode_table === '00000') {
$this->default_zone = $i;
} else {
// Read codes from config
$zipcodes = explode(',', str_replace([' ', '-'], '', strtoupper($zipcode_table)));
// sort codes, first by alpha, then by reverse-length so we process longest-first
usort($zipcodes, function($a, $b){
$a = trim($a, '!');
$b = trim($b, '!');
return strcmp($a, $b);
});
usort($zipcodes, function($a, $b){
$a = trim($a, '!');
$b = trim($b, '!');
return (strlen($a) < strlen($b)) ? 1 : -1;
});
// Check for exclusion patterns defined with a starting or ending ! symbol
foreach($zipcodes as $check_against) {
if ($check_against === '!' || strpos($check_against, '!') === false) continue; // if no ! skip checking this iteration
if (strpos($this->dest_zipcode, trim($check_against, '!')) === 0) { // strip ! to do matching
$this->dest_zone = false;
// If exclusion detected, use "continue" to end this foreach and skip the next one as well
continue 2;
}
}
// Pass if the supplied code matches a defined prefix pattern
foreach($zipcodes as $check_against) {
if (strpos($check_against, '!') !== false) continue;
if (strpos($this->dest_zipcode, $check_against) === 0) {
$this->dest_zone = $i;
// If a match is found, end this foreach
break;
}
}
}
}
}
if ($this->dest_zone === false && $this->default_zone === false) {
$this->enabled = false;
}
}
}
}
public function quote($method = '')
Re: ZipShip - Support Thread
You are the "Sensei". I will give it a whirl tomorrow and let you know.
Cheers!!!
Re: ZipShip - Support Thread
Preliminary tests look great ... thanks! I am trying to add more zones by changing $this->num_zones = 3; but nothing happens.
Re: ZipShip - Support Thread
Quote:
Originally Posted by
allmart
Preliminary tests look great ... thanks! I am trying to add more zones by changing $this->num_zones = 3; but nothing happens.
To change the number of zones, you'll need to "Remove" the module (after saving a copy of any zipcodes currently configured), update the number of zones and then re-install.
Re: ZipShip - Support Thread
I am using One Page Checkout, when a postal code is not within our delivery area a pop-up displays "Please contact the store owner; some required elements of this page are missing." Once OK is clicked then the page is displayed without the shipping and payment details and a message Not Available At This Time Sorry, we are not shipping to your region at this time. Please contact us for alternate arrangements. Anyway of not displaying the initial pop-up?
Thanks,
Re: ZipShip - Support Thread
Quote:
Originally Posted by
allmart
I am using One Page Checkout, when a postal code is not within our delivery area a pop-up displays "Please contact the store owner; some required elements of this page are missing." Once OK is clicked then the page is displayed without the shipping and payment details and a message Not Available At This Time Sorry, we are not shipping to your region at this time. Please contact us for alternate arrangements. Anyway of not displaying the initial pop-up?
Thanks,
That "some required elements are missing" message indicates that the template 'rendering' of the page is missing some required jQuery selectors. You can view the browser's "Console Log" by pressing F12 and then the 'Console' tab. That will contain information that identifies which elements are missing.
Re: ZipShip - Support Thread
Quote:
Originally Posted by
lat9
Quote:
Originally Posted by
allmart
I am using One Page Checkout, when a postal code is not within our delivery area a pop-up displays "Please contact the store owner; some required elements of this page are missing." Once OK is clicked then the page is displayed without the shipping and payment details and a message Not Available At This Time Sorry, we are not shipping to your region at this time. Please contact us for alternate arrangements. Anyway of not displaying the initial pop-up?
Thanks,
That "some required elements are missing" message indicates that the template 'rendering' of the page is missing some required jQuery selectors. You can view the browser's "Console Log" by pressing F12 and then the 'Console' tab. That will contain information that identifies which elements are missing.
Actually this situation is not a result of anything wrong with ZipShip.
OPC appears not to be expecting "no shipping results at all", so it's croaking.
I've opened issue https://github.com/lat9/one_page_checkout/issues/285 where I describe more details about it.
Re: ZipShip - Support Thread
I tried implementing this mod but nothing happens when you press the "confirm order" button and listed below is what is listed in the log:
Code:
PHP Warning: strpos(): Empty needle in /***/***/***includes/modules/shipping/zipship.php on line 113
Line 113 is listed in red below.
Code:
$this->dest_zone = false;
$this->default_zone = false;
// $this->dest_zipcode = substr(strtoupper($order->delivery['postcode']), 0, (int)ENTRY_POSTCODE_MIN_LENGTH);
$this->dest_zipcode = strtoupper(str_replace([' ', '-'], '', $order->delivery['postcode']));
for ($i = 1; $i <= $this->num_zones; $i++) {
$current_table = "MODULE_SHIPPING_ZIPSHIP_CODES_$i";
if (defined($current_table)) {
$zipcode_table = constant($current_table);
if ($zipcode_table === '00000') {
$this->default_zone = $i;
} else {
// Read codes from config
$zipcodes = explode(',', str_replace([' ', '-'], '', strtoupper($zipcode_table)));
// Sort codes by length (longest first) and alpha
usort($zipcodes, function($a, $b){
$a = trim($a, '!');
$b = trim($b, '!');
return (strlen($a) < strlen($b)) ?: strcmp($b, $a);
});
// 1. For pattern matching, assume a "prefix". That is, for M***** just list M, and for L4**** just use L4.
// 2. In any listed postal code, if you add a "!" at the beginning or end of the code, it will exclude that one. eg: M4B1Y! or !M4B1Y would exclude all M4B1Y* codes.
// One caveat to note: if a postalcode pattern is present in more than one zone, the "last" non-excluded match will be used for calculating rates. (eg: if it matches in zones 1 and 3, then the rates from zone 3 will apply, ignoring its existence in zone 1).
// Check for exclusion patterns defined with a starting or ending ! symbol
foreach($zipcodes as $check_against) {
if (strpos($check_against, '!') === false) continue; // if no ! skip checking this iteration
if (strpos($this->dest_zipcode, trim($check_against, '!')) === 0) { // strip ! to do matching
$this->dest_zone = false;
// If exclusion detected, use "continue" to end this foreach and skip the next one as well
continue 2;
}
}
// Pass if the supplied code matches a defined prefix pattern
foreach($zipcodes as $check_against) {
if (strpos($check_against, '!') !== false) continue;
if (strpos($this->dest_zipcode, $check_against) === 0) {
$this->dest_zone = $i;
// If a match is found, end this foreach
break;
}
}
}
}
}
Thanks in advance for your help!
Re: ZipShip - Support Thread
What are all your zone rules? It seems like you've left one that has only a ! on its own.
Re: ZipShip - Support Thread
I did find that 2 of my postal codes had "######", don't know why but I will correct and see if the issue persists.
Thanks again