If this is your first visit, check our documentation. To post, register or login.
Forums / Built-in Shipping and Payment Modules / Different shipping methods for different categories

Different shipping methods for different categories

Started by tylerd213 on 13 Mar 2008, 2:16 AM · Views: 107,885

Results 481 to 500 of 554
16 Jun 2012, 6:45 PM
#481
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Different shipping methods for different categories

First, you use the products_id that you need for the stickers ... I gave examples for 2 products_id 115 and 168 ...

If you only need one, then comment out one line and change the numbers for the products_id to your product_id number(s):

$chk_products += $_SESSION['cart']->in_cart_check('products_id','115');
// $chk_products += $_SESSION['cart']->in_cart_check('products_id','168');

Next, you are not adding the code correctly ...

You see how the code I posted has some BLACK lines, above and below the RED lines?

This means on your code, you should replace what is between those BLACK lines with the code in RED ... you keep adding the new code in and leaving the old code in there ...

Look at my code and look at your code and you will see that they are not the same ...

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!

17 Jun 2012, 9:36 AM
#482
dw08gm avatar

dw08gm

Totally Zenned

Join Date:
Sep 2008
Location:
DownUnder, overlooking South Pole.
Posts:
1,022
Plugin Contributions:
2

Re: Different shipping methods for different categories

I want all of my different shipping arrangements, as developed from this thread, to be written to a single separate file, that acts between the shopping cart and any shipping modules, and is generally not affected by shipping mod upgrades (so long as mod name does not change).

Does such a file already exist?

If not, I gather some kind of require statement is also needed to call and close the single file.

So what to do?

17 Jun 2012, 1:28 PM
#483
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Different shipping methods for different categories

