Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Flat rate UPS


dreamscape

Recommended Posts

well frankly I am very surprised that this contribution doesn't already exsist... and since I know nothing about the OSC shipping modules and how to make a new one.... I am wondering if anyone has a way that I can get 3 flat rate shipping options for UPS??

 

like:

 

UPS Shipping

- Ground $6.00

- 2nd Day Air $12.00

- Overnight $18.00

 

I've tried the "modify the flat.php changing "flat" to something else"... it will only work if the original flat.php is enabled and then it takes the shipping figure from the original flat.php no matter what alternate flate rate option is selected.

The only thing necessary for evil to flourish is for good men to do nothing

- Edmund Burke

Link to comment
Share on other sites

Actually, i am using 3 methods for shipping

 

ups - 5.95

fedex 2 day 12.95

fedex 1 day 16.95

 

All these are using mod versions of the flat.php file. Make sure when you are modifing the flat.php file that you change EVERY ref. to the word flat.

 

Examples

 

flat -> flat2

FLAT -> FLAT2

 

The reason that the flat must be active for all to work in your case is that you didn't change the class name (flat ).

 

It can be done... Good luck PM me if you need further help.

 

 

Steve

Link to comment
Share on other sites

I did change everything...

 

I'm not some 2 bit idiot magee here... I specifically made sure everything was changed.

The only thing necessary for evil to flourish is for good men to do nothing

- Edmund Burke

Link to comment
Share on other sites

I even though that maybe the flat_... in front was messin it up so I changed it all to "f_ups_ground" and "F_UPS_GROUND".... and changed the filenames to f_ups_ground.php as well....

 

and lo and behold it still does not work... just cycles through checkout_shipping.php unless I activate the original flat.php module and then takes only the figures from the original module....

 

I am on MS1 (actually snapshot from march 3, 2003... MS2.2CVS)

The only thing necessary for evil to flourish is for good men to do nothing

- Edmund Burke

Link to comment
Share on other sites

<?php

/*

$Id: flatrate2.php,v 1.40 2003/02/05 22:41:52 hpdl Exp $

 

osCommerce, Open Source E-Commerce Solutions

http://www.oscommerce.com

 

Copyright © 2003 osCommerce

 

Released under the GNU General Public License

 

Based on flat.php / named flaterate2.php / by steve 3/13/03

*/

 

class flatrate2 {

var $code, $title, $description, $icon, $enabled;

 

// class constructor

function flatrate2() {

global $order;

 

$this->code = 'flatrate2';

$this->title = MODULE_SHIPPING_FLATRATE2_TEXT_TITLE;

$this->description = MODULE_SHIPPING_FLATRATE2_TEXT_DESCRIPTION;

$this->sort_order = MODULE_SHIPPING_FLATRATE2_SORT_ORDER;

$this->icon = '';

$this->tax_class = MODULE_SHIPPING_FLATRATE2_TAX_CLASS;

$this->enabled = ((MODULE_SHIPPING_FLATRATE2_STATUS == 'True') ? true : false);

 

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

$check_flag = false;

$check_query = tep_db_query("select zone_id from " . TABLE_ZONES_TO_GEO_ZONES . " where geo_zone_id = '" . MODULE_SHIPPING_FLATRATE2_ZONE . "' and zone_country_id = '" . $order->delivery['country']['id'] . "' order by zone_id");

while ($check = tep_db_fetch_array($check_query)) {

if ($check['zone_id'] < 1) {

$check_flag = true;

break;

} elseif ($check['zone_id'] == $order->delivery['zone_id']) {

$check_flag = true;

break;

}

}

 

if ($check_flag == false) {

$this->enabled = false;

}

}

}

 

// class methods

function quote($method = '') {

global $order;

 

$add_charge = 0;

if (((int)$order->delivery['zone_id'] == 13) || ((int)$order->delivery['zone_id'] == 2)) {

$add_charge = (int)ADDITIONAL_SHIPPING_CHARGE;

}

 

$this->quotes = array('id' => $this->code,

'module' => MODULE_SHIPPING_FLATRATE2_TEXT_TITLE,

'methods' => array(array('id' => $this->code,

'title' => MODULE_SHIPPING_FLATRATE2_TEXT_WAY,

'cost' => MODULE_SHIPPING_FLATRATE2_COST + $add_charge)));

 

if ($this->tax_class > 0) {

$this->quotes['tax'] = tep_get_tax_rate($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);

}

 

if (tep_not_null($this->icon)) $this->quotes['icon'] = tep_image($this->icon, $this->title);

 

return $this->quotes;

}

 

function check() {

if (!isset($this->_check)) {

$check_query = tep_db_query("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_SHIPPING_FLATRATE2_STATUS'");

$this->_check = tep_db_num_rows($check_query);

}

return $this->_check;

}

 

