Exemplo n.º 1
0
function fn_fedex_ship($data, &$auth, $shipping_settings, $origination)
{
    $ground_codes = array('90', '92');
    $account_number = $shipping_settings['fedex']['account_number'];
    $meter_number = $shipping_settings['fedex']['meter_number'];
    $package_type = $shipping_settings['fedex']['package_type'];
    $drop_off_type = $shipping_settings['fedex']['drop_off_type'];
    $height = $shipping_settings['fedex']['height'];
    $width = $shipping_settings['fedex']['width'];
    $length = $shipping_settings['fedex']['length'];
    // Normalize supplier address data
    $origination_address1 = substr($origination['address'], 0, 32);
    preg_match_all("/[\\d\\w]/", $origination['zipcode'], $matches);
    $origination_postal = !empty($matches[0]) ? implode('', $matches[0]) : '';
    preg_match_all("/[\\d]/", $origination['phone'], $matches);
    $origination_phone = !empty($matches[0]) ? implode('', $matches[0]) : '8001234567';
    $origination_phone = strlen($origination_phone) >= 10 ? substr($origination_phone, 0, 10) : str_pad($origination_phone, 10, '0');
    $origination_name = substr($origination['company'], 0, 35);
    $origination_city = $origination['city'];
    $origination_state = $origination['state'];
    $origination_country = $origination['country'];
    // Normalize customer address data
    $destination_address1 = substr($location['address'], 0, 32);
    preg_match_all("/[\\d\\w]/", $location['zipcode'], $matches);
    $destination_postal = !empty($matches[0]) ? implode('', $matches[0]) : '';
    preg_match_all("/[\\d]/", $location['phone'], $matches);
    $destination_phone = !empty($matches[0]) ? implode('', $matches[0]) : '';
    $destination_phone = strlen($destination_phone) >= 10 ? substr($destination_phone, 0, 10) : str_pad($destination_phone, 10, '0');
    $destination_name = $location['firstname'] . ' ' . $location['lastname'];
    $destination_city = $location['city'];
    $destination_state = $location['state'];
    $destination_country = $location['country'];
    $is_domestic = $destination_country == $origination_country ? true : false;
    // define weight unit and value
    $weight_unit = 'LBS';
    $weight_unit_short = 'LB';
    $weight = $weight_data['full_pounds'];
    $fed = new FedExDC($account_number, $meter_number);
    $ship_data = array('weight_units' => $weight_unit, 11 => $destination_name, 13 => $destination_address1, 15 => $destination_city, 16 => $destination_state, 17 => $destination_postal, 18 => $destination_phone, 50 => $destination_country, 4 => $origination_name, 5 => $origination_address1, 7 => $origination_city, 8 => $origination_state, 9 => $origination_postal, 117 => $origination_country, 183 => $origination_phone, 57 => $height, 58 => $width, 59 => $length, 1116 => 'I', 1273 => $package_type, 1274 => $code, 23 => '1', 1333 => $drop_off_type, 1401 => $weight, 116 => '1', 68 => 'USD', 2399 => '1');
    $today = getdate(TIME);
    if ($today['wday'] == 0 || $today['wday'] == 6) {
        // if today is saturday or sunday, set ship date manually
        $next_time = strtotime($today['wday'] == 0 ? "+1 day" : "+2 days");
        $next_date = getdate($next_time);
        $ship_data[24] = $next_date['year'] . $next_date['month'] . $next_date['day'];
    }
    if ($is_domestic == false) {
        $customs_total = fn_format_price($_SESSION['cart']['total']);
        $ship_data[70] = 1;
        // INTL: who pay the duties (2 - recipient)
        $ship_data[79] = 'Good contents';
        // INTL: description of content
        $ship_data[80] = $origination_country;
        // INTL: producer of goods
        $ship_data[82] = 1;
        // INTL: number of units in one good
        $ship_data[1408] = '1.000000';
        // INTL: value of each unit
        $ship_data[414] = $weight_unit_short;
        // INTL: weight unit measure
        $ship_data[1407] = '0.1';
        // INTL: weight of each unit
        $ship_data[1411] = $customs_total;
        // INTL: customs total
    }
    if (in_array($code, $ground_codes)) {
        if ($code == '90') {
            $ship_data[440] = 'Y';
        }
        $ship_data[1119] = 'N';
        $ship_data[2399] = '2';
        // indirect signature
        //		$ship_ret = $fed->ship_ground($ship_data);
    } else {
        //		$ship_ret = $fed->ship_express($ship_data);
    }
    $ship_ret = $fed->rate_services($ship_data);
    $charge = $fed->lookup('net_charge_amount');
    $result = array('cost' => $charge);
    if (!empty($charge)) {
        return $result;
    } else {
        if (defined('SHIPPING_DEBUG')) {
            return array('error' => $fed->getError());
        }
    }
    return false;
}