Guest Posted March 17, 2008 Posted March 17, 2008 Background note first. I am using MVS to distinguish between products that I can send by post to virtually anywhere and those which I can only deliver locally or have collected from my premises. I have tried to modify the local delivery module dly.php file for use with the MVS 1.1. This was partially successful, but has a couple of complications I need help sorting. I mention both problems as they may be inter-related. Sadly I am not a programmer and this is now beyond my guessing ability! When I go to the checkout_shuipping page it always includes the local delivery option in the possible shipping methods no matter whether the postcode is in the list of postcodes I have entered in the admin section or not which means I can end up offering local delivery to another continent! The second is that when I try to remove the module in the admin section I get the following error: Warning: Missing argument 1 for keys() in /vhost/vhost6/d/e/m/demiati.es/www/includes/modules/vendors_shipping/dly.php on line 255 Warning: Cannot modify header information - headers already sent by (output started at /vhost/vhost6/d/e/m/demiati.es/www/includes/modules/vendors_shipping/dly.php:255) in /vhost/vhost6/d/e/m/demiati.es/www/admin/includes/functions/general.php on line 22 These errors mean very little to me, so I'm a bit stuck. I would love to get the module working correctly, but the most important for me are not the removal errors as I don't intend to remove it, but I need to determine how to make the inclusion of the shipping method into the checkout_shipping page conditional upon the delivery postcode. The dly.php file I have modified is as below. I have tried to enter comments where I have changed an otherwise working module. <?php /* $Id: dly.php,v 1.6 2006/06/23 11:00:00 WoT Exp $ Dr. Bill Bailey, [url="http://www.lowcarbnexus.com"]http://www.lowcarbnexus.com[/url] Zoe Lozada Almodovar, [email protected] VERY slight hack of dly.php by Dr. Bill Bailey, [url="http://www.lowcarbnexus.com"]http://www.lowcarbnexus.com[/url] 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, [url="http://www.lowcarbnexus.com"]http://www.lowcarbnexus.com[/url] Made to work with latest check-out procedure by Matthijs (Mattice) >> e-mail: [email protected] >> site: [url="http://www.matthijs.org"]http://www.matthijs.org[/url] CHANGES (v1.6) (wheeloftime): - added code for different delivery costs depending on weight or price. CHANGES (v1.5): - added code to enter maximum distance you will travel for local deliveries. CHANGES (v1.4): - added code to convert admin supplied postal codes to upper case. - added code to remove spaces from both admin & user supplied postal codes while comparing them. CHANGES (v1.3): - added code to convert user supplied postal codes to upper case. 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->icon = 'pixel_trans.gif'; // To remove icon change to: $this->icon = 'pixel_trans.gif'; /* This section has been commented out from the DLY module as per Modules.txt Modifying Shipping Modules for Multi-Vendor Shipping, v 0.9rc3 2005/03/22 by Craig Garrison Sr and Jim Keebaugh $this->tax_class = MODULE_SHIPPING_DLY_TAX_CLASS; $this->sort_order = MODULE_SHIPPING_DLY_SORT_ORDER; $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); $zip_up = MODULE_SHIPPING_DLY_ZIPCODE; $zip_up = strtoupper($zip_up); $zip_up = str_replace (' ', '', $zip_up); $zipcodes = split (',', $zip_up); $order->delivery['postcode'] = strtoupper($order->delivery['postcode']); $order->delivery['postcode'] = str_replace (' ', '', $order->delivery['postcode']); 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; } }*/ /* Start of new section to comply with MVS 1.1 as per Module.txt Modifying Shipping Modules for Multi-Vendor Shipping, v 0.9rc3 2005/03/22 by Craig Garrison Sr and Jim Keebaugh */ } function sort_order($vendors_id='1') { if (defined (@constant ('MODULE_SHIPPING_DLY_SORT_ORDER_' . $vendors_id))) { $this->sort_order = @constant('MODULE_SHIPPING_DLY_SORT_ORDER_' . $vendors_id); } else { $this->sort_order = '0'; } return $this->sort_order; } function tax_class($vendors_id='1') { $this->tax_class = constant('MODULE_SHIPPING_DLY_TAX_CLASS_' . $vendors_id); return $this->tax_class; } // Added next 4 lines to replace "$this->min_order = MODULE_SHIPPING_DLY_MINIMUM_ORDER_TOTAL;" from unmodified dly.php - The Minimum Order Total required to activate module function min_order($vendors_id='1') { // added line $this->min_order = constant('MODULE_SHIPPING_DLY_MINIMUM_ORDER_TOTAL_' . $vendors_id); // added line return $this->min_order; // added line } // added line function enabled($vendors_id='1') { $this->enabled = false; $status = @constant('MODULE_SHIPPING_DLY_STATUS_' . $vendors_id); if (isset ($status) && $status != '') { $this->enabled = (($status == 'True') ? true : false); } return $this->enabled; } function zones($vendors_id='1') { if ( ($this->enabled == true) && ((int)constant('MODULE_SHIPPING_DLY_ZONE_' . $vendors_id) > 0) ) { $check_flag = false; $check_query = tep_db_query("select zone_id from " . TABLE_ZONES_TO_GEO_ZONES . " where geo_zone_id = '" . (int)constant('MODULE_SHIPPING_DLY_ZONE_' . $vendors_id) . "' and zone_country_id = '" . $order->delivery['country']['id'] . "' order by zone_id"); // The Following 7 lines were copied from the dly.php module I think they //$zipcodes = split (',', MODULE_SHIPPING_DLY_ZIPCODE); // added line $zip_up = MODULE_SHIPPING_DLY_ZIPCODE; // added line $zip_up = strtoupper($zip_up); // added line $zip_up = str_replace (' ', '', $zip_up); // added line $zipcodes = split (',', $zip_up); // added line $order->delivery['postcode'] = strtoupper($order->delivery['postcode']); // added line $order->delivery['postcode'] = str_replace (' ', '', $order->delivery['postcode']); // added line while ($check = tep_db_fetch_array($check_query)) { if ($check['zone_id'] < 1) { // Copied next 1 line from unmodified dly.php as the inclusion into checkout_shipping not taking any notice of delivery postcode if ((in_array($order->delivery['postcode'], $zipcodes) or (MODULE_SHIPPING_DLY_ZIPCODE == ''))) // added line $check_flag = true; break; } elseif ($check['zone_id'] == $order->delivery['zone_id']) { // Copied next 1 line from unmodified dly.php as the inclusion into checkout_shipping not taking any notice of delivery postcode if ((in_array($order->delivery['postcode'], $zipcodes) or (MODULE_SHIPPING_DLY_ZIPCODE == ''))) // added line $check_flag = true; break; } //if }//while if ($check_flag == false) { $this->enabled = false; }//if }//if return $this->enabled; }//function // class methods function quote($method = '', $module = '', $vendors_id = '1') { global $order, $cart, $shipping_weight, $shipping_num_boxes; if (constant('MODULE_SHIPPING_DLY_MODE_' . $vendors_id) == 'price') { $order_total = $cart->show_total(); } else { $order_total = $shipping_weight; } $table_cost = split("[:,]" , MODULE_SHIPPING_DLY_COST); $shipping_rate = 0; $size = sizeof($table_cost); for ($i=0, $n=$size; $i<$n; $i+=2) { if ($order_total <= $table_cost[$i]) { $shipping_rate = $table_cost[$i+1]; break; } } if (constant('MODULE_SHIPPING_DLY_MODE_' . $vendors_id) == 'weight') { $shipping_rate = $shipping_rate * $shipping_num_boxes; } $vendors_data_query = tep_db_query("select handling_charge, handling_per_box, vendor_country from " . TABLE_VENDORS . " where vendors_id = '" . (int)$vendors_id . "'" ); $vendors_data = tep_db_fetch_array($vendors_data_query); $country_name = tep_get_countries($vendors_data['vendor_country'], true); $handling_charge = $vendors_data['handling_charge']; $handling_per_box = $vendors_data['handling_per_box']; if ($handling_charge > $handling_per_box*$shipping_num_boxes) { $handling = $handling_charge; } else { $handling = $handling_per_box*$shipping_num_boxes; } $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' => $shipping_rate + $handling))); //if (tep_not_null($this->icon)) $this->quotes['icon'] = tep_image($this->icon, $this->title); if ($this->tax_class > 0) { $this->quotes['tax'] = tep_get_tax_rate($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']); } return $this->quotes; } function check($vendors_id='1') { if (!isset($this->_check)) { $check_query = tep_db_query("select configuration_value from " . TABLE_VENDOR_CONFIGURATION . " where vendors_id = '". $vendors_id ."' and configuration_key = 'MODULE_SHIPPING_DLY_STATUS_" . $vendors_id . "'"); $this->_check = tep_db_num_rows($check_query); } return $this->_check; } function install($vendors_id='1') { tep_db_query("insert into " . TABLE_VENDOR_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added, vendors_id) values ('Enable Local Delivery', 'MODULE_SHIPPING_DLY_STATUS_" . $vendors_id . "' , 'True', 'Do you want to offer Local Delivery?', '6', '2', 'tep_cfg_select_option(array(\'True\', \'False\'), ', now(), '" . $vendors_id . "')"); // BOF Determine if costs table is based on price or weight tep_db_query("insert into " . TABLE_VENDOR_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added, vendors_id) values ('Delivery Cost Method', 'MODULE_SHIPPING_DLY_MODE_" . $vendors_id . "', 'weight', 'The delivery cost is based on the order total or the total weight of the items ordered.', '6', '2', 'tep_cfg_select_option(array(\'weight\', \'price\'), ', now(), '" . $vendors_id . "')"); // EOF Determine if costs table is based on price or weight tep_db_query("insert into " . TABLE_VENDOR_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added, vendors_id) values ('Local Delivery Cost', 'MODULE_SHIPPING_DLY_COST_" . $vendors_id . "', '25:8.50,50:5.50,10000:0.00', 'The delivery 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. Be aware: The Handling fee will NOT be added.', '6', '4', now(), '" . $vendors_id . "')"); tep_db_query("insert into " . TABLE_VENDOR_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, use_function, set_function, date_added, vendors_id) values ('Tax Class', 'MODULE_SHIPPING_DLY_TAX_CLASS_" . $vendors_id . "', '0', 'Use the following Tax Class on the Shipping Fee.', '6', '6', 'tep_get_tax_class_title', 'tep_cfg_pull_down_tax_classes(', now(), '" . $vendors_id . "')"); // Beg Minimum Order Total required to activate module tep_db_query("insert into " . TABLE_VENDOR_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added, vendors_id) values ('Minimum Order Total', 'MODULE_SHIPPING_DLY_MINIMUM_ORDER_TOTAL_" . $vendors_id . "', '0.00', 'What is the Minimum Order Total required for this option to be activated.', '6', '8', now(), '" . $vendors_id . "')"); // End Minimum Order Total required to activate module tep_db_query("insert into " . TABLE_VENDOR_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added, vendors_id) values ('Maximum Local Delivery Distance', 'MODULE_SHIPPING_DLY_MAX_LOCAL_DISTANCE_" . $vendors_id . "', '12 Km', 'What is the Maximum Local delivery distance which you will travel to deliver orders. [ ie. 12 Km ]', '6', '10', now(), '" . $vendors_id . "')"); // Begin ZipCode tep_db_query("insert into " . TABLE_VENDOR_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added, vendors_id) values ('Zip codes', 'MODULE_SHIPPING_DLY_ZIPCODE_" . $vendors_id . "', '', 'Only enable this shipping method for these ZIP / Post Codes. Separate with comma if several, empty if all. Postal Codes including letters must be in capital letters.', '6', '12', now(), '" . $vendors_id . "')"); // End ZipCode tep_db_query("insert into " . TABLE_VENDOR_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, use_function, set_function, date_added, vendors_id) values ('Shipping Zone', 'MODULE_SHIPPING_DLY_ZONE_" . $vendors_id . "', '0', 'If a zone is selected, only enable this shipping method for that zone.', '6', '14', 'tep_get_zone_class_title', 'tep_cfg_pull_down_zone_classes(', now(), '" . $vendors_id . "')"); tep_db_query("insert into " . TABLE_VENDOR_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added, vendors_id) values ('Sort Order', 'MODULE_SHIPPING_DLY_SORT_ORDER_" . $vendors_id . "', '10', 'Sort order of display.', '6', '16', now(), '" . $vendors_id . "')"); } function remove($vendors_id) { tep_db_query("delete from " . TABLE_VENDOR_CONFIGURATION . " where configuration_key in ('" . implode("', '", $this->keys()) . "')"); } function keys($vendors_id) { return array('MODULE_SHIPPING_DLY_STATUS_' . $vendors_id, // Begin costs method 'MODULE_SHIPPING_DLY_MODE_' . $vendors_id, // End cost method 'MODULE_SHIPPING_DLY_COST_' . $vendors_id, 'MODULE_SHIPPING_DLY_TAX_CLASS_' . $vendors_id, // Beg Minimum Order Total required to activate module 'MODULE_SHIPPING_DLY_MINIMUM_ORDER_TOTAL_' . $vendors_id, // End Minimum Order Total required to activate module 'MODULE_SHIPPING_DLY_MAX_LOCAL_DISTANCE_' . $vendors_id, // Begin ZipCode 'MODULE_SHIPPING_DLY_ZIPCODE_' . $vendors_id, // End ZipCode 'MODULE_SHIPPING_DLY_SORT_ORDER_' . $vendors_id, 'MODULE_SHIPPING_DLY_ZONE_' . $vendors_id); } } ?> If there is anyone out there who can help me they would make a now slightly demoralised, technically challenged fool very happy. Here's hoping and thank you for taking the time to get this far! Quote
♥kymation Posted March 22, 2008 Posted March 22, 2008 The easy fix first: Replace line 252 of the above file with this: tep_db_query("delete from " . TABLE_VENDOR_CONFIGURATION . " where configuration_key in ('" . implode("', '", $this->keys($vendors_id)) . "')"); That will fix the error message you are getting. For the postcode error, you need to replace MODULE_SHIPPING_DLY_ZIPCODE with constant('MODULE_SHIPPING_DLY_ZIPCODE_' . $vendors_id) on lines 140, 150, and 155. That's all I can see right now. If there are more bugs you can't figure out, post them here or in the MVS thread. Regards Jim Quote See my profile for a list of my addons and ways to get support.
Guest Posted March 22, 2008 Posted March 22, 2008 The easy fix first: Replace line 252 of the above file with this:tep_db_query("delete from " . TABLE_VENDOR_CONFIGURATION . " where configuration_key in ('" . implode("', '", $this->keys($vendors_id)) . "')"); That will fix the error message you are getting. For the postcode error, you need to replace MODULE_SHIPPING_DLY_ZIPCODE with constant('MODULE_SHIPPING_DLY_ZIPCODE_' . $vendors_id) on lines 140, 150, and 155. That's all I can see right now. If there are more bugs you can't figure out, post them here or in the MVS thread. Regards Jim Thank you for the very fast response. I have made the relevant corrections and my error messages have dissappeared. Unfortunately the module still takes no notice of the postcodes which are entered in the admin section and includes the module for any postcode. If you have any ideas I'd love to hear them. Thanks Carl Quote
Guest Posted March 22, 2008 Posted March 22, 2008 Thank you for the very fast response. I have made the relevant corrections and my error messages have dissappeared. Unfortunately the module still takes no notice of the postcodes which are entered in the admin section and includes the module for any postcode. If you have any ideas I'd love to hear them. Thanks Carl As an update to the above, I have noticed the price of the shipping using the Local Delivery Module is being taken from the table which is in the dly module outside of MVS, i.e. the one that is used when use vendor shipping is set to false. I don't know if this has any relevance. Thanks Carl Quote
♥kymation Posted March 22, 2008 Posted March 22, 2008 Again, the easy one first -- Replace line 179 with this code: $table_cost = split("[:,]" , constant('MODULE_SHIPPING_DLY_COST' . $vendors_id)); You will also need to replace Lines 174 - 176 with the following: $order_total = $cart->vendor_shipping[$vendors_id]['cost']; } else { $order_total = $cart->vendor_shipping[$vendors_id]['weight']; I'm also having some problems with what appears to be the original code. For function zones($vendors_id='1') { to work as intended, it needs to have global $order; added just after that line (Line 132.) I don't see how this worked without that line. Try those changes and see what happens. Regards Jim Quote See my profile for a list of my addons and ways to get support.
Guest Posted March 24, 2008 Posted March 24, 2008 My Error; I have reversed the changes I made and re-edited the code and corrected the errors I had coming up. The module still takes no notice of which post code is in the delivery address. If you have any ideas I 'd love to hear them. Thanks Carl Quote
♥kymation Posted March 28, 2008 Posted March 28, 2008 I've managed to get this working. It's a bit of a hack, but I just haven't got the time (or the energy) to do it properly. In dly.php, find this code (line 123 ff) function enabled($vendors_id='1') { $this->enabled = false; $status = @constant('MODULE_SHIPPING_DLY_STATUS_' . $vendors_id); if (isset ($status) && $status != '') { $this->enabled = (($status == 'True') ? true : false); and add this line after it: $this->enabled = $this->zones ($vendors_id); It's ugly but it works. On my system anyway; I give no guarantees of other operating systems, versions of PHP and MySQL, etc. There are a couple of persistent oddities left over from the original code. You will need to specify a zone in addition to postcode(s). This should not be necessary, and could be fixed with a bit of coding, but my brain is just refusing to work right now. I don't see this as being a problem in any case. Also, the Maximum Local Delivery Distance does absolutely nothing. Making this work would require something like a driving distance query to Google Maps. It could probably be done, but I question the usefulness compared to the amount of time required to code it. Maybe if I get extremely bored some day. Don't hold your breath. Regards Jim Quote See my profile for a list of my addons and ways to get support.
Guest Posted March 29, 2008 Posted March 29, 2008 I've managed to get this working. It's a bit of a hack, but I just haven't got the time (or the energy) to do it properly. In dly.php, find this code (line 123 ff)function enabled($vendors_id='1') { $this->enabled = false; $status = @constant('MODULE_SHIPPING_DLY_STATUS_' . $vendors_id); if (isset ($status) && $status != '') { $this->enabled = (($status == 'True') ? true : false); and add this line after it: $this->enabled = $this->zones ($vendors_id); It's ugly but it works. On my system anyway; I give no guarantees of other operating systems, versions of PHP and MySQL, etc. There are a couple of persistent oddities left over from the original code. You will need to specify a zone in addition to postcode(s). This should not be necessary, and could be fixed with a bit of coding, but my brain is just refusing to work right now. I don't see this as being a problem in any case. Also, the Maximum Local Delivery Distance does absolutely nothing. Making this work would require something like a driving distance query to Google Maps. It could probably be done, but I question the usefulness compared to the amount of time required to code it. Maybe if I get extremely bored some day. Don't hold your breath. Regards Jim Hi Jim, I think you have saved my life; at least my wife isn't going to kill me now. That trick seems to have worked perfectly; THANK YOU. I now have to learn a bit more about zones to get it working as I want, but you have been phenomenally helpful. You asked me before to post the module as a contribution when it was fixed. This is not something I am confident doing as I don't know how best to tidy it up without breaking it, but I will try. Kind Regards Carl 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.