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
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 ...
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
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:
Code:
// 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:
Code:
// 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:
Code:
$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;
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
Code:
<?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 http://www.zen-cart.com/license/2_0.txt 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();
}
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
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 ...
1 Attachment(s)
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
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
1 Attachment(s)
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 ...