Zen Cart Logo
Forums / Addon Shipping Modules / ZipShip - Support Thread

ZipShip - Support Thread

Views: 53,121

Results 61 to 80 of 109
10 Dec 2020, 8:46 PM
#61
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

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.

                $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 = '')
10 Dec 2020, 9:12 PM
#62
allmart avatar

allmart

Zen Follower

Join Date:
Feb 2016
Location:
Canada
Posts:
192
Plugin Contributions:
0

Re: ZipShip - Support Thread

You are the "Sensei". I will give it a whirl tomorrow and let you know.

Cheers!!!

11 Dec 2020, 2:09 PM
#63
allmart avatar

allmart

Zen Follower

Join Date:
Feb 2016
Location:
Canada
Posts:
192
Plugin Contributions:
0

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.

11 Dec 2020, 4:29 PM
#64
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,089
Plugin Contributions:
56

Re: ZipShip - Support Thread

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.

15 Dec 2020, 7:28 PM
#65
allmart avatar

allmart

Zen Follower

Join Date:
Feb 2016
Location:
Canada
Posts:
192
Plugin Contributions:
0

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,

15 Dec 2020, 7:43 PM
#66
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,089
Plugin Contributions:
56

Re: ZipShip - Support Thread

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.

15 Dec 2020, 9:20 PM
#67
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: ZipShip - Support Thread

lat9:

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.

21 Dec 2020, 4:48 PM
#68
allmart avatar

allmart

Zen Follower

Join Date:
Feb 2016
Location:
Canada
Posts:
192
Plugin Contributions:
0

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:

