Forums / Built-in Shipping and Payment Modules / Flat rate for 1 category, Per Item for all others

Flat rate for 1 category, Per Item for all others

Started by znak on 12 Oct 2009, 5:00 AM · Views: 3,591

Results 1 to 20 of 20
12 Oct 2009, 5:00 AM
#1
znak avatar

znak

New Zenner

Join Date:
Oct 2009
Posts:
6
Plugin Contributions:
0

Flat rate for 1 category, Per Item for all others

Hi,
I'm having trouble setting up a shipping rule I require.

I have 1 category (Seed) which will always have a flat rate of $1.50 shipping regardless of quantity ordered and other categories that I want to use per item shipping.

Is it possible to set up ZenCart to use the flat rate for all category 1 purchases as well as the shipping per item for anything purchased from another category?

An example could be:
A customer purchases 6 packets of seed and, let's say a dehydrator and some clips which have different shipping costs ($10 and $2) and come from category 2.

Total shipping should be $13.50. Can this be done?

Also, can the shipping be left blank awaiting a total shipping quote as many of the items I sell require individual shipping quotations.

12 Oct 2009, 2:07 PM
#2
ajeh avatar

ajeh

Oba-san

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

Re: Flat rate for 1 category, Per Item for all others

Let's assume that the categories_id is 10 ... and that it is the master_categories_id for all of the Seeds ...

You can edit the shipping module:
/includes/modules/shipping/item.php

