Page 2 of 3 FirstFirst 123 LastLast
Results 11 to 20 of 29
  1. #11
    Join Date
    Sep 2003
    Location
    Ohio
    Posts
    69,402
    Plugin Contributions
    6

    Default Re: Free Shipping Options module, how to exclude some categories

    You could write an extensive piece of code for it ...

    I thought somewhere over the last few months I wrote something for a shipping module to take the top level category and build something for that but I cannot recall what or where it might be on the forum ...
    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!

  2. #12
    Join Date
    Mar 2005
    Location
    California
    Posts
    663
    Plugin Contributions
    0

    Default Re: Free Shipping Options module, how to exclude some categories

    I went through all 30 pages of the similar thread 'Different shipping methods for different categories' (http://www.zen-cart.com/forum/showth...=91394&page=30) and 'exclude certain products from free shipping' (http://www.zen-cart.com/forum/showth...ategory&page=3), but could not find a solution for looking up all subcategories.

    I found some code somewhere else on the web and this is what I've come up with:
    PHP Code:
    /**
     * Get all the subcategory IDs of the parent category whose ID
     * is specified.
     *
     * @param integer $parentID
     * @return array
     */
    function getSubcategories ($parentID$self false) {
    $subs = array ();
    if (
    $self) {
    $subs[] = $parentID;
    }
    _getSubcategories ($parentID, &$subs);
    return 
    $subs;
    }
     
    /**
     * Help function for getSubcategories()
     *
     * @param integer $pid
     * @param array $cats
     * @see getSubcategories()
     */
    function _getSubcategories ($pid, &$cats) {
    global 
    $db;
    $sql "SELECT c.categories_id FROM " TABLE_CATEGORIES " c WHERE c.parent_id=$pid";
    $result $db->Execute($sql);
    while (!
    $result->EOF) {
    $cats[] = $result->fields['categories_id'];
    _getSubcategories ($result->fields['categories_id'], &$cats);
    $result->MoveNext();
    }
    }

    $top_cat_ids = array('1','25','35');
    $exclude_categories getSubcategories($top_cat_idstrue)      
                
          global 
    $cart;
          if (!
    IS_ADMIN_FLAG && $_SESSION['cart']->in_cart_check('master_categories_id'$exclude_categories) > 0) {
            
    $this->enabled false;
          } 
    Would this work?

  3. #13
    Join Date
    Mar 2005
    Location
    California
    Posts
    663
    Plugin Contributions
    0

    Default Re: Free Shipping Options module, how to exclude some categories

    The function works, I've put it in the extra functions folder.

    Now I've got all the category ids in an array called $all_cats_exclude

    I'm trying to get it to work here by using
    PHP Code:
          global $cart;
          if (!
    IS_ADMIN_FLAG && $_SESSION['cart']->in_cart_check('master_categories_id'$all_cats_exclude) > 0) {
            
    $this->enabled false;
          } 
    But this is not working.

    Does the function $_SESSION['cart']->in_cart_check('master_categories_id') work with an array or would I need to create a loop to run through all the values in the array?

    (sorry for all the questions, as you can see my php knowledge is very basic)

  4. #14
    Join Date
    Mar 2005
    Location
    California
    Posts
    663
    Plugin Contributions
    0

    Default Re: Free Shipping Options module, how to exclude some categories

    This is what I'm using and it seems to finally work.

    PHP Code:
         if (!IS_ADMIN_FLAG) {
            global 
    $cart;
            foreach(
    $all_cats_exclude as $key => $cat_id_value){
            
    $chk_exclude_categories += $_SESSION['cart']->in_cart_check('master_categories_id',$cat_id_value);
            }
            if (
    $chk_exclude_categories 0) {
              
    $this->enabled false;
            }
          } 
    For the file with the function to get the all the subcategories, it should go in the extra functions folder both in the catalog and admin; otherwise in the admin section it will give the 'call to undefined function" error.

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

    Default Re: Free Shipping Options module, how to exclude some categories

    How are you building your array: $all_cats_exclude
    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. #16
    Join Date
    Mar 2005
    Location
    California
    Posts
    663
    Plugin Contributions
    0

    Default Re: Free Shipping Options module, how to exclude some categories

    sorry, I forgot to include that, here's the complete code that goes in the freeoptions.php file
    Just enter your top category ids in $top_cat_ids = array('1','2','3');
    PHP Code:
    $top_cat_ids = array('1','2','3');
    $all_cats_exclude = array();
    foreach(
    $top_cat_ids as $key => $top_id_value){
    $subcat_results getSubcategories($top_id_valuetrue);
        foreach(
    $subcat_results as $key => $ind_cat_id_value){
            
    $all_cats_exclude[] = $ind_cat_id_value;
        } 

    }

         if (!
    IS_ADMIN_FLAG) {
            global 
    $cart;
            foreach(
    $all_cats_exclude as $key => $cat_id_value){
            
    $chk_exclude_categories += $_SESSION['cart']->in_cart_check('master_categories_id',$cat_id_value);
            }
            if (
    $chk_exclude_categories 0) {
              
    $this->enabled false;
            }
          } 

    Hope this helps someone, I saw many posts asking how to get all the subcategories by entering the top level category, but I could find any available solution.
    Last edited by tj1; 28 Jan 2011 at 10:40 PM.

  7. #17
    Join Date
    Apr 2009
    Posts
    17
    Plugin Contributions
    0

    Default Re: Free Shipping Options module, how to exclude some categories

    I was so happy when I found this, but auugh, I just cannot get it to exclude a category from the free shipping option.

    PHP Code:
    // disable only when entire cart is free shipping
          
    if (zen_get_shipping_enabled($this->code)) {
              
    $this->enabled = ((MODULE_SHIPPING_FREEOPTIONS_STATUS == 'True') ? true false);
          }

          
    //Magical free shipping category exclusion code
          
    $top_cat_ids = array('108','9999','9999');
          
    $all_cats_exclude = array();
          foreach(
    $top_cat_ids as $key => $top_id_value){
            
    $subcat_results getSubcategories($top_id_valuetrue);
            foreach(
    $subcat_results as $key => $ind_cat_id_value){
              
    $all_cats_exclude[] = $ind_cat_id_value;
            } 
          }

          if (!
    IS_ADMIN_FLAG) {
            global 
    $cart;
            foreach(
    $all_cats_exclude as $key => $cat_id_value){
              
    $chk_exclude_categories += $_SESSION['cart']->in_cart_check('master_categories_id',$cat_id_value);
            }
            if (
    $chk_exclude_categories 0) {
              
    $this->enabled false;
            }
          }
          
    //end category exclusion code 
    I have that in my freeoptions.php file. When I have a shopping cart that qualifies for free shipping, then I add a product of master category 108, it still just offers free shipping.

    Am I missing something crucial here?

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

    Default Re: Free Shipping Options module, how to exclude some categories?

    Make sure that when you use the 108 that this is actually the master_categories_id in the products table ...

    You can check this by going to the Catalog ... Categories/Products ... and find the Product and click E for edit and see what it reads for the:
    Product Master Category:

    What are your settings in the Free Shipping Options freeoptions shipping module that you see when you click on it and look at the right panel?
    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!

  9. #19
    Join Date
    Apr 2009
    Posts
    17
    Plugin Contributions
    0

    Default Re: Free Shipping Options module, how to exclude some categories?

    Yep, it's definitely the master categories ID.
    In addition, my settings for the Free Shipping Options are unchanged from the default.

    I cannot seem to get the addition of a product from category 108 to void the free shipping option and present regular shipping options. My category ID should be in the all_cats_exclude() array in the above code, right? I've tried it in both arrays and still I just get a free shipping option.

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

    Default Re: Free Shipping Options module, how to exclude some categories?

    Check the /cache directory and ensure you have no error logs being generated on this ...
    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!

 

 
Page 2 of 3 FirstFirst 123 LastLast

Similar Threads

  1. group pricing exclude some master categories
    By count in forum Discounts/Coupons, Gift Certificates, Newsletters, Ads
    Replies: 0
    Last Post: 20 Jan 2013, 11:42 PM
  2. Limiting shipping options for some product categories
    By ShawnMilo in forum Addon Shipping Modules
    Replies: 13
    Last Post: 26 Jun 2008, 01:46 PM
  3. How to exclude certain shipping options if certain weight
    By dman76 in forum Built-in Shipping and Payment Modules
    Replies: 2
    Last Post: 18 May 2008, 12:15 PM
  4. Free Shipping Options Module
    By WaltBoyd in forum Built-in Shipping and Payment Modules
    Replies: 1
    Last Post: 2 Dec 2007, 09:09 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