Forums / Built-in Shipping and Payment Modules / Flat rate shipping based on master category ID?

Flat rate shipping based on master category ID?

Views: 4,399

Results 1 to 19 of 19
26 Mar 2014, 1:14 PM
#1
snowgoose avatar

snowgoose

New Zenner

Join Date:
Jul 2011
Posts:
21
Plugin Contributions:
0

Flat rate shipping based on master category ID?

Hello all,

I'm trying to sort out shipping within my development site.

I need 3 types of flat rate shipping.

1 ) Livestock, ( eg, cat ID's 1, 4 & 5 )
2 ) Drystock ( eg, cat ID's 2 & 6 )
3 ) Mix of both (eg, Cat ID's 1, 4 & 6 )

I think I need to duplicate the flat rate shipping module twice ( giving me 3 flat rates ), then have them check the basket for items within selected categories and then estimate shipping based on that?

1 would be £8.00
2 would be £5
3 would be £10

My PHP knowledge isn't the best so I was hoping someone might be able to help with my query?

Jake

26 Mar 2014, 1:26 PM
#2
ajeh avatar

ajeh

Oba-san

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

Re: Flat rate shipping based on master category ID?

I buy 12 Products from master_categories_id 1, 4 and 5 and pay just £8.00, correct?

I buy 12 Products from master_categories_id 2 and 6 and pay just £5, correct?

I buy 12 Products from master_categories_id 1, 2, 4, 5 and 6 and pay just £10, correct?

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!

26 Mar 2014, 1:29 PM
#3
snowgoose avatar

snowgoose

New Zenner

Join Date:
Jul 2011
Posts:
21
Plugin Contributions:
0

Re: Flat rate shipping based on master category ID?

Yes that is correct :) Prices stay the same regardless of quantities purchased :)

26 Mar 2014, 1:42 PM
#4
ajeh avatar

ajeh

Oba-san

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

Re: Flat rate shipping based on master category ID?

The cloning the Flat Rate flat module would be the best choice and then customize when each of the modules show based on the content of the shopping cart ...

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!

26 Mar 2014, 1:52 PM
#5
snowgoose avatar

snowgoose

New Zenner

Join Date:
Jul 2011
Posts:
21
Plugin Contributions:
0

Re: Flat rate shipping based on master category ID?

Ajeh:

The cloning the Flat Rate flat module would be the best choice and then customize when each of the modules show based on the content of the shopping cart ...

Thanks that is what I was thinking.

Any idea of the codes needed for each module in order for them to check the cart contents?

26 Mar 2014, 2:02 PM
#6
ajeh avatar

ajeh

Oba-san

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

Re: Flat rate shipping based on master category ID?

You can use the code in RED and adapt it as needed:

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

[B]// bof: only show for category 1, 4 and 5
      $chk_cat = 0;
      $chk_cat += $_SESSION['cart']->in_cart_check('master_categories_id','1');
      $chk_cat += $_SESSION['cart']->in_cart_check('master_categories_id','4');
      $chk_cat += $_SESSION['cart']->in_cart_check('master_categories_id','5');
      if ($chk_cat != $_SESSION['cart']->show_total()) {
        $this->enabled = false;
      }
// eof: only show for category 1, 4 and 5
[/B]

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!

26 Mar 2014, 2:12 PM
#7
snowgoose avatar

snowgoose

New Zenner

Join Date:
Jul 2011
Posts:
21
Plugin Contributions:
0

Re: Flat rate shipping based on master category ID?

Ajeh:

You can use the code in RED and adapt it as needed:

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

[B]// bof: only show for category 1, 4 and 5
$chk_cat = 0;
$chk_cat += $_SESSION['cart']->in_cart_check('master_categories_id','1');
$chk_cat += $_SESSION['cart']->in_cart_check('master_categories_id','4');
$chk_cat += $_SESSION['cart']->in_cart_check('master_categories_id','5');
if ($chk_cat != $_SESSION['cart']->show_total()) {
$this->enabled = false;
}
// eof: only show for category 1, 4 and 5
[/B]


Thanks very much for that :)
26 Mar 2014, 3:37 PM
#8
snowgoose avatar

snowgoose

New Zenner

Join Date:
Jul 2011
Posts:
21
Plugin Contributions:
0

Re: Flat rate shipping based on master category ID?

I've managed to clone the shipping module and update them for Livestock & Drystock, but I can't work out the third one for "mixed" orders containing both.