If you replace the whole section of code that starts with:

  function quote($method = '') {
    // BOF: UPS USPS

and ends with:

  /**
   * check status of module
   *
   * @return boolean
   */

with this new code:

  function quote($method = '') {
    // BOF: UPS USPS
    global $order, $shipping_weight, $shipping_num_boxes, $transittime;

    if ( zen_not_null($method) && (isset($this->types[$method]) || in_array($method, $this->intl_types)) ) {
      $this->_setService($method);
    }


    // usps doesnt accept zero weight send 1 ounce (0.0625) minimum
    $usps_shipping_weight = ($shipping_weight <= 0.0 ? 0.0625 : $shipping_weight);
    $shipping_pounds = floor ($usps_shipping_weight);
    $shipping_ounces = (16 * ($usps_shipping_weight - floor($usps_shipping_weight)));
    // usps currently cannot handle more than 5 digits on international
    // change to 2 if International rates fail based on Tare Settings
    $shipping_ounces = zen_round($shipping_ounces, MODULE_SHIPPING_USPS_DECIMALS);

    // weight must be less than 35lbs and greater than 6 ounces or it is not machinable
    switch(true) {
      case ($shipping_pounds == 0 and $shipping_ounces < 6):
      // override admin choice too light
      $is_machinable = 'False';
      break;

      case ($usps_shipping_weight > 35):
      // override admin choice too heavy
      $is_machinable = 'False';
      break;

      default:
      // admin choice on what to use
      $is_machinable = MODULE_SHIPPING_USPS_MACHINABLE;
    }

    $this->_setMachinable($is_machinable);
    $this->_setContainer('None');
    $this->_setSize('REGULAR');
    $this->_setFirstClassType('FLAT');

    $this->_setWeight($shipping_pounds, $shipping_ounces);
    $uspsQuote = $this->_getQuote();

    if (is_array($uspsQuote)) {
      if (isset($uspsQuote['error'])) {
        $this->quotes = array('module' => $this->title,
                              'error' => $uspsQuote['error']);
      } else {

        // BOF: UPS USPS
        if (in_array('Display weight', explode(', ', MODULE_SHIPPING_USPS_OPTIONS))) {
          switch (SHIPPING_BOX_WEIGHT_DISPLAY) {
            case (0):
            $show_box_weight = '';
            break;
            case (1):
            $show_box_weight = ' (' . $shipping_num_boxes . ' ' . TEXT_SHIPPING_BOXES . ')';
            break;
            case (2):
            $show_box_weight = ' (' . number_format($usps_shipping_weight * $shipping_num_boxes,2) . TEXT_SHIPPING_WEIGHT . ')';
            break;
            default:
            $show_box_weight = ' (' . $shipping_num_boxes . ' x ' . number_format($usps_shipping_weight,2) . TEXT_SHIPPING_WEIGHT . ')';
            break;
          }
        }
        // EOF: UPS USPS

        // BOF: UPS USPS
        $this->quotes = array('id' => $this->code,
        'module' => $this->title . $show_box_weight);
        // EOF: UPS USPS

        // set handling fee
        if ($order->delivery['country']['id'] == SHIPPING_ORIGIN_COUNTRY  || (SHIPPING_ORIGIN_COUNTRY == '223' && $this->usps_countries == 'US')) {
          // national
          $usps_handling_fee = MODULE_SHIPPING_USPS_HANDLING;
        } else {
          // international
          $usps_handling_fee = MODULE_SHIPPING_USPS_HANDLING_INT;
        }

        $methods = array();
        $size = sizeof($uspsQuote);
        for ($i=0; $i<$size; $i++) {
          list($type, $cost) = each($uspsQuote[$i]);

          // BOF: UPS USPS
          $title = ((isset($this->types[$type])) ? $this->types[$type] : $type);
          if(in_array('Display transit time', explode(', ', MODULE_SHIPPING_USPS_OPTIONS)))    $title .= $transittime[$type];
          // strip the ** from the titles
          $title = str_replace('**', '', $title);
          $cost = preg_replace('/[^0-9.]/', '',  $cost);

// bof: skip products when not the only ones in cart
$cart_count = $_SESSION['cart']->count_contents();
$chk_products = 0;
$chk_products += $_SESSION['cart']->in_cart_check('products_id','182');
// $chk_products += $_SESSION['cart']->in_cart_check('products_id','168');
//echo '<br>Type: ' . $type . ' Title: ' . $title . ' cost: ' . $cost . ' cart count ' . $cart_count . 'exclude: ' . $chk_products . '<br>';
if ( ( ($chk_products > 0 && $cart_count == $chk_products) && ($type != 'First-Class Mail International Letter**' && $type != 'FIRST CLASS')) || (($chk_products > 0 && $cart_count != $chk_products) && ($type == 'First-Class Mail International Letter**' || $type == 'FIRST CLASS')) || (($chk_products == 0) && ($type == 'First-Class Mail International Letter**' || $type == 'FIRST CLASS')) ) {
// skip it
//echo 'I skipped: ' . $type . '<br>';
} else {
//echo 'I did NOT skipped: ' . $type . '<br>';
          $methods[] = array('id' => $type,
                             'title' => $title,
                             'cost' => ($cost * $shipping_num_boxes) + (MODULE_SHIPPING_USPS_HANDLING_METHOD == 'Box' ? $usps_handling_fee * $shipping_num_boxes : $usps_handling_fee) );
}
// eof: skip products when not the only ones in cart

          // bof: sort by contributed by Marco B
          // Sort the options
          if (MODULE_SHIPPING_USPS_QUOTE_SORT != 'Unsorted') {
            usort($methods,'usps_sort_'.MODULE_SHIPPING_USPS_QUOTE_SORT);
          }
          // eof: sort by contributed by Marco B
        }

        $this->quotes['methods'] = $methods;

        if ($this->tax_class > 0) {
          $this->quotes['tax'] = zen_get_tax_rate($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);
        }
      }
    } elseif ($uspsQuote == -1) {
      $this->quotes = array('module' => $this->title,
                            'error' => MODULE_SHIPPING_USPS_TEXT_SERVER_ERROR . (MODULE_SHIPPING_USPS_SERVER=='test' ? MODULE_SHIPPING_USPS_TEXT_TEST_MODE_NOTICE : ''));
    } else {
      $this->quotes = array('module' => $this->title,
                            'error' => MODULE_SHIPPING_USPS_TEXT_ERROR . (MODULE_SHIPPING_USPS_SERVER=='test' ? MODULE_SHIPPING_USPS_TEXT_TEST_MODE_NOTICE : ''));
    }

    if (zen_not_null($this->icon)) $this->quotes['icon'] = zen_image($this->icon, $this->title);

    return $this->quotes;
  }
  /**
   * check status of module
   *
   * @return boolean
   */

Does this work correctly?

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!

18 Jun 2012, 4:33 AM
#484
prolite avatar

prolite

New Zenner

Join Date:
Apr 2012
Posts:
28
Plugin Contributions:
0

Re: Different shipping methods for different categories

Thank you Ajeh. Everything works correctly, except for the $1.95 for US first class mail still showing $1.95 for stickers only. A letter weighing 1 ounce: (0.0625) with only stickers in it, should only cost 45 cents or less. When I went to https://www.usps.com to do a "calculate price" check, the actual price was 45 cents. The information I put in was the following: US addresses only (From zip: 11510 To zip: 90210) and choose "Letter" at the bottom, and the list of blue options on the next screen showed the cheapest method: "First-Class Mail® Letter" at the price of: 45 cents. But on my shopping cart it still shows $1.95 for stickers only at the weight of (0.0625). Are the USPS production servers creating this error?

18 Jun 2012, 12:59 PM
#485
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Different shipping methods for different categories

Find this line in the file:
/includes/modules/shipping/usps.php

    $this->_setFirstClassType('FLAT');

Change it to read:

//    $this->_setFirstClassType('FLAT');
   $this->_setFirstClassType('LETTER');

Does this get the cheaper rate?

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!

18 Jun 2012, 4:42 PM
#486
prolite avatar

prolite

New Zenner

Join Date:
Apr 2012
Posts:
28
Plugin Contributions:
0

Re: Different shipping methods for different categories

Ajeh:

Find this line in the file:
/includes/modules/shipping/usps.php

$this->_setFirstClassType('FLAT');
> 
> Change it to read:
> ```
//    $this->_setFirstClassType('FLAT');
   $this->_setFirstClassType('LETTER');

Does this get the cheaper rate?

Yes, that fixed it. Thank you. Do you accept donations?

18 Jun 2012, 4:58 PM
#487
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Different shipping methods for different categories

Glad to hear that this is working for you ...

The Zen Cart Team donations can be made from:
http://www.zen-cart.com/content.php?6-donate

Thanks for the support! :smile:

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!

18 Jun 2012, 6:33 PM
#488
prolite avatar

prolite

New Zenner

Join Date:
Apr 2012
Posts:
28
Plugin Contributions:
0

Re: Different shipping methods for different categories

Ajeh:

Glad to hear that this is working for you ...

The Zen Cart Team donations can be made from:
http://www.zen-cart.com/content.php?6-donate

Thanks for the support! :smile:

Can I pay you separately for you time? I don't want to pay the whole team. I will pay you since only you helped.

Dan,

19 Jun 2012, 11:45 PM
#489
painted_hills_nb avatar

painted_hills_nb

New Zenner

Join Date:
Apr 2012
Location:
Fossil, OR
Posts:
35
Plugin Contributions:
0

Re: Different shipping methods for different categories

I assumed that when I need to add additional product_ids for 2-Day Air only I could just duplicate the code and add the new id number in both the /includes/modules/shipping/perweightunit.php and UPS...not so???

Ajeh:

To turn off the Per Unit perweightunit when products_id is in the cart, customize the code in:
/includes/modules/shipping/perweightunit.php

with the code:

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

// bof: turn off if products_id 87 is in the cart
if (!IS_ADMIN_FLAG) {
$chk_product = 0;
$chk_product += $_SESSION['cart']->in_cart_check('products_id','87');
if ($chk_product > 0) {
$this->enabled = false;
}
}
// eof: turn off if products_id 87 is in the cart

> 
> You can customize UPS with this code in RED:
> ```
        $cost = preg_replace('/[^0-9.]/', '',  $cost);
// bof: turn off if products_id 87 is in the cart
echo 'UPS TYPE: ' . $type . ' Title: ' . $this->types[$type] . '<br>';
  $chk_product = 0;
  $chk_product += $_SESSION['cart']->in_cart_check('products_id','87');
  if ($chk_product > 0) {
    if ($type == '2DA') {
        $methods[] = array('id' => $type,
                           'title' => $this->types[$type],
                           'cost' => ($cost * $shipping_num_boxes) + (MODULE_SHIPPING_UPS_HANDLING_METHOD == 'Box' ? MODULE_SHIPPING_UPS_HANDLING * $shipping_num_boxes : MODULE_SHIPPING_UPS_HANDLING) );
    } else {
      // skip shipping
    }
  } else {
        $methods[] = array('id' => $type,
                           'title' => $this->types[$type],
                           'cost' => ($cost * $shipping_num_boxes) + (MODULE_SHIPPING_UPS_HANDLING_METHOD == 'Box' ? MODULE_SHIPPING_UPS_HANDLING * $shipping_num_boxes : MODULE_SHIPPING_UPS_HANDLING) );
  }
// eof: turn off if products_id 87 is in the cart

      }
      $this->quotes['methods'] = $methods;

