Forums / Addon Shipping Modules / Seperate shipping method by category - USPS with FLAT rate for 1 master category

Seperate shipping method by category - USPS with FLAT rate for 1 master category

Views: 3,162

Results 1 to 17 of 17
10 Jan 2012, 2:54 PM
#1
wa1ed avatar

wa1ed

New Zenner

Join Date:
Dec 2005
Posts:
17
Plugin Contributions:
0

Seperate shipping method by category - USPS with FLAT rate for 1 master category

Hello,
Version is Zen Cart 1.3.7

I know this has been gone over and I have searched and read many entries but still do not quite get how to do this.

Our Store http://santas-village-shop.com/zen2/ sells many items, most of which can be shipped USPS and that works well. I have 3 items in Master category 5 that I would like to set a flat rate of $3 to ship. I do not want flat rate to show up on any other items.

I will provide textual instructions to the customer to tell them these items must be purchased separately.

SO:

if category 5 item, flat rate $3 - No other shipping method
If any other category USPS - No Flat rate

A method of doing this that allows shipping costs to be added together at checkout would be ideal so that the customer doesn't have to do 2 orders if they want to purchase from category 5 and an item from another category. However as stated above, I can provide textual instructions to the customer if needed.

Any help would be greatly appreciated

Thank you
Ed LaBonte
Santa's I.T. Elf

10 Jan 2012, 3:56 PM
#2
ajeh avatar

ajeh

Oba-san

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

Re: Seperate shipping method by category - USPS with FLAT rate for 1 master category

Have you considered checking how many Products are in the Cart from category 5 and if:

all are from category 5 use Flat Rate ...

none are from category 5 use USPS ...

if 1 or more are from category 5 but other products are in the cart, adjust the price for them and use USPS ...

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!

10 Jan 2012, 6:32 PM
#3
wa1ed avatar

wa1ed

New Zenner

Join Date:
Dec 2005
Posts:
17
Plugin Contributions:
0

Re: Seperate shipping method by category - USPS with FLAT rate for 1 master category

Hi and Thank you!!

That sounds great but How what where? Would you be able to give me a little more assistance?

Thank you
Ed

10 Jan 2012, 7:28 PM
#4
ajeh avatar

ajeh

Oba-san

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

Re: Seperate shipping method by category - USPS with FLAT rate for 1 master category

You would edit the file:
/includes/modules/shipping/flat.php

and add the code in RED:

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

// bof: turn off if not only Category 5 based on master_categories_id
      if (!IS_ADMIN_FLAG) {
        global $db, $cart;
        // check how many products are in the cart for products_id 12, 17, 18
        $chk_products = 0;
        $chk_products += $_SESSION['cart']->in_cart_check('master_categories_id', '5');
        if ($chk_products != $_SESSION[cart]->count_contents()) {
          // turn off shipping module
          $this->enabled = false;
        }
      }
// eof: turn off if not only Category 5 based on master_categories_id


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

Then in the USPS module:
/includes/modules/shipping/usps.php

add code in RED:

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

// bof: turn off if only Category 5 based on master_categories_id
      if (!IS_ADMIN_FLAG) {
        global $db, $cart;
        // check how many products are in the cart for products_id 12, 17, 18
        $chk_products = 0;
        $chk_products += $_SESSION['cart']->in_cart_check('master_categories_id', '5');
        if ($chk_products == $_SESSION[cart]->count_contents()) {
          // turn off shipping module
          $this->enabled = false;
        }
      }
// eof: turn off if only Category 5 based on master_categories_id

    if ($this->enabled) {

and then in the quote for it add the code in RED:

          $cost = preg_replace('/[^0-9.]/', '',  $cost);         
//echo 'USPS: ' . $type . ' cost: ' . $cost . '<br>';

// bof: add $5.00 if 1 or more Category 5 based on master_categories_id
        global $cart;
        // check how many products are in the cart for products_id 12, 17, 18
        $chk_products = 0;
        $extra_charge = 0.00;
        $chk_products += $_SESSION['cart']->in_cart_check('master_categories_id', '5');
        if ($chk_products > 0) {
          // charge $5.00
          $extra_charge = 5.00;
        }
      }

          $methods[] = array('id' => $type,
                             'title' => $title,
                             'cost' => ($cost * $shipping_num_boxes) + $extra_charge + (MODULE_SHIPPING_USPS_HANDLING_METHOD == 'Box' ? MODULE_SHIPPING_USPS_HANDLING * $shipping_num_boxes : MODULE_SHIPPING_USPS_HANDLING) );
