Zen Cart Logo
Forums / Built-in Shipping and Payment Modules / Limit shipping choices for one catagory

Limit shipping choices for one catagory

Locked

Views: 2,750

Results 1 to 18 of 18
This thread is locked. New replies are disabled.
9 Jul 2009, 12:55 AM
#1
jimmythebarrel avatar

jimmythebarrel

New Zenner

Join Date:
May 2009
Posts:
16
Plugin Contributions:
0

Limit shipping choices for one catagory

Hi, i ship livestock I sell on my site. I need a way to set my UPS shipping so if ANY items from the livestock catagory get added to the cart, ONLY the overnight shipping option is available.

Also, i need to add a one time box charge if any livestock is ordered. This is for insulated box and cold or heat packs.

If drygoods are ordered, they should be able to see all UPS shipping options. No worries about box charge then.

The livestock has their own unique product ID.

I have looked at the forums, and I just get confused.

9 Jul 2009, 4:05 AM
#2
jimmythebarrel avatar

jimmythebarrel

New Zenner

Join Date:
May 2009
Posts:
16
Plugin Contributions:
0

Re: Limit shipping choices for one catagory

After looking around on the forums some more, I guess what I need is a code string for my UPS module.

Basically, if catagory 65 livestock are in the cart, then 2 Day and ground shipping are disabled in the UPS module. Or if anything with a model number begining with LS-IQ-HC is in the cart, same thing.

Then, can I add a way to offer shipping additions only IF something from cat 65 is in the cart? I offer a shipping upgrade so when I ship livestock, I pack them in a special moss so they stay moist and cooler. But its not needed if only drygoods are ordered. Although if i offer it across the board it wont bother me. They wanna pay and extra fee for some moss around drygoods, more power to them.

This is my site for reference. Its the hermit crabs I need ONLY next day on. http://www.hermitcrabvendor.com/

9 Jul 2009, 9:22 PM
#3
jimmythebarrel avatar

jimmythebarrel

New Zenner

Join Date:
May 2009
Posts:
16
Plugin Contributions:
0

Re: Limit shipping choices for one catagory

I think i have the add the moss thing resolved. Looks like I could redo the Gift Wrap Module do that. Still need the help on catagory shipping.

Anyone?

11 Jul 2009, 8:35 PM
#4
ajeh avatar

ajeh

Oba-san

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

Re: Limit shipping choices for one catagory

