moonflower Posted March 10, 2006 Posted March 10, 2006 hello, we have developed a new shipping module named Kiala (find it here). It will be used on the Belgian market. It contains the following bug: You will get up to 5 shipping options of which you can select one (through a radio button). But whatever option you select, osC will always take the first option in the list and write this into the mySql database. does someone have an idea? could somebody have a look at it? please note * I am not experienced in php * the shipping mdoule is not written according to the osC standards !! (because I know too little of it yet) thanks in advance Quote
moonflower Posted March 17, 2006 Author Posted March 17, 2006 For your ease of use, I post here the code of the Kiala shipping module: Please note it is not written according to the osC standards (my apologies!!) Thanks <? /* $Id: kiala.php,v 1.40 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 kiala { var $code, $title, $description, $icon, $enabled; // class constructor function kiala() { global $order; $this->code = 'kiala'; $this->title = MODULE_SHIPPING_KIALA_TEXT_TITLE; $this->description = MODULE_SHIPPING_KIALA_TEXT_DESCRIPTION; $this->sort_order = MODULE_SHIPPING_KIALA_SORT_ORDER; $this->icon = DIR_WS_ICONS . 'shipping_kiala.gif'; $this->icontitle = MODULE_SHIPPING_KIALA_TEXT_ICONTITLE; $this->tax_class = MODULE_SHIPPING_KIALA_TAX_CLASS; $this->enabled = ((MODULE_SHIPPING_KIALA_STATUS == 'True') ? true : false); if ( ($this->enabled == true) && ((int)MODULE_SHIPPING_KIALA_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_KIALA_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, $language, $cart, $shipping_weight, $shipping_num_boxes; // $language om de taal van de Kiala-site te geven (NL of FR) $check_weight = (($shipping_weight*$shipping_num_boxes) > MODULE_SHIPPING_KIALA_WEIGHT_MAX); $check_amount = ($cart->show_total() < MODULE_SHIPPING_KIALA_AMOUNT); $check_display_weight = (MODULE_SHIPPING_KIALA_DISPLAY_WEIGHT == 'False'); $check_display_amount = (MODULE_SHIPPING_KIALA_DISPLAY_AMOUNT == 'False'); // If shipping weight exceeded and order amount too low if ($check_weight && $check_amount) { if ($check_display_weight && $check_display_amount) { return; } elseif ($check_display_weight) { $errormessage = MODULE_SHIPPING_KIALA_TEXT_ERROR_AMOUNT; } elseif ($check_display_amount) { $errormessage = MODULE_SHIPPING_KIALA_TEXT_ERROR_WEIGHT; } else { $errormessage = MODULE_SHIPPING_KIALA_TEXT_ERROR_WEIGHT . "<br>" . MODULE_SHIPPING_KIALA_TEXT_ERROR_AMOUNT; } $this->quotes = array('module' => $this->title, 'error' => $errormessage ); // If shipping weight is exceeded } elseif ($check_weight) { if ($check_display_weight) return; else $errormessage = MODULE_SHIPPING_KIALA_TEXT_ERROR_WEIGHT; $this->quotes = array('module' => $this->title, 'error' => $errormessage ); // If min. order amount is not purchased } elseif ($check_amount) { if ($check_display_amount) return; else $errormessage = MODULE_SHIPPING_KIALA_TEXT_ERROR_AMOUNT; //else $this->quotes['error'] = MODULE_SHIPPING_KIALA_TEXT_ERROR_AMOUNT; //else $this->quotes = array('module' => $this->title, 'error' => MODULE_SHIPPING_KIALA_TEXT_ERROR_AMOUNT); $this->quotes = array('module' => $this->title, 'error' => $errormessage ); // Else show Kiala module: } else { $this->quotes = array('id' => $this->code, 'module' => $this->title ); $methods = array(); $query_selectzip = "SELECT * FROM " . TABLE_KIALA_BELUX_ZIPKPLIST . " WHERE zip='" . $order->delivery['postcode'] . "' AND country='" . $order->delivery['country']['iso_code_2'] . "' ORDER BY suggestion_order"; // SORT BY? $result_selectzip = mysql_query($query_selectzip); // Controleer of de seleczip-query gelukt is: if (!$result_selectzip = mysql_query($query_selectzip)) { // Het uitvoeren van de selectzip-query is mislukt. // We don't use tep_db_query because we need a custom error instead of the osC error // Toon text dat de module niet beschikbaar is: $this->quotes = array('module' => $this->title, 'error' => MODULE_SHIPPING_KIALA_TEXT_NOT_AVAILABLE ); } else { // Het uitvoeren van de selectzip-query is gelukt. // Controleer of de resultaten er zijn: if (mysql_num_rows($result_selectzip)>0) { // Er is resultaat voor de selectzip-query gevonden. // Controleer de beschikbaarheid van alle Kialapunten: $teller = 0; while (list($id, $line_type, $zip, $country, $kp_id, $suggestion_order, $distance) = mysql_fetch_row($result_selectzip)) { $query_countkpdetails = "SELECT * FROM " . TABLE_KIALA_BELUX_KPLIST . " WHERE kp_id='" . $kp_id . "' AND ( kp_activities_start_date<NOW() AND ( kp_activities_end_date='0000-00-00' OR kp_activities_end_date>NOW() ) ) AND ( last_delivery_date='0000-00-00' OR last_delivery_date>(DATE_ADD(NOW(), INTERVAL " . (MODULE_SHIPPING_KIALA_PREPARATION_DURATION + MODULE_SHIPPING_KIALA_TRANSPORT_DURATION) . " DAY)) OR ( first_delivery_date!='0000-00-00' AND first_delivery_date<(DATE_ADD(NOW(), INTERVAL " . (MODULE_SHIPPING_KIALA_PREPARATION_DURATION + MODULE_SHIPPING_KIALA_TRANSPORT_DURATION). " DAY)) ) ) AND ( temporary_closure_start_date='0000-00-00' OR temporary_closure_start_date>(DATE_ADD(NOW(), INTERVAL " . (MODULE_SHIPPING_KIALA_PREPARATION_DURATION + MODULE_SHIPPING_KIALA_TRANSPORT_DURATION + MODULE_SHIPPING_KIALA_GUARANTEED_DURATION) . " DAY))) "; $result_countkpdetails = mysql_query($query_countkpdetails); // Controleer of de countkpdetails-query gelukt is: if (!$result_countkpdetails = mysql_query($query_countkpdetails)) { // Het uitvoeren van de countkpdetails-query is mislukt. // We don't use tep_db_query because we need a custom error instead of the osC error // Toon text dat de module niet beschikbaar is: $this->quotes = array('module' => $this->title, 'error' => MODULE_SHIPPING_KIALA_TEXT_NOT_AVAILABLE ); } else { // Het uitvoeren van de countkpdetails-query is gelukt. // Controleer of de resultaten er zijn: // if ($result_countkpdetails['total']>0) if (mysql_num_rows($result_countkpdetails)>0) { // Er is resultaat voor de selectzip-query gevonden. // Verhoog de teller: $teller++; } } // End If Controleer of de countkpdetails-query gelukt is } // End While Controleer de beschikbaarheid van alle Kialapunten //echo "EINDTELLER = " .$teller; if ($teller>0) { // Er zijn beschikbare Kialapunten gevonden. // Query opnieuw uitvoeren: $query_selectzip = "SELECT * FROM " . TABLE_KIALA_BELUX_ZIPKPLIST . " WHERE zip='" . $order->delivery['postcode'] . "' AND country='" . $order->delivery['country']['iso_code_2'] . "' ORDER BY suggestion_order"; // SORT BY? $result_selectzip = mysql_query($query_selectzip); // Haal nu de rijen op (van alle Kialapunten): while (list($id, $line_type, $zip, $country, $kp_id, $suggestion_order, $distance) = mysql_fetch_row($result_selectzip)) { $query_getkpdetails = "SELECT * FROM " . TABLE_KIALA_BELUX_KPLIST . " WHERE kp_id='" . $kp_id . "' AND ( kp_activities_start_date<NOW() AND ( kp_activities_end_date='0000-00-00' OR kp_activities_end_date>NOW() ) ) AND ( last_delivery_date='0000-00-00' OR last_delivery_date>(DATE_ADD(NOW(), INTERVAL " . (MODULE_SHIPPING_KIALA_PREPARATION_DURATION + MODULE_SHIPPING_KIALA_TRANSPORT_DURATION) . " DAY)) OR ( first_delivery_date!='0000-00-00' AND first_delivery_date<(DATE_ADD(NOW(), INTERVAL " . (MODULE_SHIPPING_KIALA_PREPARATION_DURATION + MODULE_SHIPPING_KIALA_TRANSPORT_DURATION). " DAY)) ) ) AND ( temporary_closure_start_date='0000-00-00' OR temporary_closure_start_date>(DATE_ADD(NOW(), INTERVAL " . (MODULE_SHIPPING_KIALA_PREPARATION_DURATION + MODULE_SHIPPING_KIALA_TRANSPORT_DURATION + MODULE_SHIPPING_KIALA_GUARANTEED_DURATION) . " DAY))) "; $result_getkpdetails = mysql_query($query_getkpdetails); // We don't use tep_db_query because we need a custom error instead of the osC error // Haal nu de rijen op (van de detailgegevens van de Kialapunten): while (list($id, $line_type, $kp_id, $address_language_1, $kp_name_1, $extra_address_line_1, $street_1, $street_nr_1, $locality_1, $city_1, $province_or_region_1, $location_hint_1, $address_language_2, $kp_name_2, $extra_address_line_2, $street_2, $street_nr_2, $locality_2, $city_2, $province_or_region_2, $location_hint_2, $zip) = mysql_fetch_row($result_getkpdetails)) { // Selecteer de juiste taalvelden op basis van de gekozen taal // Als taal frans is, toon dan alle velden met suffix _1, // anders (= als taal nederlands of engels of een andere taal is) // toon alle velden met suffix_2 if ($language == "francais") { $kp_name = $kp_name_1; $street = $street_1; $street_nr = $street_nr_1; $city = $city_1; $langcode = "FR"; } else { $kp_name = $kp_name_2; $street = $street_2; $street_nr = $street_nr_2; $city = $city_2; $langcode = "NL"; } // Stel de lijst met de Kialapunten samen: $methods[] = array('id' => $type, 'title' => $kp_name . " (KP" . $kp_id . ") [<a href='javascript:kiala_shop(\"" . $langcode . "\"," . $kp_id . ")'>" . MODULE_SHIPPING_KIALA_TEXT_MOREINFO . "</a>]<br>$street $street_nr<br>$zip ".strtoupper($city), //$this->types[$type], 'cost' => MODULE_SHIPPING_KIALA_COST); } // End While Haal de rijen van de detailgegevens van de Kialapunten op $this->quotes['methods'] = $methods; if ($this->tax_class > 0) { $this->quotes['tax'] = tep_get_tax_rate($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']); } } } else { // Er zijn geen beschikbare Kialapunten gevonden. // Toon text dat er geen Kialapunten gevonden zijn: $this->quotes = array('module' => $this->title, 'error' => MODULE_SHIPPING_KIALA_TEXT_NO_MATCH ); } // End If teller } else { // Er is geen resultaat gevonden voor de selectzip-query. // Toon text dat postcode waarschijnlijk niet gevonden is: $this->quotes = array('module' => $this->title, 'error' => MODULE_SHIPPING_KIALA_TEXT_WRONG_ZIP ); } // End IF Controleer of er resulaten zijn van de selectzip-query } // End If Controleer of de selectzip-query gelukt is } // End show Kiala module // Maak een link van de image naar een informatiepagina if (tep_not_null($this->icon)) { $this->quotes['icon'] = '<a href="javascript:kiala_info()">' . tep_image($this->icon, $this->icontitle) . '</a>'; $this->quotes['icon'] .= '??<a href="javascript:kiala_info()">' . tep_image_button('button_kiala_info.gif', IMAGE_BUTTON_KIALA_INFO) . '</a>'; $this->quotes['icon'] .= '??<a href="' . tep_href_link(FILENAME_CHECKOUT_SHIPPING_ADDRESS, '', 'SSL') . '">' . tep_image_button('button_kiala_zip.gif', IMAGE_BUTTON_KIALA_ZIP) . '</a>'; } return $this->quotes; } // End function quote() function check() { if (!isset($this->_check)) { $check_query = tep_db_query("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_SHIPPING_KIALA_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 shipping via Kiala', 'MODULE_SHIPPING_KIALA_STATUS', 'True', 'Do you want to offer shipping via Kiala?', '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 ('Maximum Weight', 'MODULE_SHIPPING_KIALA_WEIGHT_MAX', '10', 'What is the maximum weight you will ship?', '6', '8', 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 ('Display Text for Maximum Weight', 'MODULE_SHIPPING_KIALA_DISPLAY_WEIGHT', 'True', 'Do you want to display text if the maximum weight is exceeded?', '6', '7', '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_KIALA_COST', '1.10', '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, date_added) values ('Minimum Order Amount', 'MODULE_SHIPPING_KIALA_AMOUNT', '50.00', 'Minimum order amount purchased before enabling this shipping method?', '6', '8', 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 ('Display Text for Minimum Order Amount', 'MODULE_SHIPPING_KIALA_DISPLAY_AMOUNT', 'True', 'Do you want to display text if the minimum amount is not reached?', '6', '7', '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 ('Preparation Duration', 'MODULE_SHIPPING_KIALA_PREPARATION_DURATION', '2', 'Days of preparation at the DSP.', '6', '0', now())"); tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Transport Duration', 'MODULE_SHIPPING_KIALA_TRANSPORT_DURATION', '3', 'Days of transportation to the KP.', '6', '0', now())"); tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Guaranteed Duration At KP', 'MODULE_SHIPPING_KIALA_GUARANTEED_DURATION', '14', 'Guaranteed duration at KP in days.', '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_KIALA_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_KIALA_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_KIALA_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_KIALA_STATUS', 'MODULE_SHIPPING_KIALA_WEIGHT_MAX', 'MODULE_SHIPPING_KIALA_DISPLAY_WEIGHT', 'MODULE_SHIPPING_KIALA_COST', 'MODULE_SHIPPING_KIALA_AMOUNT', 'MODULE_SHIPPING_KIALA_DISPLAY_AMOUNT', 'MODULE_SHIPPING_KIALA_PREPARATION_DURATION', 'MODULE_SHIPPING_KIALA_TRANSPORT_DURATION', 'MODULE_SHIPPING_KIALA_GUARANTEED_DURATION', 'MODULE_SHIPPING_KIALA_TAX_CLASS', 'MODULE_SHIPPING_KIALA_ZONE', 'MODULE_SHIPPING_KIALA_SORT_ORDER'); } } ?> Quote
moonflower Posted March 17, 2006 Author Posted March 17, 2006 This is what I found in the meantime: 1. I select a shipping option on the checkout_shipping page 2. I continue to the checkout_payment page 3. I continue to the checkout_confirmation page => Here always the first option of the Kiala shipping module is shown and this option is written to the MySql database 4. However, when I return to the checkout_shipping page, the radion button of my original choice is selected I thinks it has something to do with the array that contains the different options. I experimented somewhat with the UPS shipping module: it will collect data from www.ups.com but when I enter an array hardcoded in modules/shipping/ups.php, then I get the same behaviour as our Kiala shipping module: whatever option you select, always the first option is taken. Actually I do not know how the data array must be defined or must look like. I will try to find out... Thanks a lot for your help Quote
Guest Posted March 23, 2006 Posted March 23, 2006 its because your $type variable is not initialized/set. 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.