shuweee Posted September 27, 2005 Posted September 27, 2005 quite frankly i'm not a coder so i'm here looking for some assistance. but logically this should be quite easy for you hard core coder out there :D this particular contribution is setup to scan for exact match of postal code, however in order for this to work for me in Canada, i'm hoping someone can tell me how to make this contribution to only scan for first 3 characters of postal code rather than looking for exact match. in Canda we use V1P2A2 and first 3 characters will identify the area they are in unlike in US it goes by numbers. Anyone's help would be greatly appreciated.. http://www.oscommerce.com/community/contri...h,Local+Deliver :thumbsup: Quote
shuweee Posted September 27, 2005 Author Posted September 27, 2005 here are the codes <?php /* $Id: dly.php,v 1.2 2004/11/18 16:29:56 ChBu Exp $ Dr. Bill Bailey, http://www.lowcarbnexus.com Zoe Lozada Almodovar, [email protected] VERY slight hack of dly.php by Dr. Bill Bailey, http://www.lowcarbnexus.com VERY slight hack of spu.php by dion made from original code by M. Halvorsen (http://www.arachnia-web.com) to allow local delivery from warehouse. Dr. Bill Bailey, http://www.lowcarbnexus.com Made to work with latest check-out procedure by Matthijs (Mattice) >> e-mail: [email protected] >> site: http://www.matthijs.org CHANGES (v1.2): - added selection of post codes (city codes) where this delivery is possible, it will not show up if the delivery is not in a selected city of the selected zone. CHANGES (v1.1): - added Minimum Total Order Value to configuration - updated code - added icon references CHANGES (v1.0): - formatted to work with latest checkout procedure - removed icon references - updated the db queries Released under the GNU General Public License */ class dly { var $code, $title, $description, $icon, $enabled; // class constructor function dly() { global $order; $this->code = 'dly'; $this->title = MODULE_SHIPPING_DLY_TEXT_TITLE; $this->description = MODULE_SHIPPING_DLY_TEXT_DESCRIPTION; $this->sort_order = MODULE_SHIPPING_DLY_SORT_ORDER; $this->icon = DIR_WS_ICONS . 'shipping_dly.gif'; // To remove icon change this line to: $this->icon = ''; $this->enabled = MODULE_SHIPPING_DLY_STATUS; // Beg Minimum Order Total required to activate module $this->min_order = MODULE_SHIPPING_DLY_MINIMUM_ORDER_TOTAL; if ( ($order->info['total']) < ($this->min_order) ) { $this->enabled = false; } // End Minimum Order Total required to activate module if ( ($this->enabled == true) && ((int)MODULE_SHIPPING_DLY_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_DLY_ZONE . "' and zone_country_id = '" . $order->delivery['country']['id'] . "' order by zone_id"); $zipcodes=split (',',MODULE_SHIPPING_DLY_ZIPCODE); while ($check = tep_db_fetch_array($check_query)) { if ($check['zone_id'] < 1) { if ((in_array($order->delivery['postcode'],$zipcodes )) or (MODULE_SHIPPING_DLY_ZIPCODE=='')) $check_flag = true; break; } elseif ($check['zone_id'] == $order->delivery['zone_id']) { if ((in_array($order->delivery['postcode'],$zipcodes )or (MODULE_SHIPPING_DLY_ZIPCODE==''))) $check_flag = true; break; } } if ($check_flag == false) { $this->enabled = false; } } } // class methods function quote($method = '') { global $order; $this->quotes = array('id' => $this->code, 'module' => MODULE_SHIPPING_DLY_TEXT_TITLE, 'methods' => array(array('id' => $this->code, 'title' => MODULE_SHIPPING_DLY_TEXT_WAY, 'cost' => MODULE_SHIPPING_DLY_COST))); 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_DLY_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, date_added) values ('Enable Local Delivery', 'MODULE_SHIPPING_DLY_STATUS', '1', 'Do you want to offer Local Delivery?', '6', '5', now())"); tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Local Delivery Cost', 'MODULE_SHIPPING_DLY_COST', '0.00', 'What is the Local Delivery cost? (The Handling fee will NOT be added.)', '6', '6', now())"); // Beg Minimum Order Total required to activate module tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Minimum Order Total', 'MODULE_SHIPPING_DLY_MINIMUM_ORDER_TOTAL', '0.00', 'What is the Minimum Order Total required for this option to be activated.', '6', '7', now())"); // End Minimum Order Total required to activate module // Begin ZipCode tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Zip codes', 'MODULE_SHIPPING_DLY_ZIPCODE', '', 'Only enable this shipping method for these zip codes. Separate with comma if several, empty if all.', '6', '7', now())"); // End ZipCode 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_DLY_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_DLY_SORT_ORDER', '3', 'Sort order of display.', '6', '0', now())"); } function remove() { $keys = ''; $keys_array = $this->keys(); for ($i=0; $i<sizeof($keys_array); $i++) { $keys .= "'" . $keys_array[$i] . "',"; } $keys = substr($keys, 0, -1); tep_db_query("delete from " . TABLE_CONFIGURATION . " where configuration_key in (" . $keys . ")"); } function keys() { return array('MODULE_SHIPPING_DLY_STATUS', 'MODULE_SHIPPING_DLY_COST', // Beg Minimum Order Total required to activate module 'MODULE_SHIPPING_DLY_MINIMUM_ORDER_TOTAL', // End Minimum Order Total required to activate module // Begin ZipCode 'MODULE_SHIPPING_DLY_ZIPCODE', // End ZipCode 'MODULE_SHIPPING_DLY_SORT_ORDER', 'MODULE_SHIPPING_DLY_ZONE'); } } ?> Quote
TeeCee-UK Posted October 1, 2005 Posted October 1, 2005 I too need to know how you only check the first 4 characters in a database entry so I can use the Local Distribution V1.1 for my website. Regards Tom Quote
wheeloftime Posted October 1, 2005 Posted October 1, 2005 quite frankly i'm not a coder so i'm here looking for some assistance. but logically this should be quite easy for you hard core coder out there :D this particular contribution is setup to scan for exact match of postal code, however in order for this to work for me in Canada, i'm hoping someone can tell me how to make this contribution to only scan for first 3 characters of postal code rather than looking for exact match. in Canda we use V1P2A2 and first 3 characters will identify the area they are in unlike in US it goes by numbers. Anyone's help would be greatly appreciated.. http://www.oscommerce.com/community/contri...h,Local+Deliver :thumbsup: Changing in_array($order->delivery['postcode'],$zipcodes ) to in_array(substr($order->delivery['postcode'],0,3),substr($zipcodes,0,3) ) should give what you want. Haven't tested this but you can quickly try this out (don't forget to backup). Quote
shuweee Posted October 14, 2005 Author Posted October 14, 2005 Changing in_array($order->delivery['postcode'],$zipcodes ) to in_array(substr($order->delivery['postcode'],0,3),substr($zipcodes,0,3) ) should give what you want. Haven't tested this but you can quickly try this out (don't forget to backup). hey wolf, thanks so much for helping, however i tried replacing the code and it didnt work.. if its not too much hassle, could you pm me ur email and iw ill send u the file i have and see if u can find out where and why its not working.. Thanks Changing in_array($order->delivery['postcode'],$zipcodes ) to in_array(substr($order->delivery['postcode'],0,3),substr($zipcodes,0,3) ) should give what you want. Haven't tested this but you can quickly try this out (don't forget to backup). Wolf, here ar ethe codes, i tried changing the matching line however theres 2, when i changed the first matching part, it really didnt do anything, the option isnt enable when i go through the shipping option and if i change the section part, it gives me some sort of datatype error here are the codes if ( ($this->enabled == true) && ((int)MODULE_SHIPPING_DLY_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_$ $zipcodes=split (',',MODULE_SHIPPING_DLY_ZIPCODE); while ($check = tep_db_fetch_array($check_query)) { if ($check['zone_id'] < 1) { if ((in_array($order->delivery['postcode'],$zipcodes )) or (MODULE_SHIPPING_DLY_ZIPCODE=='')) $check_flag = true; break; } elseif ($check['zone_id'] == $order->delivery['zone_id']) { if ((in_array($order->delivery['postcode'],$zipcodes )or (MODULE_SHIPPING_DLY_ZIPCODE==''))) $check_flag = true; break; } } if ($check_flag == false) { $this->enabled = false; } } } Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.