* @package icirelais_shipping_mode * @copyright Bysoft 2010 * */ class icirelais_get_point { /** * The configuration key list for ICI Relais shipping mode saved in database * @access protected * @var string array of string values */ var $_configuration_key = array(); /** * @var string the customer's address */ var $address; /** * @var integer the customer's zipcode */ var $zipcode; /** * @var string the customer's city */ var $city; /** * @var string the closing period list in string format */ var $str_closing_period; /** * @var string ICI Relay's id * @access protected */ var $shipping_methode_code; //-------------------------------------------------------------------------------------------------------------- // CONSTRUCTEUR //-------------------------------------------------------------------------------------------------------------- /** * Initialize datas from database * - get configuration keys for ICI Relais shipping mode * - get the customer's address * * @param array contain the customer's id */ function icirelais_get_point($input){ // Get ICI relais configuration key from database $query = "SELECT configuration_key, configuration_value FROM configuration WHERE configuration_key LIKE 'MODULE_SHIPPING_ICIRELAIS_%'"; $get_configuration_value = tep_db_query($query); while($row = tep_db_fetch_array($get_configuration_value)){ $this->_configuration_key[$row['configuration_key']] = $row['configuration_value']; } // Get the customer's address $query = "SELECT entry_street_address, entry_postcode, entry_city FROM address_book WHERE customers_id =".$input['customer_id']; if(strlen($input['sendto']) > 0 && intval($input['sendto'])) { $query .= " AND address_book_id=".$input['sendto']; } $get_customer_address = tep_db_query($query); while($row = tep_db_fetch_array($get_customer_address)){ $this->address = $row['entry_street_address']; $this->zipcode = trim($row['entry_postcode']); $this->city = $row['entry_city']; } $this->shipping_methode_code = $input['shipping_methode_code']; require_once('includes/languages/'.$input['language'].'/modules/shipping/icirelais.php'); } //-------------------------------------------------------------------------------------------------------------- // GET ICI RELAIS POINT FROM MYPUDO OR BACKUP (DATABASE) //-------------------------------------------------------------------------------------------------------------- /** * Get the 10 nearer ici relais point from the customer's address * by the webservice MyPudo or by the database backup if the webservice is unvalable * * @return array contain the structure of the ici relais list for the front office */ function get_point(){ // Array returned with all ICI Relais points. To be complete with this function. $quote = array( 'id' => $this->shipping_methode_code, 'module' => MODULE_SHIPPING_ICIRELAIS_TEXT_TITLE, 'methods' => array()); // Zip code is mandatory if(empty($this->zipcode)){ $quote['error'] = TEXT_POSTALCODE_MISSING; return $quote; } // If empty(cp+ville) ==> do not call the webservice for nothing and get from database's backup if(empty($this->city)){ $relais_items = $this->get_point_backup(); } else { // MyPudo WEBSERVICE CALL include('nusoap/nusoap.php'); $client = new nusoap_client($this->_configuration_key['MODULE_SHIPPING_ICIRELAIS_MYPUDO_URL'], 'wsdl', false, false, false, false, 0, 10); $parameters = array ( 'firmID' => $this->_configuration_key['MODULE_SHIPPING_ICIRELAIS_ID_MARCHAND'], 'securityKey' => $this->_configuration_key['MODULE_SHIPPING_ICIRELAIS_SECURITY_KEY'], 'strAddress' => utf8_encode($this->stripAccents($this->address)), 'strZIPCode' => $this->zipcode, 'strCity' => utf8_encode($this->stripAccents($this->city)), 'requestID' => '' ); $result = ( array ) $client->call('GetSiteIDs_By_AddressInfos_As_XmlResponse', $parameters); $result = ( array ) $result ['GetSiteIDs_By_AddressInfos_As_XmlResponseResult']; // Call backup database if : // - no webservice result // - soap fault exception // - quality indicator = 0 // - error // - no MyPudo idem if(!$result || $client->fault || ( int ) $result['RESPONSE']['RESPONSE_QUALITY'] == 0 || $client->getError() || empty ( $result['RESPONSE']['PUDO_ITEM'] )){ $relais_items = $this->get_point_backup(); } else { $relais_items = $result['RESPONSE']['PUDO_ITEM']; } } // Reorganize de ici relais points by distance $relais_items = $this->reorganize_id_list_by_distance($relais_items); ksort($relais_items); if (!$relais_items) { // No ici relais point from MyPudo nor database backup $quote['error'] = TEXT_NO_ICIRELAIS_POINT; } else { // Filter ici relais points to display the 5 first one $quote['methods'] = $this->filter_points ( $relais_items ); } return $quote; } function stripAccents($texte) { $texte = str_replace( array( 'à', 'â', 'ä', 'á', 'ã', 'å', 'î', 'ï', 'ì', 'í', 'ô', 'ö', 'ò', 'ó', 'õ', 'ø', 'ù', 'û', 'ü', 'ú', 'é', 'è', 'ê', 'ë', 'ç', 'ÿ', 'ñ', 'À', 'Â', 'Ä', 'Á', 'Ã', 'Å', 'Î', 'Ï', 'Ì', 'Í', 'Ô', 'Ö', 'Ò', 'Ó', 'Õ', 'Ø', 'Ù', 'Û', 'Ü', 'Ú', 'É', 'È', 'Ê', 'Ë', 'Ç', '', 'Ñ' ), array( 'a', 'a', 'a', 'a', 'a', 'a', 'i', 'i', 'i', 'i', 'o', 'o', 'o', 'o', 'o', 'o', 'u', 'u', 'u', 'u', 'e', 'e', 'e', 'e', 'c', 'y', 'n', 'A', 'A', 'A', 'A', 'A', 'A', 'I', 'I', 'I', 'I', 'O', 'O', 'O', 'O', 'O', 'O', 'U', 'U', 'U', 'U', 'E', 'E', 'E', 'E', 'C', 'Y', 'N' ),$texte); return $texte; } //-------------------------------------------------------------------------------------------------------------- // GET ICI RELAIS POINT BACKUP (DATABASE) //-------------------------------------------------------------------------------------------------------------- /** * Get ici relais point from backup database * * @return array list of ici relais points id */ function get_point_backup() { $query = "SELECT relay_id, sort_order, distance FROM icibackup WHERE postal_code ='".$this->zipcode."' ORDER BY distance ASC"; $get_icibackup_id = tep_db_query($query); $i = 0; while($row = tep_db_fetch_array($get_icibackup_id)){ $relais_items[$i]['PUDO_ID'] = $row['relay_id']; $relais_items[$i]['ORDER'] = $row['sort_order']; $relais_items[$i]['DISTANCE'] = $row['distance']; $i++; } return $relais_items; } //-------------------------------------------------------------------------------------------------------------- // FILTER THE 10 ICI RELAIS POINTS //-------------------------------------------------------------------------------------------------------------- /** * Get each ici relais point detail, filter them by closing period * If the point is good and if we have less than 6 points, we prepare the display list and the detail in a html div * * @return array part of ici relais points list array */ function filter_points($relais_items){ $quote['methods'] = array(); $offset = 1; foreach ( $relais_items as $items ) { $point = array(); $this->str_closing_period = ''; // Search the ici relais point detail $query = " SELECT relay_id, shop_name, adresse_1, adresse_2, adresse_3, postal_code, city, coord_lat, coord_long, monday_opening_hours, tuesday_opening_hours, wednesday_opening_hours, thursday_opening_hours, friday_opening_hours, saturday_opening_hours, sunday_opening_hours, closing_period_start_date_1, closing_period_end_date_1, closing_period_start_date_2, closing_period_end_date_2, closing_period_start_date_3, closing_period_end_date_3 FROM icirelais WHERE relay_id LIKE '".$items['PUDO_ID']."'"; $get_point_detail = tep_db_query($query); // Only if the point is in database, we propose it if($point = tep_db_fetch_array($get_point_detail)){ // Is between closing period and closing period > 4 days ==> we don't propose le ICI Relais point if($this->is_between_closing_period ( $point, 1 ) || $this->is_between_closing_period ( $point, 2 ) || $this->is_between_closing_period ( $point, 3 )) { continue; } // Construct the closing period info the display in the point's detail if(strlen($this->str_closing_period) > 0){ $this->str_closing_period = TEXT_WARNING_ICIRELAIS_POINT_CLOSED.$this->str_closing_period; $display = 'block'; } else { $display = 'none'; } // We display only 5 ICI Relais points if ($offset <= 5) { // ICI Relais list $title = ''; // window : left column $title.= '
'; $quote['methods'][] = array('id' => $point['relay_id'], // text : display in the delivery's sumup insted of title (html code on't be in the table order_total) 'text' => TEXT_ICIRELAIS_POINT . $point['shop_name'] . ' (' . $point['relay_id'] . ')', 'title' => $title, 'cost' => MODULE_SHIPPING_ICIRELAIS_COST); $offset++; } else { break; } } } return $quote['methods']; } //-------------------------------------------------------------------------------------------------------------- // OPENING HOURS FORMATTING //-------------------------------------------------------------------------------------------------------------- /** * Opening hours string list for a day * * @return string de la forme 09:00-12:30 & 14:00- 17:30 ou Fermé & 14:00- 17:30 */ function get_opening_hours ($opening_hours){ $opening_hours_tab = explode ( " ", $opening_hours ); if (($opening_hours_tab [0] == "00:00-00:00") && ($opening_hours_tab [1] == "00:00-00:00")) { $hours = TEXT_CLOSED; } else { if ($opening_hours_tab [0] == "00:00-00:00") { $hours = TEXT_CLOSED . ' & ' . $opening_hours_tab [1]; } if ($opening_hours_tab [1] == "00:00-00:00") { $hours = $opening_hours_tab [0] . ' & '.TEXT_CLOSED; } if ($opening_hours_tab [0] != "00:00-00:00" && $opening_hours_tab [1] != "00:00-00:00") $hours = $opening_hours_tab [0] . ' & ' . $opening_hours_tab [1]; } return $hours; } //-------------------------------------------------------------------------------------------------------------- // IS BETWEEN CLOSING PERIOD //-------------------------------------------------------------------------------------------------------------- /** * Determine if the potential shipping date to the ici relais point will be in a closing period * * @return boolean */ function is_between_closing_period($point,$num_period) { // ICI Relais needs 12 days of treatment + number of additional treatment day specified in the back office $max = $this->_configuration_key['MODULE_SHIPPING_ICIRELAIS_ADDITIONAL_TREATMENT_DAY'] + 12 ; //12 days of treatment for ICI Relais $now = time(); $deadline = strtotime('+'.$max.' days'); $start=strtotime($this->convertdateformat($point['closing_period_start_date_'.$num_period])); $end = strtotime($this->convertdateformat($point['closing_period_end_date_'.$num_period])); if (($deadline >= $start && $deadline <= $end) || ($now >= $start && $now <= $end) || ($now < $start && $deadline > $end) ) { // The ICI relais point is closed ! // so we conserve the closing date(s) if($this->str_closing_period) { $this->str_closing_period .= ' '.TEXT_AND.'