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,884

Results 141 to 160 of 554
20 Oct 2009, 1:13 PM
#141
ajeh avatar

ajeh

Oba-san

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

Different shipping methods for different categories

You could test the cart for how many products are in a given master_categories_id and if there is 1 or more from the aerosols category then it raises the rate being charged in the Flat Rate flat shipping module ...

In the shopping_cart class is this function:

  /**
   * 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') {

it can be used to test how many products are in the master_categories_id for this category using:
$_SESSION['cart']->in_cart_check('master_categories_id','27')

where 27 is the master_categories_id for the aerosols ...

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!

20 Oct 2009, 1:27 PM
#142
spid3r1987 avatar

spid3r1987

Zen Follower

Join Date:
Jul 2009
Posts:
497
Plugin Contributions:
0

Re: Different shipping methods for different categories

ok stupid question from me, how do i find my master category for "aerosols"
manufacturer ambersil

i may not know how yet, but i soon will....i hope :)

20 Oct 2009, 1:43 PM
#143
spid3r1987 avatar

spid3r1987

Zen Follower

Join Date:
Jul 2009
Posts:
497
Plugin Contributions:
0

Re: Different shipping methods for different categories

ok so im a bit lost, well alot...

where do i enter that code, and how does it affect the flat.php shipping rate??

im a total noob to this...sorry

i may not know how yet, but i soon will....i hope :)

22 Oct 2009, 5:19 PM
#144
lindasdd avatar

lindasdd

Zen Follower

Join Date:
Jun 2007
Posts:
474
Plugin Contributions:
0

Re: Different shipping methods for different categories

I have been playing around with this code attempting to turn off free shipping for certain categories, but so far have had no luck. I think because free shpping seems to flow in from multiple places.

Any advice on how to accomplish this? Or am I being an idiot and just need to find hte right file.

The other problem is that when I add the code the admin section gets screwy. No errors, but the right secion of the shipping admin where there are buttons and options dissapears.

-lindasdd

22 Oct 2009, 11:00 PM
#145
ajeh avatar

ajeh

Oba-san

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

Re: Different shipping methods for different categories

Okay ... let's first break down what you are trying to do ...

It sounds like you want a Flat Rate flat shipping module to run for the rate of 6.95 ... unless there is 1 or more Products from the aerosols category ... then the Flat Rate flat shipping module should be, for the whole order, set to 15.00 ...

Now the trick is to test the shopping cart for 1 or more Products from the aerosols category ...

Let's assume the aerosols category is categories_id 27 ... if that is the case, when you edit a Product from there, it should list the Master Category ...
Product Master Category:

this will either tell you the ID and Name of the Category or there will be a dropdown list, if this is a Linked Product ...

The "Master Category" is the "Main Category" of a Product, as in the Category that "owns" the Product and is used for other things like Sales, setting the products_price_sorter, etc. etc. where a Master Category has to be known ...

To control the Flat Rate flat shipping module for the amount to charge, we need to test if 1 or more Products are in the aerosols category, which we are using as categories_id 27 ... which would be set in the products table for the master_categories_id 27 ...

To use this to change the Cost of the Flat Rate flat shipping module, you need to test and adjust the rate based on the results ...

Editing the file:
/includes/modules/shipping/flat.php

There is a section of code that generates the quote or the cost:

// class methods
    function quote($method = '') {
      global $order;

      $this->quotes = array('id' => $this->code,
                            'module' => MODULE_SHIPPING_FLAT_TEXT_TITLE,
                            'methods' => array(array('id' => $this->code,
                                                     'title' => MODULE_SHIPPING_FLAT_TEXT_WAY,
                                                     'cost' => MODULE_SHIPPING_FLAT_COST)));
      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;
    }

This needs to be changed ...

// class methods
    function quote($method = '') {
      global $order;

// check for number of aerosols in cart and change rate if 1 or more are in the cart
  global $cart;
  $cnt_aerosols = $_SESSION['cart']->in_cart_check('master_categories_id','27');
  if ($cnt_aerosols > 0) {
    $flat_aerosols = 15.00;
  } else {
    $flat_aerosols = 0.00;
  }
      $this->quotes = array('id' => $this->code,
                            'module' => MODULE_SHIPPING_FLAT_TEXT_TITLE,
                            'methods' => array(array('id' => $this->code,
                                                     'title' => MODULE_SHIPPING_FLAT_TEXT_WAY,
                                                     'cost' => ($flat_aerosols > 0 ? $flat_aerosols : MODULE_SHIPPING_FLAT_COST))));
      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;
    }

Now when products from categories_id 27, based on master_categories_id 27 in the products table are in the cart the rate will be 15.00 rather than what is set in the Flat Rate flat shipping module ...

Easy Smeazy, eh? :cool:

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!

23 Oct 2009, 2:15 AM
#146
lindasdd avatar

lindasdd

Zen Follower

Join Date:
Jun 2007
Posts:
474
Plugin Contributions:
0

Re: Different shipping methods for different categories

lindasdd:

I have been playing around with this code attempting to turn off free shipping for certain categories, but so far have had no luck. I think because free shpping seems to flow in from multiple places.

Any advice on how to accomplish this? Or am I being an idiot and just need to find hte right file.

The other problem is that when I add the code the admin section gets screwy. No errors, but the right secion of the shipping admin where there are buttons and options dissapears.

-lindasdd

Just in case someone stumbles upon this later, I wanted to include my solution for my problem.

  1. Go to Admin>Modules>Order Total . Click on ot_shipping. Turn off the " allow free shipping" otherwise this overwrites everything else
  2. Install the Free Options Shipping module and configure
  3. Open the includes/modules/shipping/freeoptions.php file and adjust using Ajeh's code:

right below this:

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

add this:

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

But of course change the category id.

Now if only I could get my Admin>Modules>Shipping screen to look normal.

23 Oct 2009, 3:36 AM
#147
ajeh avatar

ajeh

Oba-san

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

Re: Different shipping methods for different categories

What does not look normal on the Admin for the Modules ... Shipping ... :unsure:

Check that you do not have a bak file in there or extra shipping modules copies as that is a self loading directory and it will load files that it should not ... :lookaroun

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!

24 Oct 2009, 12:52 AM
#148
lindasdd avatar

lindasdd

Zen Follower

Join Date:
Jun 2007
Posts:
474
Plugin Contributions:
0

Re: Different shipping methods for different categories

Ajeh:

What does not look normal on the Admin for the Modules ... Shipping ... :unsure:

Well before the change the Module>Shipping screen had all the shipping methods ont he left and then the options for the highlighted shipping method on the right.

Now the "options" portion on the right is no longer existent.

No bak files and the shipping works, it is just that the Admin is screwy now.

Also I'm using 1.3.7
-lindasdd

24 Oct 2009, 2:20 AM
#149
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 do not have the right screen then there is either an error in one of the shipping modules or there is an extra file in the:
/includes/modules/shipping directory that does not belong or there is a language file in the directory that should be fixed with the proper code file ...

Check the files on the server in:
/includes/modules/shipping

and make sure that they are all the code files and that none are duplicates of one another ...

If you have any new/customized files there could be an error in it that the Admin is detecting that the shop is not ...

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!

24 Oct 2009, 2:56 AM
#150
lindasdd avatar

lindasdd

Zen Follower

Join Date:
Jun 2007
Posts:
474
Plugin Contributions:
0

Re: Different shipping methods for different categories

Awesome!

I had renamed my old shipping file as freeoptions1 instead of freeoptions. I do this when making changes so that I can easily switch back if need be. Normally it doesn't create issues, but I guess in this case it was.

Thanks for all your help.

lindasdd

24 Oct 2009, 3:28 AM
#151
ajeh avatar

ajeh

Oba-san

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

Re: Different shipping methods for different categories

To avoid issues ... I use the naming convention of:
freeoptions.php_1
freeoptions.php_ORI
etc. etc.

That way it is not picked up as a php file ... :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!

28 Oct 2009, 4:44 AM
#152
brismods avatar

brismods

New Zenner

Join Date:
Sep 2009
Posts:
4
Plugin Contributions:
0

Re: Different shipping methods for different categories

Guys, I'm hoping you're able to help us out with this one. We're trying to do something similar to those at the start of the thread. I've tried several different codes etc. and haven't had any luck.

Bascially we want to make it so that any large items can only be shipped by the 'large item shipping' shipping module we got. So basically items in catagory 18 are all large items, so they are included, but items from catagory 23 are also large, so they need to be added to the code also some how.

In an ideal world, it would work so that if i add a large item to the cart, it would only have the large item shipping option and then if i added a smaller item, it would still only have the large item shipping option and of course, as soon as you remove the large item from the cart, it shows all the normal shipping options (excluding the large item shipping) for the small item

I have taken a few stabs at this myself and failed horribly. If anyone knows what we need to do, it would be really appreciated :smile:

29 Oct 2009, 2:25 AM
#153
lindasdd avatar

lindasdd

Zen Follower

Join Date:
Jun 2007
Posts:
474
Plugin Contributions:
0

Re: Different shipping methods for different categories

Since this is growing into the master thread for crazy shipping changes based on category I thought I would add one more solution I have found. IT is a bit of a hack, but maybe will inspire you if you can't find your own.

Problem: I need to charge a flat rate, only once if a product in a certain category(frozen foods) is chosen. Then I also need to charge the standard calculated rates(Fedex or USPS.)

Solution: (This can be done by any attribute, one of them being category, but in my case it is by model.)

  1. For each product in the category make the model 'frozen'(I don't use category ID for reasons not described here)
  2. Open /includes/modules/order_total/ot_loworderfee.php
    3)Change this:
if ( ($pass == true) && ( ($order->info['total'] - $order->info['shipping_cost']) < MODULE_ORDER_TOTAL_LOWORDERFEE_ORDER_UNDER) ) {
        if ( ($pass == true) && ( $order->info['subtotal'] < MODULE_ORDER_TOTAL_LOWORDERFEE_ORDER_UNDER) ) {
          $charge_it = 'true';

To this:

if ( ($pass == true) && ( ($order->info['total'] - $order->info['shipping_cost']) < MODULE_ORDER_TOTAL_LOWORDERFEE_ORDER_UNDER) ) {
        if ( ($pass == true) && ($_SESSION['cart']->in_cart_check('products_model','frozen') > 0) ) {
          $charge_it = 'true';

4)Change your settings in the ADmin screen so the low order fee is activated at very low levels(less than $1).

Huh? Why?: Instead of adding a fee based on cost, it is adding a fee if certain conditions exist. In this case it is based on if the 'products_model' is 'frozen'. If you want to do it based on categories just change it to: ```
in_cart_check('master_categories_id','66') > 0) )


where 66 is the category id


-lindasdd

P.S. Thanks again Ajeh. This is all based on modifications to your posts. After reading almost every shipping post that comes up from searching I am amazed at your patience in responding again and again.
30 Oct 2009, 5:48 PM
#154
yoppo avatar

yoppo

New Zenner

Join Date:
Aug 2009
Posts:
40
Plugin Contributions:
0

Re: Different shipping methods for different categories

All I seem to do is ask questions! :blush:

I need table rate shipping for products ID 15 and 16

Thanks :smile:

31 Oct 2009, 2:36 AM
#155
lindasdd avatar

lindasdd

Zen Follower

Join Date:
Jun 2007
Posts:
474
Plugin Contributions:
0

Re: Different shipping methods for different categories

Brismods:

Guys, I'm hoping you're able to help us out with this one. We're trying to do something similar to those at the start of the thread. I've tried several different codes etc. and haven't had any luck..........

:smile:

The only way I can think to do this is to make it so all other shipping options turn off when a product from one of those categories is in the cart. If someone knows an easy way of doing this without changing ever single shipping file maybe they can chime in.

Would you be able to at least do what I just described or did you try and it didn't work?

-lindasdd

1 Nov 2009, 7:09 PM
#156
agentx avatar

agentx

New Zenner

Join Date:
Nov 2007
Location:
Virginia
Posts:
57
Plugin Contributions:
0

Re: Different shipping methods for different categories

I am having a similar problem. It seems someone out there may have a solution but I'm new to PhP and may be missing it. Here goes.

In simple terms I want to code products and product categories so that only certain shipping options appear for each.

For example.

I have a group of products that drop ship directly to the customer but they are from different sources. One will only use UPS. The other will use ups and USPS.

I would like the shipping options on the items that will only go UP to only show UPS (and calculate) while the others give the choice between UPS and USPS.

Can that be done easily tor does someone have a better solution for coding shipping for products based on source and varying dropship fees.

1 Nov 2009, 7:29 PM
#157
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 could test the cart and if there is a product that only goes UPS then disable the USPS shipping module ...

To check for how many of a specific products_id is in the cart, such as products_id 15, you can use:

global $cart;
$chk_products15 = $_SESSION['cart']->in_cart_check('products_id','15');

You can then control the $this->enabled based on the results ...

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!

1 Nov 2009, 8:31 PM
#158
agentx avatar

agentx

New Zenner

Join Date:
Nov 2007
Location:
Virginia
Posts:
57
Plugin Contributions:
0

Re: Different shipping methods for different categories

I tried that but I must be doing soemthing worng i guess.

If I have both the UPS and USPS shipping modules on then they appear as options for ALL the items in my store. I cannot find a way to have some items just USPS and some both USPS and UPS.

There is nothing in the product or category area that lets me disable the shipping modules by category or product.

1 Nov 2009, 9:16 PM
#159
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 have to edit the file:
/includes/modules/shipping/ups.php

and change the code ...

Let's say you do not want to allow UPS when products_id 15 is in the cart, change the code:

    $this->types = array('1DM' => 'Next Day Air Early AM',

to read:

global $cart;
if (IS_ADMIN_FLAG == false && $_SESSION['cart']->in_cart_check('products_id','15') > 0) {
  $this->enabled = false;
}
    $this->types = array('1DM' => 'Next Day Air Early 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!]
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 Nov 2009, 2:21 AM
#160
brismods avatar

brismods

New Zenner

Join Date:
Sep 2009
Posts:
4
Plugin Contributions:
0

Re: Different shipping methods for different categories

lindasdd:

The only way I can think to do this is to make it so all other shipping options turn off when a product from one of those categories is in the cart. If someone knows an easy way of doing this without changing ever single shipping file maybe they can chime in.

Would you be able to at least do what I just described or did you try and it didn't work?

-lindasdd

I'm not exactly the greatest when it comes to this sort of stuff. We previously had tried a few of the other solutions posted in the thread. For example there was one where we posted the code into the file, but it needed to be duplicated for the different categories, however when more than one copy of the code was in the file, the codes would seemingly clash and not work at all.