Example #1
0
 /** 
  * Echos a formatted list of shipping rates.
  * 
  * @param array $d
  * @return boolean
  */
 function list_rates(&$d)
 {
     global $vendor_country_2_code, $vendor_currency, $vmLogger;
     global $VM_LANG, $CURRENCY_DISPLAY;
     $db =& new ps_DB();
     $dbv =& new ps_DB();
     $cart = $_SESSION['cart'];
     // Read the fedex configuration file
     require_once CLASSPATH . "shipping/" . $this->classname . ".cfg.php";
     // Include the main FedEx class
     require_once CLASSPATH . 'shipping/fedex/fedexdc.php';
     // Get the meter number
     if (FEDEX_METER_NUMBER == '') {
         if (!$this->update_meter_number()) {
             $vmLogger->err($VM_LANG->_('VM_FEDEX_ERR_METER_NUMBER', false));
             return false;
         }
     }
     // Get the shopper's shipping address
     $q = "SELECT * FROM #__{vm}_user_info, #__{vm}_country WHERE user_info_id='" . $d["ship_to_info_id"] . "' AND ( country=country_2_code OR country=country_3_code)";
     $db->query($q);
     $db->next_record();
     // Get the vendor address
     $q = "SELECT * FROM #__{vm}_vendor WHERE vendor_id='" . $_SESSION['ps_vendor_id'] . "'";
     $dbv->query($q);
     $dbv->next_record();
     // Is this a residential delivery?
     $residential_delivery_flag = vmGet($_REQUEST, 'address_type', 'residential') == 'residential' ? 'Y' : 'N';
     // Is this a domestic delivery?
     $recipient_country = $db->f('country_2_code');
     $domestic_delivery = $recipient_country == 'US' || $recipient_country == 'CA' ? true : false;
     // Get the weight total
     if ($d['weight'] > 150) {
         $d['weight'] = 150;
     }
     if ($d['weight'] < 1) {
         $d['weight'] = 1;
     }
     $order_weight = number_format((double) $d['weight'], 1, '.', '');
     // Set units
     $weight_units = WEIGHT_UOM == 'KG' ? 'KGS' : 'LBS';
     $dimension_units = WEIGHT_UOM == 'KG' ? 'C' : 'I';
     // config values
     $fed_conf = array();
     // create new FedExDC object
     $meter_number = defined('FEDEX_METER_NUMBER_TEMP') ? FEDEX_METER_NUMBER_TEMP : FEDEX_METER_NUMBER;
     $fed = new FedExDC(FEDEX_ACCOUNT_NUMBER, $meter_number, $fed_conf);
     // Set up the rate request array.
     // You can either use the FedEx tag value or the field name in the $FE_RE array
     $request_array = array('carrier_code' => '', 'sender_state' => $dbv->f('vendor_state'), 'sender_postal_code' => $dbv->f('vendor_zip'), 'sender_country_code' => $vendor_country_2_code, 'recipient_state' => $db->f('state'), 'recipient_postal_code' => $db->f('zip'), 'recipient_country' => $db->f('country_2_code'), 'residential_delivery_flag' => $residential_delivery_flag, 'signature_option' => FEDEX_SIGNATURE_OPTION, 'weight_units' => $weight_units, 'total_package_weight' => $order_weight, 'drop_off_type' => '1');
     // Get the rate quote
     $rate_Ret = $fed->services_rate($request_array);
     if ($error = $fed->getError()) {
         $vmLogger->err($error);
         // Switch to StandardShipping on Error !!!
         require_once CLASSPATH . 'shipping/standard_shipping.php';
         $shipping =& new standard_shipping();
         $shipping->list_rates($d);
         return;
     } elseif (DEBUG) {
         echo "<pre>";
         echo $fed->debug_str . "\n<br />";
         print_r($rate_Ret);
         echo "\n";
         echo "ZONE: " . $rate_Ret[1092] . "\n\n";
         for ($i = 1; $i <= $rate_Ret[1133]; $i++) {
             echo "SERVICE : " . $fed->service_type($rate_Ret['1274-' . $i], $domestic_delivery) . "\n";
             echo "SURCHARGE : " . $rate_Ret['1417-' . $i] . "\n";
             echo "DISCOUNT : " . $rate_Ret['1418-' . $i] . "\n";
             echo "NET CHARGE : " . $rate_Ret['1419-' . $i] . "\n";
             echo "DELIVERY DAY : " . @$rate_Ret['194-' . $i] . "\n";
             echo "DELIVERY DATE : " . @$rate_Ret['409-' . $i] . "\n\n";
         }
         echo "</pre>";
     }
     // Set the tax rate
     if ($_SESSION['auth']['show_price_including_tax'] != 1) {
         $taxrate = 1;
     } else {
         $taxrate = $this->get_tax_rate() + 1;
     }
     // Write out the shipping rates
     $html = '<span class="fedex_header">' . $VM_LANG->_('VM_FEDEX_LBL_METHOD') . '</span><br />';
     // Get a sort order array (by cost)
     $cost_array = array();
     for ($i = 1; $i <= $rate_Ret[1133]; $i++) {
         $cost_array[$i] = $rate_Ret['1419-' . $i];
     }
     if (FEDEX_SORT_ORDER == 'ASC') {
         asort($cost_array, SORT_NUMERIC);
     } else {
         arsort($cost_array, SORT_NUMERIC);
     }
     // Determine which services we can display
     $selected_services = explode(',', FEDEX_SERVICES);
     if ($domestic_delivery) {
         $selected_services = preg_grep('/^d/', $selected_services);
         array_walk($selected_services, create_function('&$v,$k', '$v = substr($v, 1);'));
         // If this is a residential delivery, then remove the business option; otherwise, remove the home delivery option.
         if ($residential_delivery_flag == 'Y') {
             $remove = array("92");
             $selected_services = array_diff($selected_services, array("92"));
         } else {
             $remove = array("90");
             $selected_services = array_diff($selected_services, array("90"));
         }
     } else {
         $selected_services = preg_grep('/^i/', $selected_services);
         array_walk($selected_services, create_function('&$v,$k', '$v = substr($v, 1);'));
     }
     // Display each rate
     foreach (array_keys($cost_array) as $i) {
         if (in_array($rate_Ret['1274-' . $i], $selected_services)) {
             $charge = $rate_Ret['1419-' . $i] + floatval(FEDEX_HANDLINGFEE);
             $charge *= $taxrate;
             $charge_display = $CURRENCY_DISPLAY->getFullValue($charge);
             $shipping_rate_id = urlencode($this->classname . "|FedEx|" . $fed->service_type($rate_Ret['1274-' . $i], $domestic_delivery) . "|" . $charge);
             $checked = @$d["shipping_rate_id"] == $shipping_rate_id ? "checked=\"checked\"" : "";
             $html .= "\n<span class=\"ssectiontableentry" . (2 - $i % 2) . "\">";
             $html .= "\n<input type=\"radio\" id=\"{$shipping_rate_id}\" name=\"shipping_rate_id\" {$checked} value=\"{$shipping_rate_id}\" />\n";
             $_SESSION[$shipping_rate_id] = 1;
             $html .= "<label for=\"{$shipping_rate_id}\">" . $fed->service_type($rate_Ret['1274-' . $i], $domestic_delivery) . " ";
             //			if( !empty( $rate_Ret['194-'.$i] ) && !empty($rate_Ret['409-'.$i])) {
             //				$html .= ", expected delivery: ".$rate_Ret['194-'.$i].', '.$rate_Ret['409-'.$i];
             //			}
             $html .= "<strong>({$charge_display})</strong>";
             $html .= "</label>\n";
             $html .= "</span>\n";
             $html .= "<br />\n";
         }
     }
     echo $html;
     return true;
 }