Results 1 to 6 of 6
  1. #1
    Join Date
    Apr 2014
    Location
    Kansas City, MO
    Posts
    1
    Plugin Contributions
    0

    Default Restrict Specific Items from 1st Class Shipping - USPS Module

    Is there a way to restrict certain items from being able to select First Class Shipping as an option?

    I currently have just 3 items that can't be shipping 1st Class and need to restrict them, but cannot figure out how to do this.

    Thanks for any help in advance.

  2. #2
    Join Date
    Jul 2012
    Posts
    16,816
    Plugin Contributions
    17

    Default Re: Restrict Specific Items from 1st Class Shipping - USPS Module

    Quote Originally Posted by jstevens View Post
    Is there a way to restrict certain items from being able to select First Class Shipping as an option?

    I currently have just 3 items that can't be shipping 1st Class and need to restrict them, but cannot figure out how to do this.

    Thanks for any help in advance.
    So if you look through the usps.php code, you should see one or more sections where there is some documentation about restricting certain types of products/delivery options.

    One way I have seen this done is to link products into a category (say don't delivery via first class), then omit items that are in that category. So after the category is created, grab the category number. Then in the usps code, loop through all of the products and check against the return value of zen_product_in_category( $product_id, $cat_id) where $cat_id would be substituted with say '10'. If it is in that category then disable that option.

    Hopefully that helps.
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

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

    Default Re: Restrict Specific Items from 1st Class Shipping - USPS Module

    To restrict Products in the USPS shipping module, you can add the code in RED around line 377:
    Code:
    if (false) {
      $chk_cart = 0;
      $chk_cart += $_SESSION['cart']->in_cart_check('master_categories_id','12');
      $chk_cart += $_SESSION['cart']->in_cart_check('master_categories_id','15');
    }
    // bof: First-Class block
      $chk_cart = 0;
      $chk_cart += $_SESSION['cart']->in_cart_check('products_id','112');
      $chk_cart += $_SESSION['cart']->in_cart_check('products_id','113');
      $chk_cart += $_SESSION['cart']->in_cart_check('products_id','114');
    // eof: First-Class block
    
    // see below use of $chk_cart
    Then add the code in RED around line 700:
    Code:
    $show_hiddenCost = '';
    
    // bof: First-Class block
    //echo '$type: ' . $type . ' $chk_cart: ' . $chk_cart . ' preg_match: ' . preg_match('#First\-Class#i', $type) . '<br>';
    if ($chk_cart > 0 && preg_match('#First\-Class#i', $type)) {
      // skip first class
    } else {
              $methods[] = array('id' => $type_rebuilt,
                                 'title' => $title . $show_hiddenCost,
                                 'cost' => $cost,
                                );
    }
    // bof: First-Class block
            } else {
    //echo 'MISSING! USPS $type: ' . $type . (in_array($type, $this->typeCheckboxesSelected) ? ' YES' : ' NO') . ' $method: ' . $method . ' $usps_shipping_weight: ' . $usps_shipping_weight . ' $minweight: ' . $minweight . ' $maxweight: ' . $maxweight . '<br>';
            }
          }  // end for $i to $PackageSize
    Just set the products_id 112, 113 and 114 to match your products_id ...

    If you need additional products_id to be used you can copy one of the lines in the first part, if you need less than 3 comment out, from the bottom of the list ...
    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!]
    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!

  4. #4
    Join Date
    Jul 2012
    Posts
    16,816
    Plugin Contributions
    17

    Default Re: Restrict Specific Items from 1st Class Shipping - USPS Module

    Quote Originally Posted by Ajeh View Post
    To restrict Products in the USPS shipping module, you can add the code in RED around line 377:
    Code:
    if (false) {
      $chk_cart = 0;
      $chk_cart += $_SESSION['cart']->in_cart_check('master_categories_id','12');
      $chk_cart += $_SESSION['cart']->in_cart_check('master_categories_id','15');
    }
    // bof: First-Class block
      $chk_cart = 0;
      $chk_cart += $_SESSION['cart']->in_cart_check('products_id','112');
      $chk_cart += $_SESSION['cart']->in_cart_check('products_id','113');
      $chk_cart += $_SESSION['cart']->in_cart_check('products_id','114');
    // eof: First-Class block
    
    // see below use of $chk_cart
    Then add the code in RED around line 700:
    Code:
    $show_hiddenCost = '';
    
    // bof: First-Class block
    //echo '$type: ' . $type . ' $chk_cart: ' . $chk_cart . ' preg_match: ' . preg_match('#First\-Class#i', $type) . '<br>';
    if ($chk_cart > 0 && preg_match('#First\-Class#i', $type)) {
      // skip first class
    } else {
              $methods[] = array('id' => $type_rebuilt,
                                 'title' => $title . $show_hiddenCost,
                                 'cost' => $cost,
                                );
    }
    // bof: First-Class block
            } else {
    //echo 'MISSING! USPS $type: ' . $type . (in_array($type, $this->typeCheckboxesSelected) ? ' YES' : ' NO') . ' $method: ' . $method . ' $usps_shipping_weight: ' . $usps_shipping_weight . ' $minweight: ' . $minweight . ' $maxweight: ' . $maxweight . '<br>';
            }
          }  // end for $i to $PackageSize
    Just set the products_id 112, 113 and 114 to match your products_id ...

    If you need additional products_id to be used you can copy one of the lines in the first part, if you need less than 3 comment out, from the bottom of the list ...
    Ajeh,

    Somewhat of a philosphical question. Above a direct answer was provided to resolve the original question directly. Wht are the cons of using the method I suggested? With the thouught that the products to be omitted from the particular shipping method are controlled in the admin panel instead of hard coded in the shipping module?
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

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

    Default Re: Restrict Specific Items from 1st Class Shipping - USPS Module

    You could do that as well to identify the Products to be excluded ...

    However, now you would need a purpose for the Category that the Products are linked to or have to hide the Category etc.

    Either way, the method used to identify these Products for excluding the First-Class would need to be identified and should be checked around line 377, to avoid extra processing and then the results utilized around line 700 ...

    Again, there are many methods that could be used, some easy and some harder for doing this ...

    A cleaner, but more complicated to to write method would be to add a flag to the products table for something like:
    products_is_firstclass

    and the code to the admin to allow the store owner to identify these Products while adding/editing them so that future Products do not require code changes, once the logic is written into the USPS shipping module ...
    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!]
    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!

  6. #6
    Join Date
    Jul 2012
    Posts
    16,816
    Plugin Contributions
    17

    Default Re: Restrict Specific Items from 1st Class Shipping - USPS Module

    Quote Originally Posted by Ajeh View Post
    You could do that as well to identify the Products to be excluded ...

    However, now you would need a purpose for the Category that the Products are linked to or have to hide the Category etc.

    Either way, the method used to identify these Products for excluding the First-Class would need to be identified and should be checked around line 377, to avoid extra processing and then the results utilized around line 700 ...

    Again, there are many methods that could be used, some easy and some harder for doing this ...

    A cleaner, but more complicated to to write method would be to add a flag to the products table for something like:
    products_is_firstclass

    and the code to the admin to allow the store owner to identify these Products while adding/editing them so that future Products do not require code changes, once the logic is written into the USPS shipping module ...
    Not sure I understand the discussion about having to have a "use" for the category, but yes in the train of thought that I had the category would be effectively disabled (at least not viewable by customers). I'm thinking that if enough such categories were considered that there may be a category off of the top category just for administrative management and then possibly various sub categories off of there related to the type of administrative controls in place. (Ie, shipping, payment, etc.)

    As for the product information aspect, I wonder if controls in that regards are the best use of the various resources and appropriate table normalization. I would think that the field associated with USPS shipping in the product table if used would be constructed much like what lat9 did with ip blocking where multiple pieces of information would exist in the field to be parsed as needed. The question there remains what would be the reference that would be consistent so that heaven forbid the USPS comes up with a new shipping category/renames an existing one, that the field could still be used as is/easily updated.

    I guess though on the aspect of "set it and forget it" if the data is inside the product data then the cart contents need only be parsed once, with a check against the shipping methods, while the method I proposed requires possibly looking through the contents of the category once per product in the cart. (That's assuming there are no other optimizations applied to a search for an item in a list/data table/array/etc...)
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

 

 

Similar Threads

  1. Replies: 2
    Last Post: 18 Jun 2016, 12:27 AM
  2. v139h Restrict shipping module to specific category
    By Lanbo in forum General Questions
    Replies: 12
    Last Post: 28 Mar 2012, 04:13 PM
  3. Obtaining 1st Class USPS Domestic Shipping Rates
    By virage105 in forum Built-in Shipping and Payment Modules
    Replies: 1
    Last Post: 11 Nov 2011, 11:54 PM
  4. Problems with USPS module - won't do 1st class
    By L3Home in forum Built-in Shipping and Payment Modules
    Replies: 3
    Last Post: 21 Jun 2011, 11:28 PM
  5. Free Shipping for ONLY USPS 1st class or Priority Main
    By rubic07 in forum Built-in Shipping and Payment Modules
    Replies: 7
    Last Post: 20 Oct 2009, 05:58 PM

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