You could test the shopping cart content based on master_categories_id using a function in the shopping_cart class:

  /**
   * Method to calculate the number of items in a cart based on an abitrary property
   *
   * $check_what is the fieldname example: 'products_is_free'
   * $check_value is the value being tested for - default is 1
   * Syntax: $_SESSION['cart']->in_cart_check('product_is_free','1');
   *
   * @param string product field to check
   * @param mixed value to check for
   * @return integer number of items matching restraint
   */
  function in_cart_check($check_what, $check_value='1') {

You can then also test if all of the products in the shopping cart are from this category by comparing to the total number of items in the cart ...

Then, to control the quote in the UPS shipping module you can base what shows on the $type to enable and disable the methods ...

12 Jul 2009, 10:47 PM
#5
jimmythebarrel avatar

jimmythebarrel

New Zenner

Join Date:
May 2009
Posts:
16
Plugin Contributions:
0

Re: Limit shipping choices for one catagory

I understand like none of that. This is frustrating.

What PHP file do I alter?

What is the shopping_cart class?

13 Jul 2009, 3:44 AM
#6
ajeh avatar

ajeh

Oba-san

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

Re: Limit shipping choices for one catagory

You would be altering the shipping module for UPS:
/includes/modules/shipping/ups.php

You need to know how many products are in the order are from categories_id 65 ...

The master_categories_id in the products table will contain the value 65 for this categories_id if it is the master_categories_id or if you do not use Linked Products and this is the only Category that the crabs are in ...

If you want to turn off various shipping methods of the ups.php shipping module you need to know:

1 are there 1 or more products from this category ...

2 are all of the products in the cart from this category ...

The quote is built with this section of the code:

          $methods[] = array('id' => $type,
                             'title' => $this->types[$type],
                             'cost' => ($cost + MODULE_SHIPPING_UPS_HANDLING) * $shipping_num_boxes);

The $type is the method of ups about to be quoted ...

$type will be:
2DA for 2nd day
GND for ground

You can get the count of what's in the cart with:

        // EOF: UPS USPS
        global $cart;
        $how_many_items = $_SESSION['cart']->count_contents();
        $how_many_crabs = $_SESSION['cart']->in_cart_check('master_categories_id','65');;
echo 'I am type: ' . $type . ' how many items: ' . $how_many_items . ' how many are crabs: ' . $how_many_crabs . '<br>';
        $methods[] = array('id' => $type,
                           'title' => $this->types[$type],
                           'cost' => ($cost + MODULE_SHIPPING_UPS_HANDLING) * $shipping_num_boxes);

The echo just displays some text when the module is run so you can see the counts based on what is in the cart and how many total items are there and how many are crabs ...

You can use the two values to determine if all the items in the cart are crabs or if there are any crabs in the cart ...

Now, you can use the $type to control when to build the shipping method and when to skip it ...

14 Jul 2009, 9:31 PM
#7
jimmythebarrel avatar

jimmythebarrel

New Zenner

Join Date:
May 2009
Posts:
16
Plugin Contributions:
0

Re: Limit shipping choices for one catagory

Awesome. Thank you so much. Soon as I get some money generating, a cup of coffee is coming your way.

15 Jul 2009, 12:47 AM
#8
jimmythebarrel avatar

jimmythebarrel

New Zenner

Join Date:
May 2009
Posts:
16
Plugin Contributions:
0

Re: Limit shipping choices for one catagory

So do I need to define the allowable shipping methods? or the disallowed?

Is this an add a code string? Or alter one existing?

I would just add like 1DA after which instance of $type? Both? Or the one in []'s?

I added the second code string you gave me. I get the text saying how many items are in the cart, and how many crabs are in the cart at the top of my shipping module box, but it still allows the shipping I don't want. I shows that I have crabs in the cart, and yes, only category 65 has crabs.

Not to be ungrateful, your answers are surely what I need. And I thank you for answering I just don't exactly know what to do with them. I feel like a dumbass since trying to solve this one.

15 Jul 2009, 2:31 PM
#9
ajeh avatar

ajeh

Oba-san

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

Re: Limit shipping choices for one catagory

If is up to you which way you code it ...

Once you know if you have crabs ... :blink: ... you want to then check the $type ...

If you allow the code:

          $methods[] = array('id' => $type,
                             'title' => $this->types[$type],
                             'cost' => ($cost + MODULE_SHIPPING_UPS_HANDLING) * $shipping_num_boxes);

to build based on which $type you are on, then it will display ...

I am not sure what you have done thus far based on the code that I gave you ...

15 Jul 2009, 6:26 PM
#10
jimmythebarrel avatar

jimmythebarrel

New Zenner

Join Date:
May 2009
Posts:
16
Plugin Contributions:
0

Re: Limit shipping choices for one catagory

I cut and pasted the second code string you gave me. Unaltered. About midway through the module.

I didn't know where to add the shipping method type.

15 Jul 2009, 8:27 PM
#11
ajeh avatar

ajeh

Oba-san

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

Re: Limit shipping choices for one catagory

This is the whole FOR loop ...

Note: you can make this code more efficient based on where in the code the tests are done, but for now, see if this helps you:

      for ($i=0; $i<$qsize; $i++) {
        list($type, $cost) = each($upsQuote[$i]);
        // BOF: UPS USPS
        if ($type=='STD') {
          if ($std_rcd) continue;
          else $std_rcd = true;
        }
        if (!in_array($type, $allowed_methods)) continue;
        // EOF: UPS USPS
        global $cart;
        $how_many_items = $_SESSION['cart']->count_contents();
        $how_many_crabs = $_SESSION['cart']->in_cart_check('master_categories_id','65');
        $hide_2da_gnd = false;
// for another test where total items are all crabs
//        if (($how_many_crabs == $how_many_items)) {
// for another test where total items are all crabs and $type is 2DA or GND
//        if (($how_many_crabs == $how_many_items) && ($type == '2DA' || $type == 'GND')) {
        if (($type == '2DA' || $type == 'GND')) {
          $hide_2da_gnd = true;
        }

echo '<br>I am type: ' . $type . ' how many items: ' . $how_many_items . ' how many are crabs: ' . $how_many_crabs . '<br>';
if ($hide_2da_gnd == true) {
  // do nothing
  echo 'hidding: ' . $type . '<br>';
} else {
  echo 'showing: ' . $type . '<br>';
        // EOF: UPS USPS
        $methods[] = array('id' => $type,
                           'title' => $this->types[$type],
                           'cost' => ($cost + MODULE_SHIPPING_UPS_HANDLING) * $shipping_num_boxes);
}
      }

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

The echos will tell you which method type is being checked and how many items are in the cart vs how many are crabs ...

I left in some commented IFs on other ways to combine the results for other things ...

See if this helps you sort things out ...

15 Jul 2009, 10:38 PM
#12
jimmythebarrel avatar

jimmythebarrel

New Zenner

Join Date:
May 2009
Posts:
16
Plugin Contributions:
0

Re: Limit shipping choices for one catagory

Well, I managed to break my shipping module. Now I cant get it to work again. I put a backup in to replace the broken module. Now I get this on my admin page.

Parse error: syntax error, unexpected T_GLOBAL, expecting ')' in /home/iqw/hermitcrabvendor.com/includes/modules/shipping/ups.php on line 168

      $methods = array();
      // BOF: UPS USPS
      $allowed_methods = explode(", ", MODULE_SHIPPING_UPS_TYPES);
      $std_rcd = false;
      // EOF: UPS USPS
      $qsize = sizeof($upsQuote);
      for ($i=0; $i<$qsize; $i++) {
        list($type, $cost) = each($upsQuote[$i]);
        // BOF: UPS USPS
        if ($type=='STD') {
          if ($std_rcd) continue;
          else $std_rcd = true;
        }
        if (!in_array($type, $allowed_methods)) continue;
        // EOF: UPS USPS
        $methods[] = array('id' => $type,
                           'title' => $this->types[$type],
                           'cost' => ($cost + MODULE_SHIPPING_UPS_HANDLING) * $shipping_num_boxes);
      }

That is the code. Line 168 is string $std_rcd = false;.

16 Jul 2009, 4:33 AM
#13
jimmythebarrel avatar

jimmythebarrel

New Zenner

Join Date:
May 2009
Posts:
16
Plugin Contributions:
0

Re: Limit shipping choices for one catagory

Ok, managed to fix that issue. I just uploaded the full backup I had. So, WHEW.

Now, where do I put the code string in the UPS module? Do I replace code? Or just add?

16 Jul 2009, 5:29 AM
#14
ajeh avatar

ajeh

Oba-san

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

Re: Limit shipping choices for one catagory

Okay let's try again ...

You already have the code in the ups.php file that starts with the first line of this new code and ends with the last line of this new code ...

This code replaces all of that ...

I will give you the code again, starting a little higher so maybe you see the section of code to replace better:

      $methods = array();
      // BOF: UPS USPS
      $allowed_methods = explode(", ", MODULE_SHIPPING_UPS_TYPES);
      $std_rcd = false;
      // EOF: UPS USPS
      $qsize = sizeof($upsQuote);
      for ($i=0; $i<$qsize; $i++) {
        list($type, $cost) = each($upsQuote[$i]);
        // BOF: UPS USPS
        if ($type=='STD') {
          if ($std_rcd) continue;
          else $std_rcd = true;
        }
        if (!in_array($type, $allowed_methods)) continue;
        // EOF: UPS USPS
        global $cart;
        $how_many_items = $_SESSION['cart']->count_contents();
        $how_many_crabs = $_SESSION['cart']->in_cart_check('master_categories_id','65');
        $hide_2da_gnd = false;
// for another test where total items are all crabs
//        if (($how_many_crabs == $how_many_items)) {
// for another test where total items are all crabs and $type is 2DA or GND
//        if (($how_many_crabs == $how_many_items) && ($type == '2DA' || $type == 'GND')) {
        if (($type == '2DA' || $type == 'GND')) {
          $hide_2da_gnd = true;
        }

echo '<br>I am type: ' . $type . ' how many items: ' . $how_many_items . ' how many are crabs: ' . $how_many_crabs . '<br>';
if ($hide_2da_gnd == true) {
  // do nothing
  echo 'hidding: ' . $type . '<br>';
} else {
  echo 'showing: ' . $type . '<br>';
        // EOF: UPS USPS
        $methods[] = array('id' => $type,
                           'title' => $this->types[$type],
                           'cost' => ($cost + MODULE_SHIPPING_UPS_HANDLING) * $shipping_num_boxes);
}
      }

      $this->quotes['methods'] = $methods;
16 Jul 2009, 6:07 AM
#15
jimmythebarrel avatar

jimmythebarrel

New Zenner

Join Date:
May 2009
Posts:
16
Plugin Contributions:
0

Re: Limit shipping choices for one catagory

Ok, now it hides everything but next day air, no matter whats in the cart.

Shipping popup shows this. No livestock in cart.

I am type: 1DA how many items: 10 how many are crabs: 0
showing: 1DA

I am type: 2DA how many items: 10 how many are crabs: 0
hidding: 2DA

I am type: GND how many items: 10 how many are crabs: 0
hidding: GND

This shows if livestock IS in the cart.

I am type: 1DA how many items: 11 how many are crabs: 1
showing: 1DA

I am type: 2DA how many items: 11 how many are crabs: 1
hidding: 2DA

I am type: GND how many items: 11 how many are crabs: 1
hidding: GND

Sure its a small thing, just don't know what. No matter whats on the cart, it hides 2DA and GND.

SO CLOSE.

Just to clarify, i replaced this code string with the code you gave me.

      $methods = array();
      // BOF: UPS USPS
      $allowed_methods = explode(", ", MODULE_SHIPPING_UPS_TYPES);
      $std_rcd = false;
      // EOF: UPS USPS
      $qsize = sizeof($upsQuote);
      for ($i=0; $i<$qsize; $i++) {
        list($type, $cost) = each($upsQuote[$i]);
        // BOF: UPS USPS
        if ($type=='STD') {
          if ($std_rcd) continue;
          else $std_rcd = true;
        }
        if (!in_array($type, $allowed_methods)) continue;
        // EOF: UPS USPS
        $methods[] = array('id' => $type,
                           'title' => $this->types[$type],
                           'cost' => ($cost + MODULE_SHIPPING_UPS_HANDLING) * $shipping_num_boxes);
      }

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

And thank you again for the help. You rock.

16 Jul 2009, 2:32 PM
#16
ajeh avatar

ajeh

Oba-san

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

Re: Limit shipping choices for one catagory

I gave you 3 IF conditions ...

Test them to see how they work, then combine them to work the way you need this to run ...

For example, if you change this:

//        if (($how_many_crabs == $how_many_items) && ($type == '2DA' || $type == 'GND')) {
        if (($type == '2DA' || $type == 'GND')) {

to read:

        if (($how_many_crabs == $how_many_items) && ($type == '2DA' || $type == 'GND')) {
//        if (($type == '2DA' || $type == 'GND')) {

Now if all the items in the cart are crabs, it will behave differently ...

19 Jul 2009, 8:11 AM
#17
jimmythebarrel avatar

jimmythebarrel

New Zenner

Join Date:
May 2009
Posts:
16
Plugin Contributions:
0

Re: Limit shipping choices for one catagory

Getting closer. It will show only Next Day air if only Crabs are in the cart. But if product is in the cart, it still shows 2DA and GND. I need it where if a crba is in the cart even with other product, !DA is only option.

$methods = array();
      // BOF: UPS USPS
      $allowed_methods = explode(", ", MODULE_SHIPPING_UPS_TYPES);
      $std_rcd = false;
      // EOF: UPS USPS
      $qsize = sizeof($upsQuote);
      for ($i=0; $i<$qsize; $i++) {
        list($type, $cost) = each($upsQuote[$i]);
        // BOF: UPS USPS
        if ($type=='STD') {
          if ($std_rcd) continue;
          else $std_rcd = true;
        }
        if (!in_array($type, $allowed_methods)) continue;
        // EOF: UPS USPS
        global $cart;
        $how_many_items = $_SESSION['cart']->count_contents();
        $how_many_crabs = $_SESSION['cart']->in_cart_check('master_categories_id','65');
        $hide_2da_gnd = false;
// for another test where total items are all crabs
//        if (($how_many_crabs == $how_many_items)) {
// for another test where total items are all crabs and $type is 2DA or GND
       if (($how_many_crabs == $how_many_items) && ($type == '2DA' || $type == 'GND')) {
//        if (($type == '2DA' || $type == 'GND')) {
         $hide_2da_gnd = true;
        }

echo '<br>I am type: ' . $type . ' how many items: ' . $how_many_items . ' how many are crabs: ' . $how_many_crabs . '<br>';
if ($hide_2da_gnd == true) {
  // do nothing
  echo 'hidding: ' . $type . '<br>';
} else {
  echo 'showing: ' . $type . '<br>';
        // EOF: UPS USPS
        $methods[] = array('id' => $type,
                           'title' => $this->types[$type],
                           'cost' => ($cost + MODULE_SHIPPING_UPS_HANDLING) * $shipping_num_boxes);

Any last tips on where to put the //'s and such?

19 Jul 2009, 2:35 PM
#18
ajeh avatar

ajeh

Oba-san

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

Re: Limit shipping choices for one catagory

What happens if under your current IF of:

       if (($how_many_crabs == $how_many_items) && ($type == '2DA' || $type == 'GND')) {
//        if (($type == '2DA' || $type == 'GND')) {
         $hide_2da_gnd = true;
        }

You add another IF for:

       if (($how_many_crabs > 0) && ($type == '2DA' || $type == 'GND')) {
//        if (($type == '2DA' || $type == 'GND')) {
         $hide_2da_gnd = true;
        }

NOTE: depending on what you need with the shipping methods ... you may only need the 2nd IF to handle everything ...