Page 7 of 10 FirstFirst ... 56789 ... LastLast
Results 61 to 70 of 93
  1. #61
    Join Date
    Jan 2004
    Posts
    66,373
    Blog Entries
    7
    Plugin Contributions
    274

    Default 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 = '')
    Last edited by DrByte; 15 Dec 2020 at 10:21 PM. Reason: updated usort to be called twice; better PHP 8.0 compatibility
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

  2. #62
    Join Date
    Feb 2016
    Location
    Canada
    Posts
    143
    Plugin Contributions
    0

    Default Re: ZipShip - Support Thread

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

    Cheers!!!

  3. #63
    Join Date
    Feb 2016
    Location
    Canada
    Posts
    143
    Plugin Contributions
    0

    Default 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.

  4. #64
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    12,472
    Plugin Contributions
    88

    Default Re: ZipShip - Support Thread

    Quote Originally Posted by allmart View Post
    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.

  5. #65
    Join Date
    Feb 2016
    Location
    Canada
    Posts
    143
    Plugin Contributions
    0

    Default 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,

  6. #66
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    12,472
    Plugin Contributions
    88

    Default Re: ZipShip - Support Thread

    Quote Originally Posted by allmart View Post
    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.

  7. #67
    Join Date
    Jan 2004
    Posts
    66,373
    Blog Entries
    7
    Plugin Contributions
    274

    Default Re: ZipShip - Support Thread

    Quote Originally Posted by lat9 View Post
    Quote Originally Posted by allmart View Post
    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.
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

  8. #68
    Join Date
    Feb 2016
    Location
    Canada
    Posts
    143
    Plugin Contributions
    0

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

  9. #69
    Join Date
    Jan 2004
    Posts
    66,373
    Blog Entries
    7
    Plugin Contributions
    274

    Default Re: ZipShip - Support Thread

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

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

  10. #70
    Join Date
    Feb 2016
    Location
    Canada
    Posts
    143
    Plugin Contributions
    0

    Default 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

 

 
Page 7 of 10 FirstFirst ... 56789 ... LastLast

Similar Threads

  1. Hebrew Support - latest release [Support Thread]
    By eranariel in forum Addon Language Packs
    Replies: 19
    Last Post: 23 Jan 2023, 08:04 AM
  2. SysCheck [support thread]
    By swguy in forum All Other Contributions/Addons
    Replies: 36
    Last Post: 24 Oct 2020, 05:28 AM
  3. v151 Ship2Pay Support thread
    By Design75 in forum All Other Contributions/Addons
    Replies: 9
    Last Post: 5 Nov 2019, 01:14 PM
  4. goMobile Support Thread
    By steveyork136 in forum Addon Templates
    Replies: 29
    Last Post: 26 Aug 2015, 11:56 AM
  5. ZJ Silver Support Thread
    By anthonyd in forum Addon Templates
    Replies: 220
    Last Post: 5 Nov 2010, 03:30 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg
Zen-Cart, Internet Selling Services, Klamath Falls, OR