to replace the code:

    $methods[] = array('id' => $type,
                       'title' => $this->types[$type],
                       'cost' => ($cost * $shipping_num_boxes) +  (MODULE_SHIPPING_UPS_HANDLING_METHOD == 'Box' ?  MODULE_SHIPPING_UPS_HANDLING * $shipping_num_boxes :  MODULE_SHIPPING_UPS_HANDLING) );
> 
> NOTE: the echo line for:
> ```
echo 'UPS TYPE: ' . $type . ' Title: ' . $this->types[$type] . '<br>';

can be commented out with:

// echo 'UPS TYPE: ' . $type . ' Title: ' . $this->types[$type] . '<br>';

> 
> after you are done testing and sure of the $type that you want to use in this code ...

Christine
"I believe the most important single thing, beyond discipline and creativity is daring to dare." ~Maya Angelou

20 Jun 2012, 3:03 AM
#490
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Different shipping methods for different categories

You should just be able to have multiple lines of:

  $chk_product += $_SESSION['cart']->in_cart_check('products_id','87'); 
  $chk_product += $_SESSION['cart']->in_cart_check('products_id','XX'); 

where XX is the next products_id you need ...

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!

29 Jun 2012, 2:31 AM
#491
robin339 avatar

robin339

New Zenner

Join Date:
May 2007
Posts:
33
Plugin Contributions:
0

Re: Different shipping methods for different categories

Hi,
I know this is a REALLY old thread. But this is exactly what I need, only difference is that for me some categories MUST be shipped via USPS, and the Rest MUST be Shipped via UPS (I am using multiple drop-shippers, few of them ship ONLY UPS and the res USPS). I am New to Zen cart and finally starting to piece everything together :)

Thanks a million in advance,
Robin

25 Aug 2012, 4:42 AM
#492
robax avatar

robax

Zen Follower

Join Date:
Mar 2006
Posts:
187
Plugin Contributions:
0

Re: Different shipping methods for different categories

Hi all,

I've read through this thread and searched it a few times, but I need some pointers for how to implement the per-category idea to the free shipping module - Note that I'm not a PHP programmer.

I have Free Shipping Option and Free Shipping modules running on ZC 139h

I have free shipping above $300.-

I want to disable free shipping on items in a given category.

I understand I can use this code with the appropriate category Id's to disable a shipping option.

// disable for one master_categories_id
if ((IS_ADMIN_FLAG == false && $_SESSION['cart']->in_cart_check('master_categories_id','4') > 0)) {
$this->enabled = false;
}

What I want to know is if that is correct and where exactly to put it. I have tried it in various places in freeoptions.php and in freeshipper.php but without any luck.

I'm testing by inserting the category ID where the target product resides, and then going through to the shipping estimator, hoping to see the free shipping option vanish, but nope!

Any help with this is very much appreciated.
Rob

26 Aug 2012, 2:04 PM
#493
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Different shipping methods for different categories

Free Options freeoptions is based on either the Total, Weight or Item count or a combination of the 3 ... and runs at the same time as other shipping modules ...

In this module, you can add that code below:

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

FREE SHIPPING! freeshipper is based on orders of 0 amount or marked as Always Free Shipping ... and runs INSTEAD of other shipping modules ... so this code is not a good choice for this shipping module as no other shipping module would be running and if you turn it off, then there would be no shipping modules at all ...

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!

30 Aug 2012, 4:44 AM
#494
robax avatar

robax

Zen Follower

Join Date:
Mar 2006
Posts:
187
Plugin Contributions:
0

Re: Different shipping methods for different categories

Ajeh:

Free Options freeoptions is based on either the Total, Weight or Item count or a combination of the 3 ... and runs at the same time as other shipping modules ...

In this module, you can add that code below:

  // disable only when entire cart is free shipping
  if (zen_get_shipping_enabled($this->code)) {
      $this->enabled = ((MODULE_SHIPPING_FREEOPTIONS_STATUS == 'True') ? true : false);
  }
> 
> FREE SHIPPING! freeshipper is based on orders of 0 amount or marked as Always Free Shipping ... and runs INSTEAD of other shipping modules ... so this code is not a good choice for this shipping module as no other shipping module would be running and if you turn it off, then there would be no shipping modules at all ...

Fantastic, thanks Ajeh!

I was able to use that info plus some previous posts in the thread to get it to check multiple categories as follows:

  // disable for one master_categories_id
  if (IS_ADMIN_FLAG == false) {
  // check master_categories_id add one line per master_categories_id
  $chk_cat = 0;
  $chk_cat += $_SESSION['cart']->in_cart_check('master_categories_id','165');
  $chk_cat += $_SESSION['cart']->in_cart_check('master_categories_id','166');
  if ($chk_cat >= 1) {
  $this->enabled = false;
  }
  }

And that works!

Thanks again, much appreciated :wub:
Rob
30 Aug 2012, 1:52 PM
#495
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Different shipping methods for different categories

Thanks for the update that you have you site working now on this ... :smile:

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!

16 Sep 2012, 3:55 PM
#496
divavocals avatar

divavocals

Totally Zenned

Join Date:
Jan 2007
Location:
Los Angeles, California, United States
Posts:
10,011
Plugin Contributions:
3

Re: Different shipping methods for different categories

Read through this thread (yep ALL 50 pages as of this writing..:smile:)

Wanted to do a sanity check BEFORE I test and implement this.. Does my code for these two different scenarios look correct (restriction based on model number or category ID) Client has yet to decide whether he wants to use model number or category ID, so I will be demoing both options for him..

Disable based on multiple categories

    //Disable based on multiple categories
     // disable only when entire cart is free shipping
      if (zen_get_shipping_enabled($this->code)) {
          $this->enabled = ((MODULE_SHIPPING_FREEOPTIONS_STATUS == 'True') ? true : false);
      }
      // test contents for Cases
       global $cart;
        $skip_free = false;
        $chk_case = 0;
        if (IS_ADMIN_FLAG == false) {
          $chk_case += $_SESSION['cart']->in_cart_check('master_categories_id','56');
          $chk_case += $_SESSION['cart']->in_cart_check('master_categories_id','60');
          if ($chk_case > 0  && ($chk_case != $_SESSION['cart']->count_contents())) {
            $skip_free = true;
          }
        }
//echo 'FLAT : ' . $chk_case . '<br>';
      // disable for above categories
      if ((IS_ADMIN_FLAG == false && $skip_free)) {
          $this->enabled = false;
      }

      if ( ($this->enabled == true) && ((int)MODULE_SHIPPING_FREEOPTIONS_ZONE > 0) ) {

Disable based on multiple model numbers

    //Disable based on multiple model numbers
     // disable only when entire cart is free shipping
      if (zen_get_shipping_enabled($this->code)) {
          $this->enabled = ((MODULE_SHIPPING_FREEOPTIONS_STATUS == 'True') ? true : false);
      }
      // test contents for Cases
       global $cart;
        $skip_free = false;
        $chk_case = 0;
        if (IS_ADMIN_FLAG == false) {
          $chk_case += $_SESSION['cart']->in_cart_check('products_model','MH-78523');
          $chk_case += $_SESSION['cart']->in_cart_check('products_model','MH-65489');
          if ($chk_case > 0  && ($chk_case != $_SESSION['cart']->count_contents())) {
            $skip_free = true;
          }
        }
//echo 'FLAT : ' . $chk_case . '<br>';
      // disable for above model numbers
      if ((IS_ADMIN_FLAG == false && $skip_free)) {
          $this->enabled = false;
      }

      if ( ($this->enabled == true) && ((int)MODULE_SHIPPING_FREEOPTIONS_ZONE > 0) ) {

One last thing.. how would I modify this to restrict things based on a specific product ID.. Is it just a matter of doing something like this???:

          $chk_case += $_SESSION['cart']->in_cart_check('products_id','23');
          $chk_case += $_SESSION['cart']->in_cart_check('products_id','89');

My Site - Zen Cart & WordPress integration specialist
I don't answer support questions via PM. Post add-on support questions in the support thread. The question & the answer will benefit others with similar issues.

27 Sep 2012, 7:44 AM
#497
defanci avatar

defanci

New Zenner

Join Date:
Dec 2009
Posts:
42
Plugin Contributions:
0

Re: Different shipping methods for different categories

Hi, I have read through all the posts and have been testing for few days but still can't a solution. Could someone please help me with my code?

I have 3 Zone Rate, singpost, pos_malaysia and singpost_plus_posmalaysia

  1. singpost - enable for all categories except cat #20
 // bof: disable for these master_categories_id 
    if (IS_ADMIN_FLAG == false) {
      // check master_categories_id add one line per master_categories_id
      $chk_cat = 0;
      $chk_cat += $_SESSION['cart']->in_cart_check('master_categories_id','20');
       if ($chk_cat > 0) {
        $this->enabled = false;
      }
    }
    // eof: disable for these master_categories_id
  1. pos_malaysia - enable when cart only have cat #20
 // bof: disable for these master_categories_id
    if (IS_ADMIN_FLAG == false) {
      // check master_categories_id add one line per master_categories_id
      $chk_cat = 0;
      $chk_cat += $_SESSION['cart']->in_cart_check('master_categories_id','2');
      $chk_cat += $_SESSION['cart']->in_cart_check('master_categories_id','3');
      $chk_cat += $_SESSION['cart']->in_cart_check('master_categories_id','4');
	   $chk_cat += $_SESSION['cart']->in_cart_check('master_categories_id','6');
      $chk_cat += $_SESSION['cart']->in_cart_check('master_categories_id','8');
      $chk_cat += $_SESSION['cart']->in_cart_check('master_categories_id','13');
	   $chk_cat += $_SESSION['cart']->in_cart_check('master_categories_id','14');
      $chk_cat += $_SESSION['cart']->in_cart_check('master_categories_id','15');
      $chk_cat += $_SESSION['cart']->in_cart_check('master_categories_id','16');
	   $chk_cat += $_SESSION['cart']->in_cart_check('master_categories_id','17');
      $chk_cat += $_SESSION['cart']->in_cart_check('master_categories_id','18');
	  	             if ($chk_cat > 0) {
        $this->enabled = false;
      }
    }
    // eof: disable for these master_categories_id	
  1. singpost_plus_posmalaysia - mixed cart enable only when cart have cat #20 plus any other cat
// bof: enable for mixed cart where cat #20 must be present plus any other cat
	global $db, $cart;
    if (IS_ADMIN_FLAG == false) {
      // check master_categories_id add one line per master_categories_id
      $chk_cat = 0;
      $chk_cat += $_SESSION['cart']->in_cart_check('master_categories_id','2');
      $chk_cat += $_SESSION['cart']->in_cart_check('master_categories_id','3');
      $chk_cat += $_SESSION['cart']->in_cart_check('master_categories_id','4');
	   $chk_cat += $_SESSION['cart']->in_cart_check('master_categories_id','6');
      $chk_cat += $_SESSION['cart']->in_cart_check('master_categories_id','8');
      $chk_cat += $_SESSION['cart']->in_cart_check('master_categories_id','13');
	   $chk_cat += $_SESSION['cart']->in_cart_check('master_categories_id','14');
      $chk_cat += $_SESSION['cart']->in_cart_check('master_categories_id','15');
      $chk_cat += $_SESSION['cart']->in_cart_check('master_categories_id','16');
	   $chk_cat += $_SESSION['cart']->in_cart_check('master_categories_id','17');
      $chk_cat += $_SESSION['cart']->in_cart_check('master_categories_id','18');
	 	  	      if ((IS_ADMIN_FLAG == false && $_SESSION['cart']->in_cart_check('master_categories_id','20') > 0)&&(IS_ADMIN_FLAG == false && $_SESSION['cart']->in_cart_check($chk_cat ) > 0)) {
	    $this->enabled = true;
					  } else{
						  $this->enabled = false;
					  }
 	} 

singpost_plus_posmalaysia is working fine if cat #20 plus 1 other cat with quantity of 1 but it will not working when
cat #20 plus more than 2 other cat or cat #20 plus one other cat with quantity of more than 1 . Problem solved if I remove ```php
else{
$this->enabled = false;
}