// eof: add $5.00 if 1 or more Category 5 based on master_categories_id

        }

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

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!

11 Jan 2012, 12:09 PM
#5
wa1ed avatar

wa1ed

New Zenner

Join Date:
Dec 2005
Posts:
17
Plugin Contributions:
0

Re: Seperate shipping method by category - USPS with FLAT rate for 1 master category

Good Morning!

I have added your code in I think the right places but am having a bit of difficulty. When I upload the modified usps.php file the store does nothing when going to checkout and I cannot access the shipping modules settings under the admin page.

Here is the code as I added it.

thank you
Ed

<?php
/**
 * USPS Module for Zen Cart v1.3.x
 * RateV3 Updates to: January 2, 2011
 *
 * @package shippingMethod
 * @copyright Copyright 2003-2011 Zen Cart Development Team
 * @copyright Portions Copyright 2003 osCommerce
 * @license [url]http://www.zen-cart.com/license/2_0.txt[/url] GNU Public License V2.0
 * @version $Id: usps.php 18306 2011-01-03 01:09:49Z ajeh $
 */
/**
 * USPS Shipping Module class
 *
 */
class usps extends base {
  /**
   * Declare shipping module alias code
   *
   * @var string
   */
  var $code;
  /**
   * Shipping module display name
   *
   * @var string
   */
  var $title;
  /**
   * Shipping module display description
   *
   * @var string
   */
  var $description;
  /**
   * Shipping module icon filename/path
   *
   * @var string
   */
  var $icon;
  /**
   * Shipping module status
   *
   * @var boolean
   */
  var $enabled;
  /**
   * Shipping module list of supported countries (unique to USPS/UPS)
   *
   * @var array
   */
  var $countries;
  /**
   * Constructor
   *
   * @return usps
   */

// use USPS translations for US shops
   var $usps_countries;

