Page 1 of 2 12 LastLast
Results 1 to 10 of 12
  1. #1
    Join Date
    Jul 2011
    Location
    Sonoma County, CA, USA
    Posts
    20
    Plugin Contributions
    0

    Default USPS shipping module...trying to restrict shipping options programmatically

    My shop has one category whose products must be shipped via Express Mail. All other products may be shipped either by Priority or Express. If an order contains one or more products from this particular category I need to force Express Mail.

    So, both shipping methods are allowed, and I'm modifying the quote() function per Linda's code in this thread to check for products in category 69 in the cart and disable Priority Mail if that's the case. This code worked great in a past version of the USPS module, but now I'm using the update from March 27 and I can't get it to work.

    Here's the code, from within quote():

    PHP Code:
    // Disable Priority Mail for cheese. ecasteel
            
    if (($this->types[$type] == 'Priority MailRM') && $_SESSION['cart']->in_cart_check('master_categories_id','69') > 0) { 
              
    $skip_this true
            } else { 
              
    $skip_this false
            }
            if (!
    $skip_this) {
            
    // eof ecasteel
              
    if ((($method == '' && in_array($type$types)) || $method == $type) && $usps_shipping_weight <= $maxweight && $usps_shipping_weight $minweight) {
                
    $methods[] = array('id' => $type,
                                   
    'title' => $title,
                                   
    'cost' => $cost,
                                  );
              }
            
    // bof ecasteel
            
    }
            
    // eof ecasteel
          

    I think the problem is how I check for the shipping type. I'm using the string 'Priority MailRM' because that's what I see when I print out the types[] array. I've also tried 'Priority Mail', which is what worked before, and 'Priority Mail®', which is what shows up on the shipping options page during checkout. Do I need to check for a different string? I also tried checking whether the array index was 15, which is where 'Priority MailRM' shows up when I look at the types[] array. Can anyone point me in the right direction?
    Current ZC version: 1.5, upgraded manually from 1.3.9h.
    Mods: CEON URI mapping, Column Layout Grid, EZ Thumbnails, EZ Page Improved TOC, Giftwrap, Hide Categories, Integrated COWOA, USPS and Shipstation, CKEditor.

  2. #2
    Join Date
    Sep 2003
    Location
    Ohio
    Posts
    69,402
    Plugin Contributions
    6

    Default Re: USPS shipping module...trying to restrict shipping options programmatically

    See if this works better for you:
    Code:
              if ($this->usps_countries == 'US' && MODULE_SHIPPING_USPS_FIRST_CLASS_FILTER_US == 'True' && preg_match('#First\-Class#', $type) && $cnt_first > 1) continue;
    // bof: skip Priority MailRM if master_categories_id 69 has more than 1
    if (($type == 'Priority MailRM') && $_SESSION['cart']->in_cart_check('master_categories_id','69') > 0) {
      $skip_this = true;
    //echo 'USPS skip: ' . $type . '<br>';
    } else {
      $skip_this = false;
    //echo 'USPS NO skip: ' . $type . '<br>';
    }
    if ($skip_this) {
      // skip it
    } else {
              $methods[] = array('id' => $type,
                                 'title' => $title,
                                 'cost' => $cost,
                                );
    }
    // eof: skip Priority MailRM if master_categories_id 69 has more than 1
            }
          }
    
          if (sizeof($methods) == 0) return false;
    Linda McGrath
    If you have to think ... you haven't been zenned ...

    Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!

    Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today: v1.5.5]
    Officially PayPal-Certified! Just click here

    Try our Zen Cart Recommended Services - Hosting, Payment and more ...
    Signup for our Announcements Forums to stay up to date on important changes and updates!

  3. #3
    Join Date
    Jul 2011
    Location
    Sonoma County, CA, USA
    Posts
    20
    Plugin Contributions
    0

    Default Re: USPS shipping module...trying to restrict shipping options programmatically

    Brilliant! Thanks so much Linda! I wish I'd thought of testing $type directly. Couldn't see the forest for the trees....
    Current ZC version: 1.5, upgraded manually from 1.3.9h.
    Mods: CEON URI mapping, Column Layout Grid, EZ Thumbnails, EZ Page Improved TOC, Giftwrap, Hide Categories, Integrated COWOA, USPS and Shipstation, CKEditor.

  4. #4
    Join Date
    Sep 2003
    Location
    Ohio
    Posts
    69,402
    Plugin Contributions
    6

    Default Re: USPS shipping module...trying to restrict shipping options programmatically

    You are most welcome ...

    Thanks for the update that this worked for you ...
    Linda McGrath
    If you have to think ... you haven't been zenned ...

    Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!

    Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today: v1.5.5]
    Officially PayPal-Certified! Just click here

    Try our Zen Cart Recommended Services - Hosting, Payment and more ...
    Signup for our Announcements Forums to stay up to date on important changes and updates!

  5. #5
    Join Date
    Jan 2008
    Posts
    144
    Plugin Contributions
    0

    Default Re: USPS shipping module...trying to restrict shipping options programmatically

    I know this is an old thread, but would anyone have an updated solution to this problem using the current USPS module? I'm wanting to disable Ground Advantage for all tax classes except one (tax_class_id = 4). I was trying to modify the solution above but looks like the coding has changed in the last 10 years (no surprise there!). Using 1.5.8a and have the most updated USPS module available. Thanks in advance for any guidance!

  6. #6
    Join Date
    Apr 2006
    Location
    West Salem, IL
    Posts
    2,819
    Plugin Contributions
    0

    Default Re: USPS shipping module...trying to restrict shipping options programmatically

    Refer to the in-module comments present in /extras/includes/classes/observers/auto.usps_overrides.php
    Mike
    AEIIA - Zen Cart Certified & PCI Compliant Hosting
    The Zen Cart Forum...Better than a monitor covered with post-it notes!

  7. #7
    Join Date
    Jan 2008
    Posts
    144
    Plugin Contributions
    0

    Default Re: USPS shipping module...trying to restrict shipping options programmatically

    Quote Originally Posted by barco57 View Post
    Refer to the in-module comments present in /extras/includes/classes/observers/auto.usps_overrides.php
    Thank you for pointing me in the right direction...but could still use some help if possible. Do I add the extra code in the override file, or just use that as a template and add to the usps.php file?

    Second, can you tell me if I'm on the right track with this coding (wherever it ultimately goes)?

    Code:
    if (stripos($p1, 'USPS Ground Advantage') !== false) {
                        $chk_media = 0;
                        $chk_media += $_SESSION['cart']->in_cart_check('products_tax_class_id', '4') > 0;
                        if ($chk_media == $_SESSION['cart']->count_contents()) {
                            $p2 = true;
                        }
                    }
    break;

  8. #8
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    13,410
    Plugin Contributions
    94

    Default Re: USPS shipping module...trying to restrict shipping options programmatically

    Quote Originally Posted by mcqueeneycoins View Post
    Thank you for pointing me in the right direction...but could still use some help if possible. Do I add the extra code in the override file, or just use that as a template and add to the usps.php file?

    Second, can you tell me if I'm on the right track with this coding (wherever it ultimately goes)?

    Code:
    if (stripos($p1, 'USPS Ground Advantage') !== false) {
                        $chk_media = 0;
                        $chk_media += $_SESSION['cart']->in_cart_check('products_tax_class_id', '4') > 0;
                        if ($chk_media == $_SESSION['cart']->count_contents()) {
                            $p2 = true;
                        }
                    }
    break;
    @barco57 has put you on the right track, you want to make your changed to the auto.usps_overrides.php (which you'll place in the site's /includes/classes/observers sub-directory). That way, once working, it'll keep on working through a base USPS module update.

    I'm a bit confused from your description as to what you're trying to do:

    I'm wanting to disable Ground Advantage for all tax classes except one (tax_class_id = 4).
    Does this mean that Ground Advantage should be disallowed if any product in the cart uses tax_class_id 4 or if all products use that tax-class?

  9. #9
    Join Date
    Jan 2008
    Posts
    144
    Plugin Contributions
    0

    Default Re: USPS shipping module...trying to restrict shipping options programmatically

    Quote Originally Posted by lat9 View Post
    I'm a bit confused from your description as to what you're trying to do:

    Does this mean that Ground Advantage should be disallowed if any product in the cart uses tax_class_id 4 or if all products use that tax-class?
    Thanks, lat9--basically I have 3 or 4 different tax classes, one of which is for supplies. The way I have it set up now is the flat-rate option is available for all products except tax class id 4, which works just fine. It then displays only the USPS module with ground advantage and priority mail options when tax class id 4 is present in the cart.

    But, if the cart has no supplies (no products with tax id 4), it displays flat rate, ground advantage and priority mail. I basically need ground advantage to be disabled in this case and only display flat rate and priority.

    THanks!

  10. #10
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    13,410
    Plugin Contributions
    94

    Default Re: USPS shipping module...trying to restrict shipping options programmatically

    Quote Originally Posted by mcqueeneycoins View Post
    Thanks, lat9--basically I have 3 or 4 different tax classes, one of which is for supplies. The way I have it set up now is the flat-rate option is available for all products except tax class id 4, which works just fine. It then displays only the USPS module with ground advantage and priority mail options when tax class id 4 is present in the cart.

    But, if the cart has no supplies (no products with tax id 4), it displays flat rate, ground advantage and priority mail. I basically need ground advantage to be disabled in this case and only display flat rate and priority.

    THanks!
    Thanks for the clarification! You can use the following code in that auto-loaded observer:
    Code:
                case 'NOTIFY_USPS_UPDATE_OR_DISALLOW_TYPE':
                    // -----
                    // Disallow "Ground Advantage" if there are no products with a tax_class_id of 4
                    // in the cart.
                    //
                    if (stripos($p1, 'USPS Ground Advantage') !== false) {
                        if ($_SESSION['cart']->in_cart_check('products_tax_class_id', '4') == 0) {
                            $p2 = false;
                        }
                    }
                    break;

 

 
Page 1 of 2 12 LastLast

Similar Threads

  1. v155 Restrict USPS shipping options by product dimensions
    By HeleneWallis in forum Addon Shipping Modules
    Replies: 12
    Last Post: 29 Feb 2020, 03:30 AM
  2. v151 USPS shipping module - no shipping options being displayed
    By TooMuchMUsic in forum Addon Shipping Modules
    Replies: 4
    Last Post: 26 Sep 2015, 04:00 PM
  3. v151 Restrict Specific Items from 1st Class Shipping - USPS Module
    By jstevens in forum Addon Shipping Modules
    Replies: 5
    Last Post: 22 Jun 2014, 03:03 AM
  4. Replies: 16
    Last Post: 31 May 2012, 07:08 PM
  5. Replies: 2
    Last Post: 1 Jul 2009, 11: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