Does it actually need it's own code adding, or not due to the other codes using single category ID's ( i.e, if two different ID's were used ( 2 & 6 ), would the standard flat rate shipping come into play?

26 Mar 2014, 3:46 PM
#9
ajeh avatar

ajeh

Oba-san

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

Re: Flat rate shipping based on master category ID?

Also, you need to add for the Admin an IF around the new code:

if (!IS_ADMIN_FLAG) {
// new code here
}

For checking it is a mixed cart try:

// bof: only show for mixed cart category 1, 4 and 5 & category 2 and 6
if (!IS_ADMIN_FLAG) {
      $chk_cat = 0;
      $chk_cat += $_SESSION['cart']->in_cart_check('master_categories_id','1');
      $chk_cat += $_SESSION['cart']->in_cart_check('master_categories_id','4');
      $chk_cat += $_SESSION['cart']->in_cart_check('master_categories_id','5');

      $chk_cat2 = 0;
      $chk_cat2 += $_SESSION['cart']->in_cart_check('master_categories_id','2');
      $chk_cat2 += $_SESSION['cart']->in_cart_check('master_categories_id','6');

//echo 'Flat sees $chk_cat: ' . $chk_cat . ' $chk_cat2: ' . $chk_cat2 . '<br>';

      if ($this->enabled && ($chk_cat > 0 && $chk_cat2 > 0)) {
        $this->enabled = true;
      } else {
        $this->enabled = false;
      }
}
// eof: only show for mixed cart category 1, 4 and 5 & category 2 and 6

That echo can be uncommented for testing purposes ...

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!

26 Mar 2014, 4:30 PM
#10
snowgoose avatar

snowgoose

New Zenner

Join Date:
Jul 2011
Posts:
21
Plugin Contributions:
0

Re: Flat rate shipping based on master category ID?

Ajeh:

Also, you need to add for the Admin an IF around the new code:

if (!IS_ADMIN_FLAG) {
// new code here
}

> 
> For checking it is a mixed cart try:
> ```
// bof: only show for mixed cart category 1, 4 and 5 & category 2 and 6
if (!IS_ADMIN_FLAG) {
      $chk_cat = 0;
      $chk_cat += $_SESSION['cart']->in_cart_check('master_categories_id','1');
      $chk_cat += $_SESSION['cart']->in_cart_check('master_categories_id','4');
      $chk_cat += $_SESSION['cart']->in_cart_check('master_categories_id','5');

      $chk_cat2 = 0;
      $chk_cat2 += $_SESSION['cart']->in_cart_check('master_categories_id','2');
      $chk_cat2 += $_SESSION['cart']->in_cart_check('master_categories_id','6');

//echo 'Flat sees $chk_cat: ' . $chk_cat . ' $chk_cat2: ' . $chk_cat2 . '<br>';

      if ($this->enabled && ($chk_cat > 0 && $chk_cat2 > 0)) {
        $this->enabled = true;
      } else {
        $this->enabled = false;
      }
}
// eof: only show for mixed cart category 1, 4 and 5 & category 2 and 6

That echo can be uncommented for testing purposes ...

I've implemented the above but it doesn't seem to work.

I've got the flat rate shippings to display, but the cheapest shipping option comes up bold on checkout and allows checkout regardless of category number.

I need it to automatically select shipping based on category ID or even automatically add the correct shipping to customer total at checkout?

26 Mar 2014, 4:32 PM
#11
ajeh avatar

ajeh

Oba-san

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

Re: Flat rate shipping based on master category ID?

Could you Zip your 3 Flat Rates that you are using and attach them to your next post?

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!

26 Mar 2014, 6:05 PM
#13
ajeh avatar

ajeh

Oba-san

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

Re: Flat rate shipping based on master category ID?

I had a heck of a time with these files as I could not figure out why they were breaking things at first ...

I am guessing you are a MAC user? That is what I finally noticed these files were in an odd format that was MAC ... :blink:

Next, I noticed I made a boo boo and had you using show_total instead of count_contents ... major error! :eek:

Anyway ... I tidied up things and now they appear to work fine so try this Zip ...

NOTE: I was not nice and neat like you building proper directories for these files I just tossed them in a Zip ... your way is the correct way to do files, btw

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!

26 Mar 2014, 6:35 PM
#14
snowgoose avatar

snowgoose

New Zenner

Join Date:
Jul 2011
Posts:
21
Plugin Contributions:
0

Re: Flat rate shipping based on master category ID?

Ajeh:

I had a heck of a time with these files as I could not figure out why they were breaking things at first ...

I am guessing you are a MAC user? That is what I finally noticed these files were in an odd format that was MAC ... :blink:

Next, I noticed I made a boo boo and had you using show_total instead of count_contents ... major error! :eek:

Anyway ... I tidied up things and now they appear to work fine so try this Zip ...

NOTE: I was not nice and neat like you building proper directories for these files I just tossed them in a Zip ... your way is the correct way to do files, btw

Nope, no MAC in this house :) All files were edited using Windows and Notepad++, so not sure how we got MAC format :blink:

Thanks so much for your help, all seems to be working well :)

26 Mar 2014, 6:41 PM
#15
ajeh avatar

ajeh

Oba-san

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

Re: Flat rate shipping based on master category ID?

Thanks for the update all is well ...

Maybe I goobered something up in trying to clean the files up to work with them ... very weird ... :blink:

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!

26 Mar 2014, 7:38 PM
#16
snowgoose avatar

snowgoose

New Zenner

Join Date:
Jul 2011
Posts:
21
Plugin Contributions:
0

Re: Flat rate shipping based on master category ID?

Ajeh:

Thanks for the update all is well ...

Maybe I goobered something up in trying to clean the files up to work with them ... very weird ... :blink:

I'm now having a few small teething problems. Everything works fine, I just have " Flat sees $chk_cat: 1 $chk_cat2: 1" displaying in the shopping cart all the time ( the numbers are different depending on cart contents, but I'm guessing it's something to do with the "Echo" command in the code?

Also, is there any way to scrap the shipping estimator totally and just have a small shipping quote under the "sub-total" in the cart automatically assuming customers are within UK ( if not they can't checkout anyway )

26 Mar 2014, 9:12 PM
#17
snowgoose avatar

snowgoose

New Zenner

Join Date:
Jul 2011
Posts:
21
Plugin Contributions:
0

Re: Flat rate shipping based on master category ID?

Shipping is now showing in the actual cart rather than just the estimator.

Still getting the "Flat sees $chk_cat" text appearing ?

26 Mar 2014, 9:25 PM
#18
snowgoose avatar

snowgoose

New Zenner

Join Date:
Jul 2011
Posts:
21
Plugin Contributions:
0

Re: Flat rate shipping based on master category ID?

Silly me,

Just put the "//" back in front of the "echo on the "flatboth" and all working fine :)

SOLVED

26 Mar 2014, 9:35 PM
#19
ajeh avatar

ajeh

Oba-san

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

Re: Flat rate shipping based on master category ID?

Thanks for the update that things are working properly ... :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!