function install() {

tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Enable Flat Rate Shipping', 'MODULE_SHIPPING_FLATRATE2_STATUS', 'True', 'Do you want to offer flat rate rate shipping?', '6', '0', 'tep_cfg_select_option(array('True', 'False'), ', now())");

tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Shipping Cost', 'MODULE_SHIPPING_FLATRATE2_COST', '5.00', 'The shipping cost for all orders using this shipping method.', '6', '0', now())");

tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, use_function, set_function, date_added) values ('Tax Class', 'MODULE_SHIPPING_FLATRATE2_TAX_CLASS', '0', 'Use the following tax class on the shipping fee.', '6', '0', 'tep_get_tax_class_title', 'tep_cfg_pull_down_tax_classes(', now())");

tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, use_function, set_function, date_added) values ('Shipping Zone', 'MODULE_SHIPPING_FLATRATE2_ZONE', '0', 'If a zone is selected, only enable this shipping method for that zone.', '6', '0', 'tep_get_zone_class_title', 'tep_cfg_pull_down_zone_classes(', now())");

tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Sort Order', 'MODULE_SHIPPING_FLATRATE2_SORT_ORDER', '0', 'Sort order of display.', '6', '0', now())");

}

 

function remove() {

tep_db_query("delete from " . TABLE_CONFIGURATION . " where configuration_key in ('" . implode("', '", $this->keys()) . "')");

}

 

function keys() {

return array('MODULE_SHIPPING_FLATRATE2_STATUS', 'MODULE_SHIPPING_FLATRATE2_COST', 'MODULE_SHIPPING_FLATRATE2_TAX_CLASS', 'MODULE_SHIPPING_FLATRATE2_ZONE', 'MODULE_SHIPPING_FLATRATE2_SORT_ORDER');

}

}

?>

Link to comment
Share on other sites

I got "ground" to work...

 

renaming to "flat_ups" or "flat_anything" crashes the module.

 

renaming to "f1" crashes the module

 

renaming to "f_ups_ground" crashes the module..

 

who the hell designed the shipping modules anyways, that it will only take certain names and not other?

The only thing necessary for evil to flourish is for good men to do nothing

- Edmund Burke

Link to comment
Share on other sites

Steve, sorry to reply like that...

 

it has come to my attention that perhaps english is not your native language, and sometime I forget that the rest of the world does not speak english natively...

 

anyways I found the problem... appraently shipping modules cannot contain and underscore in the name. it does not work if they do. also apprently they cannot be too short either (as F1 did not work either?)...

The only thing necessary for evil to flourish is for good men to do nothing

- Edmund Burke

Link to comment
Share on other sites

anything with an underscore in it, "_", crashes the module

 

I avoid special characters of all kinds and numbers.

 

Breaks those modules faster than anything. :shock:

Link to comment
Share on other sites

anything with an underscore in it, "_", crashes the module

 

I avoid special characters of all kinds and numbers.

 

Breaks those modules faster than anything. :shock:

 

I can understand avoiding number and special characters but I really don't consider and underscore to be a special character, especially in the world programming where spaces are a big NO NO and often underscores are used in place.

The only thing necessary for evil to flourish is for good men to do nothing

- Edmund Burke

Link to comment
Share on other sites

I never thought the _ a special character either until I worked with modules ...

 

It is something in how classes handle it or how the modules are written that makes them bug out when you use them.

Link to comment
Share on other sites

  • 1 month later...
I think "_" maybe illegal in a class name. Atleast that's what I got from this site:http://utvikler.start.no/code/php_coding_standard.html#classnames

 

Nope, that's not true. This code works OK:

 

<?php

$a = new a_b();

$a->hello();

 

class a_b {

function hello() {

echo "hello";

}

}

?>

----------------

Alonso Acu�a

Founder and Lead Programmer

Link to comment
Share on other sites

well thats a fine little example you have there, but really it doesn't prove anything other than you can use an underscore if your class is very very very simple.

 

make a payment or shipment module/class for OSC with an underscore in the name and see if it works as it should then. I think you will find otherwise.

The only thing necessary for evil to flourish is for good men to do nothing

- Edmund Burke

Link to comment
Share on other sites

My point was that the PHP language does accept underscores, contrary to what someone else suggested. I figure this means that this is a problem in the modules implementation then.

----------------

Alonso Acu�a

Founder and Lead Programmer

Link to comment
Share on other sites

Not meaning to aggravate anyone but I guess it's important to notice.

 

 

I came here looking for info on how to setup multiple flat rates by zones. When I read this about the special characters I named my two new modules (copies of flat.php) flat2.php and tnt_other.php just for fun and maybe to try and fix something. I did search and replace for FLAT to FLAT2, flat to flat2 then same with TNT_OTHER. This was both in languages/modules and in includes/modules.

 

And guess what, it works :o

 

I can deactivate the original flat.php and the others work OK.

 

I did have to populate the zones_to_geo_zones table to make this work by countries.

 

If anyone wants to setup 3 flat rate zones like U.S.A., Europe and All others, do this: (based on some code I found in the osc extra folder)

 

DELETE FROM geo_zones;

DELETE FROM zones_to_geo_zones;

 

 

INSERT INTO geo_zones (geo_zone_id,geo_zone_name,geo_zone_description,date_added) VALUES (1,"Europe","Europe",now());

