Page 1 of 2 12 LastLast
Results 1 to 10 of 14
  1. #1
    Join Date
    Jun 2011
    Posts
    2
    Plugin Contributions
    0

    help question Restrict Shipping of a category of products from certain states

    Hello,

    I am using version 1.3.9. I am setting up a store for someone who is selling personal protection items. He will only have about 50 products total.

    There are some items (10 at most) he cannot ship to certain states. I will most likely be using the free shipper module because my client is setting his prices manually. I am open to suggestion.

    I know that the zones is for countries, but these products will only be sold in the US. So I need a way to restrict them based on category and state somehow.

    I would like people to be able to purchase those items in any state, but restrict them from shipping to a few states.

    Can anyone point me in the right direction? I have seen a few posts asking for similar things, but they are very old and there don't seem to be any answers.

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

    Default Re: Restrict Shipping of a category of products from certain states

    Assuming you have your shop setup correctly to use the FREE SHIPPING! freeshipper shipping module ...

    Let's assume that products_id 12, 22, 27 or 122 cannot be shipped to Florida zone_id 18 and New York zone_id 43 cannot be shipped to ...

    You could customize the FREE SHIPPING! freeshipper with the following code in red:
    Code:
            if ($check_flag == false) {
              $this->enabled = false;
            }
          }
    
    // bof: do not show if products_id 12, 22, 27 or 122 are in the cart
          if (!IS_ADMIN_FLAG) {
            global $cart;
            $chk_products_in_cart = $_SESSION['cart']->get_product_id_list();
            $chk_products = '12, 22, 27, 122';
            $arr1 = explode(", ", $chk_products);
            $arr2 = explode(", ", $chk_products_in_cart);
            $donotshow = array_intersect($arr1, $arr2);
    
            // do not show florida 18 and new york 43
            $chk_delivery_zone = $order->delivery['zone_id'];
            $chk_states = '18, 43';
            $arr1 = explode(", ", $chk_states);
            $arr2 = explode(", ", $chk_delivery_zone);
            $donotshow_state = array_intersect($arr1, $arr2);
            if ((int)$donotshow_state && (int)$donotshow) {
              $this->enabled = false;
            }
          }
    // eof: do not show if products_id 12, 22, 27 or 122 are in the cart
    
        }
    
    // class methods
        function quote($method = '') {
    Not the neatest code, but it gets the job done ...
    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
    Jun 2011
    Posts
    2
    Plugin Contributions
    0

    Default Re: Restrict Shipping of a category of products from certain states

    Okay, Great! I didn't expect such a thorough reply. I will give this a try. Thank you so much!

  4. #4
    Join Date
    May 2010
    Location
    Sydney
    Posts
    2
    Plugin Contributions
    0

    Default Re: Restrict Shipping of a category of products from certain states

    Hi there,

    I also found this really useful and it works a treat, thank you.

    Only thing is orders that include products with attributes are still allowed to go through.

    Not sure if I've missed something obvious but I can't seem to get my head around it. Any tips?
    Last edited by troymo; 30 Jun 2011 at 10:18 AM. Reason: typo

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

    Default Re: Restrict Shipping of a category of products from certain states

    Instead, try using:
    Code:
    // bof: do not show if products_id 12, 22, 27 or 122 are in the cart
          if (!IS_ADMIN_FLAG) {
            global $cart;
    
            $chk_products_in_cart = 0;
            $chk_products_in_cart += $_SESSION['cart']->in_cart_check('products_id', '12');
            $chk_products_in_cart += $_SESSION['cart']->in_cart_check('products_id', '22');
            $chk_products_in_cart += $_SESSION['cart']->in_cart_check('products_id', '27');
            $chk_products_in_cart += $_SESSION['cart']->in_cart_check('products_id', '122');
    
            // do not show florida 18 and new york 43
            $chk_delivery_zone = $order->delivery['zone_id'];
            $chk_states = '18, 43';
            $arr1 = explode(", ", $chk_states);
            $arr2 = explode(", ", $chk_delivery_zone);
            $donotshow_state = array_intersect($arr1, $arr2);
            if ((int)$donotshow_state && $donotshow > 0) {
              $this->enabled = false;
            }
          }
    // eof: do not show if products_id 12, 22, 27 or 122 are in the cart
    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!

  6. #6
    Join Date
    May 2010
    Location
    Sydney
    Posts
    2
    Plugin Contributions
    0

    Default Re: Restrict Shipping of a category of products from certain states

    Apologies for the delayed reply here.

    Still couldn't get this to work using the amended code above.

    Sorry to be a bother, is there another way I can try?

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

    Default Re: Restrict Shipping of a category of products from certain states

    Make sure you use the correct products_id values ... and this assumes these products are marked Always Free Shipping or as 0 weight where 0 weight is defined as Free Shipping in the Configuration ... Shipping/Packaging ...

    This blocks Florida and New York ... so use the correct values for that too ...

    NOTE: I had a typo ...

    This is the full code for the:
    /includes/modules/shipping/freeshipper.php

    Code:
    <?php
    /**
     * @package shippingMethod
     * @copyright Copyright 2003-2009 Zen Cart Development Team
     * @copyright Portions Copyright 2003 osCommerce
     * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
     */
    // $Id: freeshipper.php 14498 2009-10-01 20:16:16Z ajeh $
    //
      class freeshipper {
        var $code, $title, $description, $icon, $enabled;
    
    // class constructor
        function freeshipper() {
          global $order, $db;
    
          $this->code = 'freeshipper';
          $this->title = MODULE_SHIPPING_FREESHIPPER_TEXT_TITLE;
          $this->description = MODULE_SHIPPING_FREESHIPPER_TEXT_DESCRIPTION;
          $this->sort_order = MODULE_SHIPPING_FREESHIPPER_SORT_ORDER;
          $this->icon = '';
          $this->tax_class = MODULE_SHIPPING_FREESHIPPER_TAX_CLASS;
    
          // enable only when entire cart is free shipping
    //      if ($_SESSION['cart']->in_cart_check('product_is_always_free_shipping','1') == $_SESSION['cart']->count_contents()) {
          if (zen_get_shipping_enabled($this->code)) {
            $this->enabled = ((MODULE_SHIPPING_FREESHIPPER_STATUS == 'True') ? true : false);
          }
    
          if ( ($this->enabled == true) && ((int)MODULE_SHIPPING_FREESHIPPER_ZONE > 0) ) {
            $check_flag = false;
            $check = $db->Execute("select zone_id from " . TABLE_ZONES_TO_GEO_ZONES . " where geo_zone_id = '" . MODULE_SHIPPING_FREESHIPPER_ZONE . "' and zone_country_id = '" . $order->delivery['country']['id'] . "' order by zone_id");
            while (!$check->EOF) {
              if ($check->fields['zone_id'] < 1) {
                $check_flag = true;
                break;
              } elseif ($check->fields['zone_id'] == $order->delivery['zone_id']) {
                $check_flag = true;
                break;
              }
              $check->MoveNext();
            }
    
            if ($check_flag == false) {
              $this->enabled = false;
            }
          }
    
    
    // bof: do not show if products_id 12, 22, 27 or 122 are in the cart
          if (!IS_ADMIN_FLAG) {
            global $cart;
    
            $chk_products_in_cart = 0;
            $chk_products_in_cart += $_SESSION['cart']->in_cart_check('products_id', '12');
            $chk_products_in_cart += $_SESSION['cart']->in_cart_check('products_id', '22');
            $chk_products_in_cart += $_SESSION['cart']->in_cart_check('products_id', '27');
            $chk_products_in_cart += $_SESSION['cart']->in_cart_check('products_id', '122');
    
            // do not show florida 18 and new york 43
            $chk_delivery_zone = $order->delivery['zone_id'];
            $chk_states = '18, 43';
            $arr1 = explode(", ", $chk_states);
            $arr2 = explode(", ", $chk_delivery_zone);
            $donotshow_state = array_intersect($arr1, $arr2);
            if ((int)$donotshow_state && $chk_products_in_cart > 0) {
              $this->enabled = false;
            }
          }
    // eof: do not show if products_id 12, 22, 27 or 122 are in the cart
    
        }
    
    // class methods
        function quote($method = '') {
          global $order;
    
          $this->quotes = array('id' => $this->code,
                                'module' => MODULE_SHIPPING_FREESHIPPER_TEXT_TITLE,
                                'methods' => array(array('id' => $this->code,
                                                         'title' => MODULE_SHIPPING_FREESHIPPER_TEXT_WAY,
                                                         'cost' => MODULE_SHIPPING_FREESHIPPER_COST + MODULE_SHIPPING_FREESHIPPER_HANDLING)));
    
          if ($this->tax_class > 0) {
            $this->quotes['tax'] = zen_get_tax_rate($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);
          }
    
          if (zen_not_null($this->icon)) $this->quotes['icon'] = zen_image($this->icon, $this->title);
    
          return $this->quotes;
        }
    
        function check() {
          global $db;
          if (!isset($this->_check)) {
            $check_query = $db->Execute("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_SHIPPING_FREESHIPPER_STATUS'");
            $this->_check = $check_query->RecordCount();
          }
          return $this->_check;
        }
    
        function install() {
          global $db;
          $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Enable Free Shipping', 'MODULE_SHIPPING_FREESHIPPER_STATUS', 'True', 'Do you want to offer Free shipping?', '6', '0', 'zen_cfg_select_option(array(\'True\', \'False\'), ', now())");
          $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Free Shipping Cost', 'MODULE_SHIPPING_FREESHIPPER_COST', '0.00', 'What is the Shipping cost?', '6', '6', now())");
          $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Handling Fee', 'MODULE_SHIPPING_FREESHIPPER_HANDLING', '0', 'Handling fee for this shipping method.', '6', '0', now())");
          $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, use_function, set_function, date_added) values ('Tax Class', 'MODULE_SHIPPING_FREESHIPPER_TAX_CLASS', '0', 'Use the following tax class on the shipping fee.', '6', '0', 'zen_get_tax_class_title', 'zen_cfg_pull_down_tax_classes(', now())");
          $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, use_function, set_function, date_added) values ('Shipping Zone', 'MODULE_SHIPPING_FREESHIPPER_ZONE', '0', 'If a zone is selected, only enable this shipping method for that zone.', '6', '0', 'zen_get_zone_class_title', 'zen_cfg_pull_down_zone_classes(', now())");
          $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Sort Order', 'MODULE_SHIPPING_FREESHIPPER_SORT_ORDER', '0', 'Sort order of display.', '6', '0', now())");
        }
    
        function remove() {
          global $db;
          $db->Execute("delete from " . TABLE_CONFIGURATION . " where configuration_key like 'MODULE\_SHIPPING\_FREESHIPPER\_%'");
        }
    
        function keys() {
          return array('MODULE_SHIPPING_FREESHIPPER_STATUS', 'MODULE_SHIPPING_FREESHIPPER_COST', 'MODULE_SHIPPING_FREESHIPPER_HANDLING', 'MODULE_SHIPPING_FREESHIPPER_TAX_CLASS', 'MODULE_SHIPPING_FREESHIPPER_ZONE', 'MODULE_SHIPPING_FREESHIPPER_SORT_ORDER');
        }
      }
    ?>
    Last edited by Ajeh; 5 Jul 2011 at 03:44 AM.
    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!

  8. #8
    Join Date
    Jan 2011
    Posts
    196
    Plugin Contributions
    0

    Default Re: Restrict Shipping of a category of products from certain states

    I am trying to adopt this restriction. Is it possible to restrict master category at once? Instead of 100's of products individually?

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

    Default Re: Restrict Shipping of a category of products from certain states

    For master_categories_id restrictions rather than products_id restrictions you would change:
    Code:
            $chk_products_in_cart += $_SESSION['cart']->in_cart_check('products_id', '12');
    to use:
    Code:
            $chk_products_in_cart += $_SESSION['cart']->in_cart_check('master_categories_id', '10');
    in a similar manner ... just remove any of the lines that you do not need to figure out the $chk_products_in_cart
    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!

  10. #10
    Join Date
    Jan 2011
    Posts
    196
    Plugin Contributions
    0

    Default Re: Restrict Shipping of a category of products from certain states

    That works! Thank you.

    I have products that ONLY SHIPS WITHIN HOME STATE. So, in this case, NY, zone 43 is the only allowed-to-ship state. If I list exceptions, too many to list and too many unknowns. Is it possible to change the code that way? 'IF NOT ZONE 43, disable"

 

 
Page 1 of 2 12 LastLast

Similar Threads

  1. v151 Can I restrict certain shipping modules for certain products?
    By gumboot in forum Built-in Shipping and Payment Modules
    Replies: 10
    Last Post: 13 Feb 2013, 05:26 AM
  2. restrict shipping certain products to certain states?
    By airtime in forum Built-in Shipping and Payment Modules
    Replies: 2
    Last Post: 18 Jan 2011, 05:11 AM
  3. Is it possible to restrict certain items to be sold in specific US states?
    By iscatech in forum Setting Up Categories, Products, Attributes
    Replies: 1
    Last Post: 30 Sep 2010, 02:21 AM
  4. Restrict Country IP's from Certain Category
    By Ruthless in forum General Questions
    Replies: 1
    Last Post: 13 Jan 2010, 02:35 PM
  5. shipping of certain products restricted to certain states?
    By jaxon in forum Built-in Shipping and Payment Modules
    Replies: 1
    Last Post: 3 Jul 2007, 05:08 AM

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