and change the function quote by replacing it with:

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

      // adjusted count for free shipping
      $item_total_count = $total_count - $_SESSION['cart']->free_shipping_items();

      // check number of seeds ordered from categories_id 10
      $chk_seeds = $_SESSION['cart']->in_cart_check('master_categories_id','10');
      $item_total_count = $item_total_count - $chk_seeds;
      if ($chk_seeds > 0) {
        $chk_seeds_shipping = 1.50;
      } else {
        $chk_seeds_shipping = 0.00;
      }
      $this->quotes = array('id' => $this->code,
                            'module' => MODULE_SHIPPING_ITEM_TEXT_TITLE,
                            'methods' => array(array('id' => $this->code,
                                                     'title' => MODULE_SHIPPING_ITEM_TEXT_WAY,
                                                     'cost' => (MODULE_SHIPPING_ITEM_COST * $item_total_count) + $chk_seeds_shipping + MODULE_SHIPPING_ITEM_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;
    }

Now all Products using the master_categories_id 10 will be removed from the count that Item Rate item shipping uses and charge $1.50 if any are in the cart ... :smile:

Just change the '10' to the master_categories_id for the Seeds ...

See if that works for you ...

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!

13 Oct 2009, 3:32 AM
#3
znak avatar

znak

New Zenner

Join Date:
Oct 2009
Posts:
6
Plugin Contributions:
0

Re: Flat rate for 1 category, Per Item for all others

Thanks for your reply. It doesn't seem to be working correctly.
I ran a test purchase of 5 packets of seed ($1.50 flat rate postage) and 1 Preserver ($20 postage). The two options for postage presented to me were:

Please select the preferred shipping method to use on this order.
Flat Rate $1.50Best Way
Per Unit $45.75Best Way

The postage should have calculated to $21.50, any ideas?

13 Oct 2009, 3:50 AM
#4
ajeh avatar

ajeh

Oba-san

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

Re: Flat rate for 1 category, Per Item for all others

The code posted was to work with the Item Rate item shipping module based on the "per item" referrance in your first post ...

Now, however, you are showing Flat Rate and Per Unit perunitweight shipping modules ...

Flat Rate is a single charge for the whole order ...

Per Unit is based on the full weight of the order ...

What shipping module do you want to use this code with? :unsure:

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!

13 Oct 2009, 4:03 AM
#5
znak avatar

znak

New Zenner

Join Date:
Oct 2009
Posts:
6
Plugin Contributions:
0

Re: Flat rate for 1 category, Per Item for all others

Sorry for the confusion. I want to use per unit perunitweight method for most categories (I understand this is the way to have individual shipping cost per item) but I want to add $1.50 to the total order shipping cost if any items are purchased from category 1. In other words I want shipping calculated by adding all the individual shipping costs for non category 1 purchases and then add $1.50 if any number of Category 1 items are purchased. You may have guessed; I am new to ZenCart. :blush:

13 Oct 2009, 4:21 AM
#6
ajeh avatar

ajeh

Oba-san

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

Re: Flat rate for 1 category, Per Item for all others

See if this works for you on the Per Unit perweightunit shipping module:

  function quote($method = '') {
    global $order, $shipping_weight;

    global $total_count;
    // check number of seeds ordered from categories_id 10
    $chk_seeds = $_SESSION['cart']->in_cart_check('master_categories_id','10');
    if ($chk_seeds > 0) {
      $chk_seeds_shipping = 1.50;
    } else {
      $chk_seeds_shipping = 0.00;
    }

    $total_weight_units = $shipping_weight;
    $this->quotes = array('id' => $this->code,
                          'module' => MODULE_SHIPPING_PERWEIGHTUNIT_TEXT_TITLE,
                          'methods' => array(array('id' => $this->code,
                                                   'title' => MODULE_SHIPPING_PERWEIGHTUNIT_TEXT_WAY,
                                                   'cost' => (MODULE_SHIPPING_PERWEIGHTUNIT_COST * $total_weight_units) + $chk_seeds_shipping
                                                              + MODULE_SHIPPING_PERWEIGHTUNIT_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;
  }

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!

13 Oct 2009, 5:37 AM
#7
znak avatar

znak

New Zenner

Join Date:
Oct 2009
Posts:
6
Plugin Contributions:
0

Re: Flat rate for 1 category, Per Item for all others

Looks like I've messed things up pretty well now. I can't get any of the postage to work properly. I reverted to the original item.php and tried to set up per unit (perunitweight) shipping. Set the weight of the products to 1.5 and thought I'd be okay. Nope, now I have no idea how it is calculating postage. 1 pack of seeds returns a shipping cost of $0. I'm losing the plot. I thought ZenCart would be relatively easy to set up but no. I just want to put my products in, assign a postage cost and build in the smarts for the Category 1 items. Thanks for your help, looks like back to ebay for me as I can't afford the time to learn how to drive this thing.

13 Oct 2009, 6:37 AM
#8
znak avatar

znak

New Zenner

Join Date:
Oct 2009
Posts:
6
Plugin Contributions:
0

Re: Flat rate for 1 category, Per Item for all others

I've had another go at it and have the following results.

Cart contains 3 x seed = $1.50 postage total
1 x preserver $20.00 postage

Total postage should be $21.50

Calculated postage is $26.00

Is it possible it is adding the $20 + (3x$1.50) + $1.50 - perhaps the maths logic is wrong - I'm not quite sure how to read it.

Any assistance would be appreciated.

13 Oct 2009, 8:09 AM
#9
znak avatar

znak

New Zenner

Join Date:
Oct 2009
Posts:
6
Plugin Contributions:
0

Re: Flat rate for 1 category, Per Item for all others

Managed to figure out the problem. I need to use 0 weight for the seed to have it calculate correctly.

13 Oct 2009, 6:16 PM
#10
ajeh avatar

ajeh

Oba-san

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

Re: Flat rate for 1 category, Per Item for all others

Thanks for the update that you had the weight added for the seeds and needed to remove that ... glad to hear that this does work for you ... :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!

12 Jun 2011, 4:09 PM
#11
nasdaqpro avatar

nasdaqpro

New Zenner

Join Date:
Jun 2011
Posts:
3
Plugin Contributions:
0

Re: Flat rate for 1 category, Per Item for all others

Ajeh:

Let's assume that the categories_id is 10 ... and that it is the master_categories_id for all of the Seeds ...

You can edit the shipping module:
/includes/modules/shipping/item.php

and change the function quote by replacing it with:

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

  // adjusted count for free shipping
  $item_total_count = $total_count - $_SESSION['cart']->free_shipping_items();

  // check number of seeds ordered from categories_id 10
  $chk_seeds = $_SESSION['cart']->in_cart_check('master_categories_id','10');
  $item_total_count = $item_total_count - $chk_seeds;
  if ($chk_seeds > 0) {
    $chk_seeds_shipping = 1.50;
  } else {
    $chk_seeds_shipping = 0.00;
  }
  $this->quotes = array('id' => $this->code,
                        'module' => MODULE_SHIPPING_ITEM_TEXT_TITLE,
                        'methods' => array(array('id' => $this->code,
                                                 'title' => MODULE_SHIPPING_ITEM_TEXT_WAY,
                                                 'cost' => (MODULE_SHIPPING_ITEM_COST * $item_total_count) + $chk_seeds_shipping + MODULE_SHIPPING_ITEM_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;
}
> 
> Now all Products using the master_categories_id 10 will be removed from the count that Item Rate item shipping uses and charge $1.50 if any are in the cart ... :smile:
> 
> Just change the '10' to the master_categories_id for the Seeds ...
> 
> See if that works for you ...

This code worked great for me for checking 1 category.  However, I need to know how to alter the code to have it check 2 or more categories.  I also would like a similar code to add per item shipping charge using the zone rates.  I would really appreciate any help.  Thanks so much!
12 Jun 2011, 4:16 PM
#12
nasdaqpro avatar

nasdaqpro

New Zenner

Join Date:
Jun 2011
Posts:
3
Plugin Contributions:
0

Re: Flat rate for 1 category, Per Item for all others

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

  // adjusted count for free shipping
  $item_total_count = $total_count - $_SESSION['cart']->free_shipping_items();

  // check number of seeds ordered from categories_id 10
  $chk_seeds = $_SESSION['cart']->in_cart_check('master_categories_id','10');
  $item_total_count = $item_total_count - $chk_seeds;
  if ($chk_seeds > 0) {
    $chk_seeds_shipping = 1.50;
  } else {
    $chk_seeds_shipping = 0.00;
  }
  $this->quotes = array('id' => $this->code,
                        'module' => MODULE_SHIPPING_ITEM_TEXT_TITLE,
                        'methods' => array(array('id' => $this->code,
                                                 'title' => MODULE_SHIPPING_ITEM_TEXT_WAY,
                                                 'cost' => (MODULE_SHIPPING_ITEM_COST * $item_total_count) + $chk_seeds_shipping + MODULE_SHIPPING_ITEM_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;
}

Ajeh,

This code worked great for me for checking one category. However, I need to modify it to check 2 or more categories. In other words, I have three categories that have a special shipping charge. If any one of the categories has a product in the cart, I need to add the fee 1 time. I would also like to add the code to the zone rate option. Any help would be greatly appreciated. Thanks so much!

12 Jun 2011, 4:19 PM
#13
ajeh avatar

ajeh

Oba-san

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

Re: Flat rate for 1 category, Per Item for all others

You could use something like this to check various master_categories_id for Products ...

$chk_cat_cnt = 0;
$chk_cat_cnt += $_SESSION['cart']->in_cart_check('master_categories_id','15');
$chk_cat_cnt += $_SESSION['cart']->in_cart_check('master_categories_id','16');
$chk_cat_cnt += $_SESSION['cart']->in_cart_check('master_categories_id','27');

Now the $chk_cat_cnt holds the number of Products for 3 different master_categories_id values ...

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!

12 Jun 2011, 4:39 PM
#14
nasdaqpro avatar

nasdaqpro

New Zenner

Join Date:
Jun 2011
Posts:
3
Plugin Contributions:
0

Re: Flat rate for 1 category, Per Item for all others

That worked Great! Thanks so much!

Can I add this somewhere in the Zone rate as well? Please advise on where to add for the zone rate.

Thanks again.

12 Jun 2011, 5:21 PM
#15
ajeh avatar

ajeh

Oba-san

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

Re: Flat rate for 1 category, Per Item for all others

Look for where the cost is setup and the quote is built ...

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 Aug 2011, 1:52 AM
#16
captaincarlton avatar

captaincarlton

New Zenner

Join Date:
May 2011
Posts:
20
Plugin Contributions:
0

Re: Flat rate for 1 category, Per Item for all others

Hi Ajeh and others,
This topic is very relevant for me as well, but I am doing something wrong. I notice that there are no conditions in the code, that is, the code supplied effectively replaces the default perweightunit code with the code from Ajeh. So, in doing so, the flat rate works for my "seeds" equivalent category, but now the perweightunit is not calculating for the other categories (totals $0.00).

In addition, up checkout, I am getting option boxes to select the shipping method - Flat Rate $5.00 or Per Unit $0.00. How come these shipping costs are not cumulative for me).

Hope you can help.

Many thanks for your time !!

adam

17 Aug 2011, 2:33 AM
#17
ajeh avatar

ajeh

Oba-san

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

Re: Flat rate for 1 category, Per Item for all others

If your Per Unit Rate is 0.00 ... then the shipping will always be $0.00 ...

Can you type really slow, and tell us exactly what it is you are trying to do with your shipping?

Pretend we know nothing about your site ... :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!

18 Aug 2011, 4:41 AM
#18
captaincarlton avatar

captaincarlton

New Zenner

Join Date:
May 2011
Posts:
20
Plugin Contributions:
0

Re: Flat rate for 1 category, Per Item for all others

Linda and others, OK, I'll try again.

In my categories sidebox, I have several top level categories, with subcats and then products within those. Looking at the first top level category path I see:

 http://www.blabla...com.au/index.php?main_page=index&cPath=1 

and the sub-cats are

http://www.blabla...com.au/index.php?main_page=index&cPath=1_10
http://www.blabla...com.au/index.php?main_page=index&cPath=1_11
```, and so on...

Similar to the other requests in this thread, I want to have a single shipping fee for two categories.  These two categories are (cPath=1 (above), and cPath=5), and contain small products which I want to set a fee of $9.99, regardless of how many are ordered.

Other categories (eg. cPath=3) have larger products, and for these I want to set a shipping fee per unit, say $20.00.  EG, I have set the weight of the product I am testing this code with to be 20kg.

I would like shipping calculated by adding all the non cat1 and non cat5 purchases and then adding $9.99 if any number of Cat1 and/or Cat5 products are ordered.

As per your advice and just looking at Cat1 for the moment, I modified the Per Unit perweightunit shipping module code. All is the same except the master_categories reference, that is:

```php
function quote($method = '') {
    global $order, $shipping_weight;

    global $total_count;
    // check number of seeds ordered from categories_id 1
    $chk_seeds = $_SESSION['cart']->in_cart_check('master_categories_id','1');
    if ($chk_seeds > 0) {
      $chk_seeds_shipping = 9.99;
    } else {
      $chk_seeds_shipping = 0.00;
    }

Here are the results:

1 x Cat3 product = $20.00 postal. OK.
1 x Cat1 product and 1 x Cat3 product. Total is still $20, expecting $29.99.

If I just add 1 x Cat1 to the cart, calculated (Per Unit) postage is $0.00, expecting $5.

My configs:

  • I have used 0 weight for the Cat 1 products.
  • Installed Shipping Modules: Per Unit perweightunit only.

Actually, I just modified this line to test $chk_seeds_shipping:

'cost' => (MODULE_SHIPPING_PERWEIGHTUNIT_COST * $total_weight_units) + $chk_seeds_shipping

to read

'cost' => (MODULE_SHIPPING_PERWEIGHTUNIT_COST * $total_weight_units) + 9.99

and the calculated postage for a cart containing Cat1 and Cat3 works, so it's something to do with the code to detect items in ('master_categories_id','1'), hence $chk_seeds_shipping must be carrying 0 value for some reason

Hope you can help (sure you can)

adam

18 Aug 2011, 1:23 PM
#19
captaincarlton avatar

captaincarlton

New Zenner

Join Date:
May 2011
Posts:
20
Plugin Contributions:
0

Re: Flat rate for 1 category, Per Item for all others

OK, after viewing http://www.zen-cart.com/forum/showthread.php?t=172745&page=2 I have worked this through. What I thought were sub cat id's (cPath=1_10) were actually Product Master Category ID (eg, 10). On that thread there was discussion around building some sort of function to capture all of these subcats under the top-level cat. But for now, I am happy listing all of my sub-cats. I will end up having around 15 of these listed in the code below, will that be an issue ?

So now the shipping fee processing is accurate across a number of categories by using

    function quote($method = '') {
    global $order, $shipping_weight;

    global $total_count;

    $chk_cat_cnt = 0;
	$chk_cat_cnt += $_SESSION['cart']->in_cart_check('master_categories_id','10');
	$chk_cat_cnt += $_SESSION['cart']->in_cart_check('master_categories_id','8');
		
    if ($chk_cat_cnt > 0) {
      $chk_catcnt_shipping = 5.95;
    } else {
      $chk_catcnt_shipping = 0.00;
    }
18 Aug 2011, 2:09 PM
#20
ajeh avatar

ajeh

Oba-san

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

Re: Flat rate for 1 category, Per Item for all others

You can add as many as you want, just follow the pattern ...

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!