INSERT INTO geo_zones (geo_zone_id,geo_zone_name,geo_zone_description,date_added) VALUES (2,"U.S.","U.S.",now());

INSERT INTO geo_zones (geo_zone_id,geo_zone_name,geo_zone_description,date_added) VALUES (4,"All Others","All Others",now());

 

 

INSERT INTO zones_to_geo_zones (association_id,zone_country_id,zone_id,geo_zone_id,date_added) VALUES (1,222,NULL,1,now()); #UK

INSERT INTO zones_to_geo_zones (association_id,zone_country_id,zone_id,geo_zone_id,date_added) VALUES (3,73,NULL,1,now()); #France

INSERT INTO zones_to_geo_zones (association_id,zone_country_id,zone_id,geo_zone_id,date_added) VALUES (4,105,NULL,1,now()); #Italy

INSERT INTO zones_to_geo_zones (association_id,zone_country_id,zone_id,geo_zone_id,date_added) VALUES (5,21,NULL,1,now()); #Belgium

INSERT INTO zones_to_geo_zones (association_id,zone_country_id,zone_id,geo_zone_id,date_added) VALUES (6,150,NULL,1,now()); #Holland

INSERT INTO zones_to_geo_zones (association_id,zone_country_id,zone_id,geo_zone_id,date_added) VALUES (7,195,NULL,1,now()); #Spain

INSERT INTO zones_to_geo_zones (association_id,zone_country_id,zone_id,geo_zone_id,date_added) VALUES (8,203,NULL,1,now()); #Sweden

INSERT INTO zones_to_geo_zones (association_id,zone_country_id,zone_id,geo_zone_id,date_added) VALUES (9,72,NULL,1,now()); #Finland

INSERT INTO zones_to_geo_zones (association_id,zone_country_id,zone_id,geo_zone_id,date_added) VALUES (10,57,NULL,1,now()); #Denmark

INSERT INTO zones_to_geo_zones (association_id,zone_country_id,zone_id,geo_zone_id,date_added) VALUES (11,84,NULL,1,now()); #Greece

INSERT INTO zones_to_geo_zones (association_id,zone_country_id,zone_id,geo_zone_id,date_added) VALUES (12,171,NULL,1,now()); #Portugal

INSERT INTO zones_to_geo_zones (association_id,zone_country_id,zone_id,geo_zone_id,date_added) VALUES (13,103,NULL,1,now()); #Ireland

INSERT INTO zones_to_geo_zones (association_id,zone_country_id,zone_id,geo_zone_id,date_added) VALUES (14,124,NULL,1,now()); #Luxembourg

 

INSERT INTO zones_to_geo_zones (association_id,zone_country_id,zone_id,geo_zone_id,date_added) VALUES (15,223,NULL,2,now()); #USA

 

 

 

#fill with all other countries into zone 4

drop table if exists tmp;

create temporary table tmp(countries_id int);

 

insert into tmp(countries_id)

SELECT countries_id FROM countries c LEFT OUTER JOIN zones_to_geo_zones z

ON c.countries_id=z.zone_country_id WHERE z.zone_country_id IS null;

 

INSERT INTO zones_to_geo_zones (zone_country_id,zone_id,geo_zone_id,date_added)

SELECT countries_id,NULL,4,now() FROM tmp;

 

drop table tmp;

----------------

Alonso Acu�a

Founder and Lead Programmer

Link to comment
Share on other sites

Not meaning to aggravate anyone but I guess it's important to notice.

 

I came here looking for info on how to setup multiple flat rates by zones. When I read this about the special characters I named my two new modules (copies of flat.php) flat2.php and tnt_other.php just for fun and maybe to try and fix something. I did search and replace for FLAT to FLAT2, flat to flat2 then same with TNT_OTHER. This was both in languages/modules and in includes/modules.

 

And guess what, it works :o

 

If only it were consistant ... :shock:

 

Since it works intermitantly, I avoid the underscore, numbers and special characters.

 

I can get it to work on simple modules. But more complex modules it fails and is not worth figuring out when it's going to work and when it's going to fail based on the depth of the module. :wink:

Link to comment
Share on other sites

I am willing to spend a couple hours of my weekend on finding out what is the problem. If someone could just send me a non-working module which then works when special chars. are eliminated.

 

send to: alonso at admintek dot net

----------------

Alonso Acu�a

Founder and Lead Programmer

Link to comment
Share on other sites

Ok so it wasn't working... It just seemed to work until a customer pointed the problem out. :oops:

 

So I went in to catalog/checkout_shipping.php and found the problem. Indeed any shipping module with an underscore will not work because of what seems to be bad programming in this page (or missing documentation warning against such names).

 

For some reason someone thought that it was a good idea to put two pieces of information into one hidden form field and separate them with a '_' then, after the form is submitted look for '_' to split it back into the two original pieces, or (both?) of these pieces are the module code so if it has a '_' it is splitted incorrectly. By changing the splitting char. to something else I managed to make my modules work.

 

I feel this is a bug. Anyone cares to file it? Fix it?

----------------

Alonso Acu�a

Founder and Lead Programmer

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...