PHP Warning:  strpos(): Empty needle in /***/***/***includes/modules/shipping/zipship.php on line 113

Line 113 is listed in red below.

               $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!

21 Dec 2020, 5:10 PM
#69
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: ZipShip - Support Thread

What are all your zone rules? It seems like you've left one that has only a ! on its own.

21 Dec 2020, 6:22 PM
#70
allmart avatar

allmart

Zen Follower

Join Date:
Feb 2016
Location:
Canada
Posts:
192
Plugin Contributions:
0

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

7 Feb 2023, 7:24 PM
#71
weif avatar

weif

New Zenner

Join Date:
Mar 2010
Location:
Butte, MT
Posts:
83
Plugin Contributions:
0

Re: ZipShip - Support Thread

I'm running into an odd error in ZipShip 3.0.1 on Zen-Cart 1.5.7c.

For the one zone that has two zip codes (entered as: 98571,98562), the shipping option does not display. It also does not display on the zones listed after the one with two zip codes...

for all the other zones, where there is only one zip code, it works fine.

When the address is in a working zone, the user sees this on the shipping page:

Shipping Method:
This is currently the only shipping method available to use on this order.
Zipcode Rate
$12.00
Deliver To Zipcode: 98535

But in the non-working zone, they only get this:

Shipping Method:
This is currently the only shipping method available to use on this order.

I suspect something is getting boogered with the comma...

Any ideas?

7 Feb 2023, 7:38 PM
#72
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,089
Plugin Contributions:
56

Re: ZipShip - Support Thread

weif:

I'm running into an odd error in ZipShip 3.0.1 on Zen-Cart 1.5.7c.

For the one zone that has two zip codes (entered as: 98571,98562), the shipping option does not display. It also does not display on the zones listed after the one with two zip codes...

for all the other zones, where there is only one zip code, it works fine.

When the address is in a working zone, the user sees this on the shipping page:

But in the non-working zone, they only get this:

I suspect something is getting boogered with the comma...

Any ideas?
Not at the moment, but are there any PHP issues logged in the site's /logs directory?

7 Feb 2023, 7:39 PM
#73
weif avatar

weif

New Zenner

Join Date:
Mar 2010
Location:
Butte, MT
Posts:
83
Plugin Contributions:
0

Re: ZipShip - Support Thread

weif:

I suspect something is getting boogered with the comma...

Well, it appears to not be the comma...

I thought that the easiest way to address the issue for the moment, would be to add another zone by modifying the /includes/modules/shipping/zipship.php and changing the $this->num_zones value, but that didn't work.

Now I have only one zip code in each zone, but only the first 3 zones work. Zones 4, 5, and 6 don't. The result is the same - three zip codes show the 'this is the only option" text, but don't actually give the option...

7 Feb 2023, 7:56 PM
#74
weif avatar

weif

New Zenner

Join Date:
Mar 2010
Location:
Butte, MT
Posts:
83
Plugin Contributions:
0

Re: ZipShip - Support Thread

lat9:

Not at the moment, but are there any PHP issues logged in the site's /logs directory?

THANK YOU!

This appears to be an undocumented expected behavior...

From log files:

[07-Feb-2023 11:17:34 America/Los_Angeles] Request URI: /index.php?main_page=checkout_shipping, IP address: 63.153.103.46
#1  trigger_error() called at [/var/www/vhosts/artisticdesignsbybrenda.com/httpdocs/includes/modules/shipping/zipship.php:195]
#2  zipship->getQuote() called at [/var/www/vhosts/artisticdesignsbybrenda.com/httpdocs/includes/modules/shipping/zipship.php:108]
#3  zipship->quote() called at [/var/www/vhosts/artisticdesignsbybrenda.com/httpdocs/includes/classes/shipping.php:174]
#4  shipping->quote() called at [/var/www/vhosts/artisticdesignsbybrenda.com/httpdocs/includes/modules/pages/checkout_shipping/header_php.php:184]
#5  require(/var/www/vhosts/artisticdesignsbybrenda.com/httpdocs/includes/modules/pages/checkout_shipping/header_php.php) called at [/var/www/vhosts/artisticdesignsbybrenda.com/httpdocs/index.php:35]
--> PHP Warning: Missing title (MODULE_SHIPPING_ZIPSHIP_TEXT_TITLE_4) or way (MODULE_SHIPPING_ZIPSHIP_TEXT_WAY_4) for the 'english' language; zipship is disabled. in /var/www/vhosts/artisticdesignsbybrenda.com/httpdocs/includes/modules/shipping/zipship.php on line 195.

I think that what is needed is an addition to the documentation where it says, "Starting with v3.0.0, you can customize the text displayed to the customer for each of the defined postcode zones..." Maybe at the end of that paragraph it should add something to the effect of, "If you have added additional zones, you MUST add entries to this file for each zone added."

7 Feb 2023, 9:34 PM
#75
weif avatar

weif

New Zenner

Join Date:
Mar 2010
Location:
Butte, MT
Posts:
83
Plugin Contributions:
0

Re: ZipShip - Support Thread

weif:

I think that what is needed is an addition to the documentation where it says, "Starting with v3.0.0, you can customize the text displayed to the customer for each of the defined postcode zones..." Maybe at the end of that paragraph it should add something to the effect of, "If you have added additional zones, you MUST add entries to this file for each zone added."

Sorry, I forgot to include the fix.

In the /includes/languages/english/modules/shipping[/YOUR_TEMPLATE]/zipship.php file (and/or other languages, as appropriate for your site), you need to add entries for:

MODULE_SHIPPING_ZIPSHIP_TEXT_TITLE_[x]
MODULE_SHIPPING_ZIPSHIP_TEXT_WAY_[x]

(where [x] is the number of the zone in the zipship configuration). This needs to be done for each zone added beyond the default three.

So if you have six zones, and have changed $this->num_zones = 3; to ```
$this->num_zones = 6;

define('MODULE_SHIPPING_ZIPSHIP_TEXT_TITLE_4', 'Zipcode Rate');
define('MODULE_SHIPPING_ZIPSHIP_TEXT_WAY_4', 'Deliver To Zipcode: ');

define('MODULE_SHIPPING_ZIPSHIP_TEXT_TITLE_5', 'Zipcode Rate');
define('MODULE_SHIPPING_ZIPSHIP_TEXT_WAY_5', 'Deliver To Zipcode: ');

define('MODULE_SHIPPING_ZIPSHIP_TEXT_TITLE_6', 'Zipcode Rate');
define('MODULE_SHIPPING_ZIPSHIP_TEXT_WAY_6', 'Deliver To Zipcode: ');

You may want or need to change these from the default text.
7 Feb 2023, 9:36 PM
#76
dbltoe avatar

dbltoe

Totally Zenned

Join Date:
Jan 2004
Location:
N of San Antonio TX
Posts:
9,794
Plugin Contributions:
15

Re: ZipShip - Support Thread

THANX for providing the fix.

I'm sure it will help others now and in the future.

10 Feb 2023, 2:01 PM
#77
royaldave avatar

royaldave

Zen Follower

Join Date:
Aug 2013
Location:
Perth, WA, AU
Posts:
284
Plugin Contributions:
1

Re: ZipShip - Support Thread

interesting.. I've used zipship for as long as I've used zencart and never had to do this.

However I do have this coding amendment in mine -

            //$this->dest_zipcode = substr(strtoupper($order->delivery['postcode']), 0, (int)ENTRY_POSTCODE_MIN_LENGTH);
            $this->dest_zipcode = strtoupper ($order->delivery['postcode']); 

Dumb dumb me didn't comment why, but I wonder if it might be a simpler solution...

10 Feb 2023, 4:02 PM
#78
weif avatar

weif

New Zenner

Join Date:
Mar 2010
Location:
Butte, MT
Posts:
83
Plugin Contributions:
0

Re: ZipShip - Support Thread

royaldave:

interesting.. I've used zipship for as long as I've used zencart and never had to do this.

However I do have this coding amendment in mine -

            //$this->dest_zipcode = substr(strtoupper($order->delivery['postcode']), 0, (int)ENTRY_POSTCODE_MIN_LENGTH);
            $this->dest_zipcode = strtoupper ($order->delivery['postcode']); 

Dumb dumb me didn't comment why, but I wonder if it might be a simpler solution...

I don't think so.

That 'correction' appears to be reinstating an old issue where zip codes had to be entered exactly matching what's in the zipship configuration.

For example, if you used the zip code 59701 in one zone and the zip code 59711 in another zone, but the customer entered 59701-8208, the customer gets a notice that you are not shipping to that area. Adding the substring check fixes this for US ZIP codes where most people will only use the 5 digit, but some use the 9 digit ZIP+ code.

(So, the fix you commented out addresses a different issue that I encountered very shortly after installing this on a site years ago...)

18 Jan 2024, 1:57 AM
#79
nicksab avatar

nicksab

Totally Zenned

Join Date:
Apr 2011
Posts:
592
Plugin Contributions:
0

Re: ZipShip - Support Thread

ZC 1.5.7 with one page checkout and Bootstrap.

For the love of ..., I can't get it to work.

I set my zones as follow:

Zone 1 Zip Codes
94939

Zone 1 Shipping Table
9999:9.99

Zone 1 Handling Fee
0

Zone 2 Zip Codes
94901,94903,94904

Zone 2 Shipping Table
9999:12.99

Zone 2 Handling Fee
0

Zone 3 is blank

I am getting the "Sorry, we are not shipping to your region at this time." no matter which zip codes i try.

If i set zone 3 like this

Zone 3 Zip Codes

Zone 3 Shipping Table
999:14.99

Zone 3 Handling Fee
0

The shipping default to $14.99 no matter which zip i enter in the shipping address.

I am no getting any errors logs or anything.

What am I doing wrong? Any help on figuring this out would be appreciated?

Thank you

P.S: I noticed the zip code gets truncated in the shipping method box and shopping cart. (i.e: Deliver To Zipcode: 9493).
If i change the delivery address zip code on the checkout page from 94939 to 94903 , the Zip Code display in shipping method changes but the zip in the shopping cart box remains to 9493.
Attachment 20453

Attachment 20454
Attachment 20455

18 Jan 2024, 7:50 AM
#80
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,089
Plugin Contributions:
56

Re: ZipShip - Support Thread

Set Configuration :: Minimum Values :: Post Code to 5 (it defaults to 4).