Guest Posted September 16, 2005 Share Posted September 16, 2005 i'm using the "extra table" contribution for shipping. 1 table: usa/canada 2 table: elsewhere now, as of this moment the customer can more or less select the wrong shipping rates (which has happened many a times in the past under my old system) would it be possible for me to "hide" the usa/canada rates if the users' mailing address on file is from another country, and vice-versa? Link to comment Share on other sites More sharing options...
Guest Posted September 16, 2005 Share Posted September 16, 2005 yes you could, here is the code flow: in catalog\checkout_shipping there is a call to the shipping class to collect all shipping modules: // get all available shipping quotes $quotes = $shipping_modules->quote(); The quote function must be defined in your shipping module. Change it to return the quote based on a country/customer-address match. Link to comment Share on other sites More sharing options...
Guest Posted September 16, 2005 Share Posted September 16, 2005 sorry that confuses me a bit. could you give me a step by step instructions on how to achieve this? Link to comment Share on other sites More sharing options...
Guest Posted September 16, 2005 Share Posted September 16, 2005 ok this is from the regions contrib I have with my shop its in the includes\modules\shipping directory (you have a shipping module there too) from function quote(): $dest_state = $order->delivery['state']; $dest_country = $order->delivery['country']['title']; So now if I get the current customer details (you have the $customers_id global var so you can find anything you want from the customers table) I can compare the country I return the quote for (vs the customers country) Depends on the module though but should be something similar with yours. Link to comment Share on other sites More sharing options...
Guest Posted September 16, 2005 Share Posted September 16, 2005 i have this: $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; } if the user is US,CA - how can i hide the other rates? and vice versa Link to comment Share on other sites More sharing options...
Guest Posted September 16, 2005 Share Posted September 16, 2005 the order class maintains the delivery along wih customer arrays. The delivery has the ['country'] field as you already seen it with the code you posted. The customer has also the ['country'] field so you could compare the 2 before fetching the available shipping rates. if( $order->delivery['country']['id'] == $order->customer['country']['id'] ) { // setup the quote } Link to comment Share on other sites More sharing options...
Guest Posted September 16, 2005 Share Posted September 16, 2005 how could i set up the code? this is the shipping module i use for overseas orders: <?php /* $Id: table.php,v 1.27 2003/02/05 22:41:52 hpdl Exp $ osCommerce, Open Source E-Commerce Solutions http://www.oscommerce.com Copyright (c) 2003 osCommerce Released under the GNU General Public License */ class table2 { var $code, $title, $description, $icon, $enabled; // class constructor function table2() { global $order; $this->code = 'table2'; $this->title = MODULE_SHIPPING_TABLE2_TEXT_TITLE; $this->description = MODULE_SHIPPING_TABLE2_TEXT_DESCRIPTION; $this->sort_order = MODULE_SHIPPING_TABLE2_SORT_ORDER; $this->icon = ''; $this->tax_class = MODULE_SHIPPING_TABLE2_TAX_CLASS; $this->enabled = ((MODULE_SHIPPING_TABLE2_STATUS == 'True') ? true : false); if ( ($this->enabled == true) && ((int)MODULE_SHIPPING_TABLE2_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_TABLE_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, $cart, $shipping_weight, $shipping_num_boxes; if (MODULE_SHIPPING_TABLE2_MODE == 'price') { $order_total = $cart->show_total(); } else { $order_total = $shipping_weight; } $table_cost = split("[:,]" , MODULE_SHIPPING_TABLE2_COST); $size = sizeof($table_cost); for ($i=0, $n=$size; $i<$n; $i+=2) { if ($order_total <= $table_cost[$i]) { $shipping = $table_cost[$i+1]; break; } } if (MODULE_SHIPPING_TABLE2_MODE == 'weight') { $shipping = $shipping * $shipping_num_boxes; } $this->quotes = array('id' => $this->code, 'module' => MODULE_SHIPPING_TABLE2_TEXT_TITLE, 'methods' => array(array('id' => $this->code, 'title' => MODULE_SHIPPING_TABLE2_TEXT_WAY, 'cost' => $shipping + MODULE_SHIPPING_TABLE2_HANDLING))); 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_TABLE2_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 Table Method', 'MODULE_SHIPPING_TABLE2_STATUS', 'True', 'Do you want to offer table 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 Table', 'MODULE_SHIPPING_TABLE2_COST', '25:8.50,50:5.50,10000:0.00', 'The shipping cost is based on the total cost or weight of items. Example: 25:8.50,50:5.50,etc.. Up to 25 charge 8.50, from there to 50 charge 5.50, etc', '6', '0', now())"); 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 ('Table Method', 'MODULE_SHIPPING_TABLE2_MODE', 'weight', 'The shipping cost is based on the order total or the total weight of the items ordered.', '6', '0', 'tep_cfg_select_option(array(\'weight\', \'price\'), ', now())"); tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Handling Fee', 'MODULE_SHIPPING_TABLE2_HANDLING', '0', 'Handling fee for 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_TABLE2_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_TABLE2_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_TABLE2_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_TABLE2_STATUS', 'MODULE_SHIPPING_TABLE2_COST', 'MODULE_SHIPPING_TABLE2_MODE', 'MODULE_SHIPPING_TABLE2_HANDLING', 'MODULE_SHIPPING_TABLE2_TAX_CLASS', 'MODULE_SHIPPING_TABLE2_ZONE', 'MODULE_SHIPPING_TABLE2_SORT_ORDER'); } } ?> US,CA,PR,APO all use the same script, but instead of "table2" it's simply "table" i'm sorry i can't code very good :) i only know how to modify what's there Link to comment Share on other sites More sharing options...
Guest Posted September 16, 2005 Share Posted September 16, 2005 so you do not want to use this module if a customer is from US/CA? or you want to use it but change somehow the rates in it? Link to comment Share on other sites More sharing options...
Guest Posted September 16, 2005 Share Posted September 16, 2005 i want to use the modules, because my shipping rates are based on order total. BUT, if they are in USA, etc. i do not want them to see the shipping rates from the overseas table, and vice versa Link to comment Share on other sites More sharing options...
Guest Posted September 16, 2005 Share Posted September 16, 2005 this is what I dont understand, You see when this module's class is instantiated does this: $check_query = tep_db_query("select zone_id from " . TABLE_ZONES_TO_GEO_ZONES . " where geo_zone_id = '" . MODULE_SHIPPING_TABLE_ZONE . "' and zone_country_id = '" . $order->delivery['country']['id'] . "' order by zone_id"); which filters everything except the delivery zone. So let me understand this The customer is from overseas but he places a delivery address in US/CA? Is that the problem? Because this filter should take care of the rates for the country. In fact it wont even enable the module. (or so it seems) because I am not sure of this: if ($check['zone_id'] < 1) { $check_flag = true; break; seems it the zone_id doesnt match it enables the module. comment out that line and try it (just for the < 1 comparison to see) like this: //$check_flag = true; Link to comment Share on other sites More sharing options...
Guest Posted September 16, 2005 Share Posted September 16, 2005 the modules i have set up, i have TWO different tables setup, only they weren't designed to be for local / international. i made them that way on my own because i couldn't find a contribution that worked with north american and overseas shipping rates to fit my needs. table = north america table2 = overseas let's say someone checking out has a north american address, the table2 module will be hidden for them and only table will show Link to comment Share on other sites More sharing options...
Guest Posted September 16, 2005 Share Posted September 16, 2005 I think I understand now so you have another class called table (The one you posted is table2) Allright so everything comes down to when this flag thing will be set to true. try this with an account with a US address see if this table2 shows up (shouldnt) Modify this code $check_query = tep_db_query("select zone_id from " . TABLE_ZONES_TO_GEO_ZONES . " where geo_zone_id = '" . MODULE_SHIPPING_TABLE_ZONE . "' and zone_country_id = '" . $order->delivery['country']['id'] . "' order by zone_id"); To this: $check_query = tep_db_query("select zone_id from " . TABLE_ZONES_TO_GEO_ZONES . " where geo_zone_id = '" . MODULE_SHIPPING_TABLE_ZONE . "' and zone_country_id != '223' and zone_country_id = '" . $order->delivery['country']['id'] . "' order by zone_id"); I just hard-coded for the US id if its found it should not fill up the array and therefore should not enable table2. If that works repeat for CA. Link to comment Share on other sites More sharing options...
Guest Posted September 16, 2005 Share Posted September 16, 2005 which file should i modify? the checkout page or one of the shipping tables? Link to comment Share on other sites More sharing options...
Guest Posted September 16, 2005 Share Posted September 16, 2005 the file you posted. Thats the shipping module for table2. backup first Link to comment Share on other sites More sharing options...
Guest Posted September 16, 2005 Share Posted September 16, 2005 still shows both selections :( Link to comment Share on other sites More sharing options...
Guest Posted September 17, 2005 Share Posted September 17, 2005 yes ok maybe that was not correct. :'( Restore the file then change this code: $check_query = tep_db_query("select zone_id from " . TABLE_ZONES_TO_GEO_ZONES . " where geo_zone_id = '" . MODULE_SHIPPING_TABLE_ZONE . "' and zone_country_id = '" . $order->delivery['country']['id'] . "' order by zone_id"); to this $check_query = tep_db_query("select zone_id, zone_country_id from " . TABLE_ZONES_TO_GEO_ZONES . " where geo_zone_id = '" . MODULE_SHIPPING_TABLE_ZONE . "' and zone_country_id = '" . $order->delivery['country']['id'] . "' order by zone_id"); and then find this code 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; } } change it to this: 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['zone_country_id'] == 223 || $check['zone_country_id'] == 38 ) $check_flag = false; and try again Link to comment Share on other sites More sharing options...
Guest Posted September 17, 2005 Share Posted September 17, 2005 same result :( Link to comment Share on other sites More sharing options...
Guest Posted September 17, 2005 Share Posted September 17, 2005 ok one last thing replace this line as well if ( ($this->enabled == true) && ((int)MODULE_SHIPPING_TABLE2_ZONE > 0) ) with this if ( ($this->enabled == true) ) watch the brackets Link to comment Share on other sites More sharing options...
Guest Posted September 18, 2005 Share Posted September 18, 2005 it seems to work, but when i tried to use a germany mailing address to check out, it gave me the u.s. rate :( Link to comment Share on other sites More sharing options...
Guest Posted September 18, 2005 Share Posted September 18, 2005 is this for the other table now? Does it work for us/ca accounts? For the other table you need to replicate what you did for table2 (table2 wasnt it?) with the exception of the countries id check. For the other table should be something like: if( $check['zone_country_id'] != 223 && $check['zone_country_id'] != 38 ) Link to comment Share on other sites More sharing options...
Guest Posted September 18, 2005 Share Posted September 18, 2005 with table.php edited, the shipping modules don't calculate or show at all (for any country). but the u.s. one worked fine (before i edited table.php) Link to comment Share on other sites More sharing options...
Guest Posted September 18, 2005 Share Posted September 18, 2005 well I assume the other shipping module "table" is identical to table2 and only the rates from the dbase are different. The new mods you did should filter out overseas accounts. Can you double-check the changes you made? Link to comment Share on other sites More sharing options...
Guest Posted September 18, 2005 Share Posted September 18, 2005 i redid the edits, but the same result. can you check my edits? maybe i keep missing something. <?php /* $Id: table.php,v 1.27 2003/02/05 22:41:52 hpdl Exp $ osCommerce, Open Source E-Commerce Solutions http://www.oscommerce.com Copyright (c) 2003 osCommerce Released under the GNU General Public License */ class table { var $code, $title, $description, $icon, $enabled; // class constructor function table() { global $order; $this->code = 'table'; $this->title = MODULE_SHIPPING_TABLE_TEXT_TITLE; $this->description = MODULE_SHIPPING_TABLE_TEXT_DESCRIPTION; $this->sort_order = MODULE_SHIPPING_TABLE_SORT_ORDER; $this->icon = ''; $this->tax_class = MODULE_SHIPPING_TABLE_TAX_CLASS; $this->enabled = ((MODULE_SHIPPING_TABLE_STATUS == 'True') ? true : false); if ( ($this->enabled == true) ) { $check_flag = false; $check_query = tep_db_query("select zone_id, zone_country_id from " . TABLE_ZONES_TO_GEO_ZONES . " where geo_zone_id = '" . MODULE_SHIPPING_TABLE_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['zone_country_id'] == 223 || $check['zone_country_id'] == 38 ) $check_flag = false; if ($check_flag == false) { $this->enabled = false; } } } // class methods function quote($method = '') { global $order, $cart, $shipping_weight, $shipping_num_boxes; if (MODULE_SHIPPING_TABLE_MODE == 'price') { $order_total = $cart->show_total(); } else { $order_total = $shipping_weight; } $table_cost = split("[:,]" , MODULE_SHIPPING_TABLE_COST); $size = sizeof($table_cost); for ($i=0, $n=$size; $i<$n; $i+=2) { if ($order_total <= $table_cost[$i]) { $shipping = $table_cost[$i+1]; break; } } if (MODULE_SHIPPING_TABLE_MODE == 'weight') { $shipping = $shipping * $shipping_num_boxes; } $this->quotes = array('id' => $this->code, 'module' => MODULE_SHIPPING_TABLE_TEXT_TITLE, 'methods' => array(array('id' => $this->code, 'title' => MODULE_SHIPPING_TABLE_TEXT_WAY, 'cost' => $shipping + MODULE_SHIPPING_TABLE_HANDLING))); 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_TABLE_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 Table Method', 'MODULE_SHIPPING_TABLE_STATUS', 'True', 'Do you want to offer table 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 Table', 'MODULE_SHIPPING_TABLE_COST', '25:8.50,50:5.50,10000:0.00', 'The shipping cost is based on the total cost or weight of items. Example: 25:8.50,50:5.50,etc.. Up to 25 charge 8.50, from there to 50 charge 5.50, etc', '6', '0', now())"); 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 ('Table Method', 'MODULE_SHIPPING_TABLE_MODE', 'weight', 'The shipping cost is based on the order total or the total weight of the items ordered.', '6', '0', 'tep_cfg_select_option(array(\'weight\', \'price\'), ', now())"); tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Handling Fee', 'MODULE_SHIPPING_TABLE_HANDLING', '0', 'Handling fee for 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_TABLE_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_TABLE_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_TABLE_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_TABLE_STATUS', 'MODULE_SHIPPING_TABLE_COST', 'MODULE_SHIPPING_TABLE_MODE', 'MODULE_SHIPPING_TABLE_HANDLING', 'MODULE_SHIPPING_TABLE_TAX_CLASS', 'MODULE_SHIPPING_TABLE_ZONE', 'MODULE_SHIPPING_TABLE_SORT_ORDER'); } } ?> Link to comment Share on other sites More sharing options...
Guest Posted September 18, 2005 Share Posted September 18, 2005 this line if( $check['zone_country_id'] == 223 || $check['zone_country_id'] == 38 ) you havent changed it as I mentioned change it to this if( $check['zone_country_id'] != 223 && $check['zone_country_id'] != 38 ) unless you posted the old table. Link to comment Share on other sites More sharing options...
Guest Posted September 18, 2005 Share Posted September 18, 2005 whoops :blush: i just edited that line in, same result Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.