  function usps() {
    global $order, $db, $template, $current_page_base;

    $this->code = 'usps';
    $this->title = MODULE_SHIPPING_USPS_TEXT_TITLE;
    $this->description = MODULE_SHIPPING_USPS_TEXT_DESCRIPTION;
    $this->sort_order = MODULE_SHIPPING_USPS_SORT_ORDER;
    $this->icon = $template->get_template_dir('shipping_usps.gif', DIR_WS_TEMPLATE, $current_page_base,'images/icons'). '/' . 'shipping_usps.gif';
    $this->tax_class = MODULE_SHIPPING_USPS_TAX_CLASS;
    $this->tax_basis = MODULE_SHIPPING_USPS_TAX_BASIS;

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

// bof: turn off if only Category 5 based on master_categories_id
      if (!IS_ADMIN_FLAG) {
        global $db, $cart;
        // check how many products are in the cart for products_id 12, 17, 18
        $chk_products = 0;
        $chk_products += $_SESSION['cart']->in_cart_check('master_categories_id', '5');
        if ($chk_products == $_SESSION[cart]->count_contents()) {
          // turn off shipping module
          $this->enabled = false;
        }
      }
// eof: turn off if only Category 5 based on master_categories_id

    if ($this->enabled) {
      // check MODULE_SHIPPING_USPS_HANDLING_METHOD is in
      $check_query = $db->Execute("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_SHIPPING_USPS_HANDLING_METHOD'");
      if ($check_query->EOF) {
        $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Handling Per Order or Per Box', 'MODULE_SHIPPING_USPS_HANDLING_METHOD', 'Box', 'Do you want to charge Handling Fee Per Order or Per Box?', '6', '0', 'zen_cfg_select_option(array(\'Order\', \'Box\'), ', now())");
      }
    }

    if ( ($this->enabled == true) && ((int)MODULE_SHIPPING_USPS_ZONE > 0) ) {
      $check_flag = false;
      $check = $db->Execute("select zone_id from " . TABLE_ZONES_TO_GEO_ZONES . " where geo_zone_id = '" . MODULE_SHIPPING_USPS_ZONE . "' and zone_country_id = '" . $order->delivery['country']['id'] . "' order by zone_id");
      while (!$check->EOF) {
        if ($check->fields['zone_id'] < 1) {
          $check_flag = true;
          break;
        } elseif ($check->fields['zone_id'] == $order->delivery['zone_id']) {
          $check_flag = true;
          break;
        }
        $check->MoveNext();
      }

      if ($check_flag == false) {
        $this->enabled = false;
      }
    }

    $this->types = array('EXPRESS' => 'Express Mail',
        'FIRST CLASS' => 'First-Class Mail',
        'PRIORITY' => 'Priority Mail',
        'PARCEL' => 'Parcel Post',
        'MEDIA' => 'Media Mail',
        'BPM' => 'Bound Printed Matter',
        'LIBRARY' => 'Library'
        );
/*
    $this->intl_types = array(
        'Global Express' => 'Global Express Guaranteed (GXG)',
        'Global Express Non-Doc Rect' => 'Global Express Guaranteed Non-Document Rectangular',
        'Global Express Non-Doc Non-Rect' => 'Global Express Guaranteed Non-Document Non-Rectangular',
        'Global Express Envelopes' => 'USPS GXG Envelopes',
        'Express Mail Int' => 'Express Mail International',
        'Express Mail Int Flat Rate Env' => 'Express Mail International Flat Rate Envelope',
        'Priority Mail International' => 'Priority Mail International',
        'Priority Mail Int Flat Rate Env' => 'Priority Mail International Flat Rate Envelope',
        'Priority Mail Int Flat Rate Box' => 'Priority Mail International Flat Rate Box',
        'Priority Mail Int Flat Rate Small Box' => 'Priority Mail International Small Flat Rate Box',
        'Priority Mail Int Flat Rate Med Box' => 'Priority Mail International Medium Flat Rate Box',
        'Priority Mail Int Flat Rate Lrg Box' => 'Priority Mail International Large Flat Rate Box',
        'First Class Mail Int Lrg Env' => 'First-Class Mail International Large Envelope',
        'First Class Mail Int Package' => 'First-Class Mail International Package',
        'First Class Mail Int Letter' => 'First-Class Mail International Letter'
        );
*/
// update and add new shipping names 01-02-2011
// 4 6 7 12 1 10 [17] 2 11 9 16 [24] [25] 8 [22] [23] [18] [20] 14 15 13
    $this->intl_types = array(
// old
        'Global Express' => 'Global Express Guaranteed (GXG)**', // ID="4" 'Global Express Guaranteed (GXG)'
        'Global Express Non-Doc Rect' => 'Global Express Guaranteed Non-Document Rectangular', // ID="6" 'Global Express Guaranteed Non-Document Rectangular'
        'Global Express Non-Doc Non-Rect' => 'Global Express Guaranteed Non-Document Non-Rectangular', // ID="7" 'Global Express Guaranteed Non-Document Non-Rectangular'
        'USPS GXG Envelopes' => 'USPS GXG Envelopes**', // ID="12" 'USPS GXG Envelopes'
        'Express Mail Int' => 'Express Mail International', // ID="1" 'Express Mail International'
        'Express Mail Int Flat Rate Env' => 'Express Mail International Flat Rate Envelope', // ID="10" 'Express Mail International Flat Rate Envelope'
// new 01-01-2011
        'Express Mail Int Legal' => 'Express Mail International Legal Flat Rate Envelope', // ID="17"
// old
        'Priority Mail International' => 'Priority Mail International', // ID="2" 'Priority Mail International'
        'Priority Mail Int Flat Rate Lrg Box' => 'Priority Mail International Large Flat Rate Box', // ID="11" 'Priority Mail International Large Flat Rate Box'
        'Priority Mail Int Flat Rate Med Box' => 'Priority Mail International Medium Flat Rate Box', // ID="9" 'Priority Mail International Medium Flat Rate Box'
        'Priority Mail Int Flat Rate Small Box' => 'Priority Mail International Small Flat Rate Box**', // ID="16" 'Priority Mail International Small Flat Rate Box'
// new 01-01-2011
        'Priority Mail Int DVD' => 'Priority Mail International DVD Flat Rate Box**', // ID="24"
        'Priority Mail Int Lrg Video' => 'Priority Mail International Large Video Flat Rate Box**', // ID="25"
// old
        'Priority Mail Int Flat Rate Env' => 'Priority Mail International Flat Rate Envelope**', // ID="8" 'Priority Mail International Flat Rate Envelope',
// new 01-01-2011
        'Priority Mail Int Legal Flat Rate Env' => 'Priority Mail International Legal Flat Rate Envelope**', // ID="22"
        'Priority Mail Int Padded Flat Rate Env' => 'Priority Mail International Padded Flat Rate Envelope**', // ID="23"
        'Priority Mail Int Gift Card Flat Rate Env' => 'Priority Mail International Gift Card Flat Rate Envelope**', // ID=18
        'Priority Mail Int Small Flat Rate Env' => 'Priority Mail International Small Flat Rate Envelope**', // ID="20"
// old
        'First Class Mail Int Lrg Env' => 'First-Class Mail International Large Envelope**', // ID="14" 'First-Class Mail International Large Envelope'
        'First Class Mail Int Package' => 'First-Class Mail International Package**', // ID="15" 'First-Class Mail International Package'
        'First Class Mail Int Letter' => 'First-Class Mail International Letter**' // ID="13" 'First-Class Mail International Letter' // ID="13"

        );

    $this->countries = $this->country_list();

// use USPS translations for US shops
    $this->usps_countries = $this->usps_translation();

  }
11 Jan 2012, 1:34 PM
#6
wa1ed avatar

wa1ed

New Zenner

Join Date:
Dec 2005
Posts:
17
Plugin Contributions:
0

Re: Seperate shipping method by category - USPS with FLAT rate for 1 master category

Hi,
After further testing I find that the flat rate shows up for the category5 items and not for any other items without the usps edits. This is great. Halfway there. Thank you

11 Jan 2012, 2:31 PM
#7
ajeh avatar

ajeh

Oba-san

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

Re: Seperate shipping method by category - USPS with FLAT rate for 1 master category

Check your USPS file and make sure that you have no spaces at the bottom and that you have the complete code as you are only showing a portion of the code so I cannot tell ... then reload it to the server ...

Check your directory /cache and see if you have any debug logs in there about the problem ...

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!

11 Jan 2012, 3:02 PM
#8
wa1ed avatar

wa1ed

New Zenner

Join Date:
Dec 2005
Posts:
17
Plugin Contributions:
0

Re: Seperate shipping method by category - USPS with FLAT rate for 1 master category

Hello!
Here is the complete code, I attached it as a zip file. There appears to be no space and I do not see any debug logs. Dreamweaver is telling me I have syntax error on line 307 which I don't see.

Ed

11 Jan 2012, 3:26 PM
#9
wa1ed avatar

wa1ed

New Zenner

Join Date:
Dec 2005
Posts:
17
Plugin Contributions:
0

Re: Seperate shipping method by category - USPS with FLAT rate for 1 master category

Hi, I removed the bracket on line 307 and that seemed to make the usps work again.. When purchasing a category 5 object, flat rate shows up nicely but so does USPS. When not a cat 5 object only USPS shows up which is perfect.

I would like USPS to not show at all on cat 5 objects and it doesnt appear that an extra charge is added when a cat 5 object is grouped with anything else

Thank you so much for your support thus far

Ed

11 Jan 2012, 4:03 PM
#10
ajeh avatar

ajeh

Oba-san

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

Re: Seperate shipping method by category - USPS with FLAT rate for 1 master category

See if this one works better ... I had a typo and a bad bracket but the bracket to remove was on a different line ...

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!

11 Jan 2012, 4:14 PM
#11
wa1ed avatar

wa1ed

New Zenner

Join Date:
Dec 2005
Posts:
17
Plugin Contributions:
0

Re: Seperate shipping method by category - USPS with FLAT rate for 1 master category

PERFECT.. Thank you so much!!!!!!!!!!

Ed

11 Jan 2012, 4:26 PM
#12
ajeh avatar

ajeh

Oba-san

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

Re: Seperate shipping method by category - USPS with FLAT rate for 1 master category

You are most welcome ... sorry for the typos ... :blush:

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 Jan 2012, 10:42 PM
#13
mek113 avatar

mek113

New Zenner

Join Date:
Apr 2011
Posts:
99
Plugin Contributions:
0

Re: Seperate shipping method by category - USPS with FLAT rate for 1 master category

This sounds like a solution for my issue as well but need it for UPS rather than USPS. I don't know PHP so is there any changes that need to be made to customize for UPS?

Does template override need to be used or upload over original file?

27 Jan 2013, 10:35 PM
#14
daffy avatar

daffy

Zen Follower

Join Date:
Jul 2008
Posts:
114
Plugin Contributions:
0

Re: Seperate shipping method by category - USPS with FLAT rate for 1 master category

This thread has been very helpful and I've installed the code and it's working.

My problem is: I want to add a book section to my shop, with subcategories. Using the parent or top category doesn't work. I used parent_id (instead of master_category_id) in the code - because that's the name of the field in the database - but obviously that's wrong because then none of the shipping modules would work and the site crashed.

The parent_id for my book category is 426 and currently I have two subcategories with master_category_id's of 431 and 428... using the code above I can only use a per item rate on one of those master categories. I expect to have a dozen book categories when I get this going, so I'd like a media mail rate for the entire section.

Thank you for any advice on this.

28 Jan 2013, 2:01 AM
#15
daffy avatar

daffy

Zen Follower

Join Date:
Jul 2008
Posts:
114
Plugin Contributions:
0

Re: Seperate shipping method by category - USPS with FLAT rate for 1 master category

Can you add more than one category id to that code, separated by commas? I suppose I could try that. I don't know enough about PHP. I'm good at copy and paste though.

29 Jan 2013, 3:50 PM
#16
daffy avatar

daffy

Zen Follower

Join Date:
Jul 2008
Posts:
114
Plugin Contributions:
0

Re: Seperate shipping method by category - USPS with FLAT rate for 1 master category

I want to add a book section to my shop, and if the only thing they're ordering is books then I need the checkout to switch over to MEDIA MAIL shipping quotes.

I found a partial solution under the thread, Seperate shipping method by category - USPS with FLAT rate for 1 master category and I posted a question there -- but it wasn't discovered apparently.

But the solution in that thread only allows for assigning ONE master category ID for flat rate shipping. I need about a dozen book categories (under one parent ID) and I would rather use true USPS media mail shipping - but if the flat rate is a better work-around, then that's fine.

Are other people having this problem? I'm the only one selling books as well as other items through my shop? That seems a little surprising.
I've searched the forum and there doesn't seem to be much info on MEDIA MAIL even though this is a very significant shipping category for anyone who sells books or DVDs.

29 Jan 2013, 5:03 PM
#17
ajeh avatar

ajeh

Oba-san

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

Re: Seperate shipping method by category - USPS with FLAT rate for 1 master category

If you mean for this code:

// bof: turn off if only Category 5 based on master_categories_id
      if (!IS_ADMIN_FLAG) {
        global $db, $cart;
        // check how many products are in the cart for products_id 12, 17, 18
        $chk_products = 0;
        $chk_products += $_SESSION['cart']->in_cart_check('master_categories_id', '5');
        if ($chk_products == $_SESSION[cart]->count_contents()) {
          // turn off shipping module
          $this->enabled = false;
        }
      }
// eof: turn off if only Category 5 based on master_categories_id

You could use for Category 5 and 7:

// bof: turn off if only Category 5 and Category 7 based on master_categories_id
      if (!IS_ADMIN_FLAG) {
        global $db, $cart;
        $chk_products = 0;
        $chk_products += $_SESSION['cart']->in_cart_check('master_categories_id', '5');
        $chk_products += $_SESSION['cart']->in_cart_check('master_categories_id', '7');
        if ($chk_products == $_SESSION[cart]->count_contents()) {
          // turn off shipping module
          $this->enabled = false;
        }
      }
// eof: turn off if only Category 5 and Category 7 based on master_categories_id

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!