but singpost_plus_posmalaysia will appear in all other categories which not suppose to. I am going crazy, any help will be very much appreciated.
27 Sep 2012, 1:29 PM
#498
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Different shipping methods for different categories

For the test for:
2. pos_malaysia - enable when cart only have cat #20

use the test for is the categories_id 20 the only thing in the cart:

      $chk_cat = 0;
      $chk_cat += $_SESSION['cart']->in_cart_check('master_categories_id','20');
      if ($chk_cat > 0  && $chk_cat != $_SESSION['cart']->count_contents()) {
        $this->enabled = false;
      }

For the test for:
3. singpost_plus_posmalaysia - mixed cart enable only when cart have cat #20 plus any other cat

use the test for is this a mixed cart with categories_id 20 in the cart:

      $chk_cat = 0;
      $chk_cat += $_SESSION['cart']->in_cart_check('master_categories_id','20');
      if ($chk_cat > 0  && $chk_cat == $_SESSION['cart']->count_contents()) {
         $this_enabled = 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!]
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!

27 Sep 2012, 3:11 PM
#499
divavocals avatar

divavocals

Totally Zenned

Join Date:
Jan 2007
Location:
Los Angeles, California, United States
Posts:
10,011
Plugin Contributions:
3

Re: Different shipping methods for different categories

Hey Linda.. Can you give me a sanity check here por favor???? :smile: Am I on the right track here if I use this code???

DivaVocals:

Read through this thread (yep ALL 50 pages as of this writing..:smile:)

Wanted to do a sanity check BEFORE I test and implement this.. Does my code for these two different scenarios look correct (restriction based on model number or category ID) Client has yet to decide whether he wants to use model number or category ID, so I will be demoing both options for him..

Disable based on multiple categories

//Disable based on multiple categories
 // disable only when entire cart is free shipping
  if (zen_get_shipping_enabled($this->code)) {
      $this->enabled = ((MODULE_SHIPPING_FREEOPTIONS_STATUS == 'True') ? true : false);
  }
  // test contents for Cases
   global $cart;
    $skip_free = false;
    $chk_case = 0;
    if (IS_ADMIN_FLAG == false) {
      $chk_case += $_SESSION['cart']->in_cart_check('master_categories_id','56');
      $chk_case += $_SESSION['cart']->in_cart_check('master_categories_id','60');
      if ($chk_case > 0  && ($chk_case != $_SESSION['cart']->count_contents())) {
        $skip_free = true;
      }
    }

//echo 'FLAT : ' . $chk_case . '<br>';
// disable for above categories
if ((IS_ADMIN_FLAG == false && $skip_free)) {
$this->enabled = false;
}

  if ( ($this->enabled == true) && ((int)MODULE_SHIPPING_FREEOPTIONS_ZONE > 0) ) {
> 
> Disable based on multiple model numbers
> ```
    //Disable based on multiple model numbers
     // disable only when entire cart is free shipping
      if (zen_get_shipping_enabled($this->code)) {
          $this->enabled = ((MODULE_SHIPPING_FREEOPTIONS_STATUS == 'True') ? true : false);
      }
      // test contents for Cases
       global $cart;
        $skip_free = false;
        $chk_case = 0;
        if (IS_ADMIN_FLAG == false) {
          $chk_case += $_SESSION['cart']->in_cart_check('products_model','MH-78523');
          $chk_case += $_SESSION['cart']->in_cart_check('products_model','MH-65489');
          if ($chk_case > 0  && ($chk_case != $_SESSION['cart']->count_contents())) {
            $skip_free = true;
          }
        }
//echo 'FLAT : ' . $chk_case . '<br>';
      // disable for above model numbers
      if ((IS_ADMIN_FLAG == false && $skip_free)) {
          $this->enabled = false;
      }

      if ( ($this->enabled == true) && ((int)MODULE_SHIPPING_FREEOPTIONS_ZONE > 0) ) {

One last thing.. how would I modify this to restrict things based on a specific product ID.. Is it just a matter of doing something like this???:

      $chk_case += $_SESSION['cart']->in_cart_check('products_id','23');
      $chk_case += $_SESSION['cart']->in_cart_check('products_id','89');

My Site - Zen Cart & WordPress integration specialist
I don't answer support questions via PM. Post add-on support questions in the support thread. The question & the answer will benefit others with similar issues.

28 Sep 2012, 1:52 AM
#500
defanci avatar

defanci

New Zenner

Join Date:
Dec 2009
Posts:
42
Plugin Contributions:
0

Re: Different shipping methods for different categories

Ajeh:

For the test for:
2. pos_malaysia - enable when cart only have cat #20

use the test for is the categories_id 20 the only thing in the cart:

  $chk_cat = 0;
  $chk_cat += $_SESSION['cart']->in_cart_check('master_categories_id','20');
  if ($chk_cat > 0  && $chk_cat != $_SESSION['cart']->count_contents()) {
    $this->enabled = false;
  }
> 
> For the test for:
> 3. singpost_plus_posmalaysia - mixed cart enable only when cart have cat #20 plus any other cat
> 
> use the test for is this a mixed cart with categories_id 20 in the cart:
> ```
      $chk_cat = 0;
      $chk_cat += $_SESSION['cart']->in_cart_check('master_categories_id','20');
      if ($chk_cat > 0  && $chk_cat == $_SESSION['cart']->count_contents()) {
         $this_enabled = false;
      }

Thank you Linda, I have change to your code and now mixed cart is working fine but when cart with only #20, it show both pos_malaysia and singpost_plus_posmalaysia, it should only show pos_malaysia. And also when cart is without #20, it should only singpost, but right now is show all three.