USPS 5.1.0 shipping method with Oscommerce

Step 1: Remove USPS module from within admin panel

Step 2: Upload and overwrite below files
includes/modules/shipping/usps.php
includes/languages/english/modules/shipping/usps.php
If your store has another languages, put this file into other language directories includes/languages//modules/shipping/usps.php;
Translate and edit its content

Step 3: In admin/includes/functions/general.php
FIND:

function tep_mod_select_option($select_array, $key_name, $key_value) 
{
     reset($select_array);
     while (list($key, $value) = each($select_array)) 
     {
     if (is_int($key)) $key = $value;
     $string .= '<br><input type="radio" name="configuration[' . $key_name . ']" value="' . $key . '"';
     if ($key_value == $key) $string .= ' CHECKED';
     $string .= '> ' . $value;
    }
    return $string;
  } 

ADD AFTER ABOVE CODE:

		// USPS Methods - credit to Greg Deeth
		  function tep_cfg_select_multioption($select_array, $key_value, $key = '') {
		    for ($i=0; $i<sizeof($select_array); $i++) {
		      $name = (($key) ? 'configuration[' . $key . '][]' : 'configuration_value');
		      $string .= '<br><input type="checkbox" name="' . $name . '" value="' . $select_array[$i] . '"';
		      $key_values = explode( ", ", $key_value);
		      if ( in_array($select_array[$i], $key_values) ) $string .= ' CHECKED';
		      $string .= '> ' . $select_array[$i];
		    }
		    $string .= '<input type="hidden" name="' . $name . '" value="--none--">';
		    return $string;
		  }
		  function tep_cfg_multiinput_list($select_array, $key_value, $key = '') {
		    $key_values = explode( ", ", $key_value);
		
		    for ($i=0; $i<sizeof($select_array); $i++) {
		      $name = (($key) ? 'configuration[' . $key . '][]' : 'configuration_value');
		      $string .= '<br><input type="text" name="' . $name . '" value="' . $key_values[$i] . '"> ' . $select_array[$i];
		    }
		    $string .= '<input type="hidden" name="' . $name . '" value="--none--">';
		    return $string;
		  }
		  function tep_cfg_multiinput_duallist_oz($select_array, $key_value, $key = '') {
		    $key_values = explode( ", ", $key_value);
		    $string .= '<center>';
		    for ($i=0; $i<sizeof($select_array); $i++) {
			$current_key_value = current($key_values);
		      $name = (($key) ? 'configuration[' . $key . '][]' : 'configuration_value');
		      $string .= '<br><input type="text" name="' . $name . '" size="3" value="' . $current_key_value . '"><i>oz</i>';
			$string .= ' <b><</b> ' . $select_array[$i] . ' <u><b><</b></u>';
			next($key_values);
			$current_key_value = current($key_values);
			$string .= '<input type="text" name="' . $name . '" size="3" value="' . $current_key_value . '"><i>oz</i>';
			next($key_values);
		    }
		    $string .= '<input type="hidden" name="' . $name . '" value="--none--">';
		    $string .= '</center>';
		    return $string;
		  }
		  function tep_cfg_multiinput_duallist_lb($select_array, $key_value, $key = '') {
		    $key_values = explode( ", ", $key_value);
		    $string .= '<center>';
		    for ($i=0; $i<sizeof($select_array); $i++) {
			$current_key_value = current($key_values);
		      $name = (($key) ? 'configuration[' . $key . '][]' : 'configuration_value');
		      $string .= '<br><input type="text" name="' . $name . '" size="3" value="' . $current_key_value . '"><i>lbs</i>';
			$string .= ' <b><</b> ' . $select_array[$i] . ' <u><b><</b></u>';
			next($key_values);
			$current_key_value = current($key_values);
			$string .= '<input type="text" name="' . $name . '" size="3" value="' . $current_key_value . '"><i>lbs</i>';
			next($key_values);
		    }
		    $string .= '<input type="hidden" name="' . $name . '" value="--none--">';
		    $string .= '</center>';
		    return $string;
		  }

FIND:

// Calculates Tax rounding the result
  function tep_calculate_tax($price, $tax) 
{
    return $price * $tax / 100;
  }

ADD AFTER ABOVE CODE:

// Round up function for non whole numbers by GREG DEETH
// The value for the precision variable determines how many digits after the decimal and rounds the last digit up to the next value
// Precision = 0 -> xx.xxxx = x+
// Precision = 1 -> xx.xxxx = xx.+
// Precision = 2 -> xx.xxxx = xx.x+
  function tep_round_up($number, $precision) 
{
	$number_whole = '';
	$num_left_dec = 0;
	$num_right_dec = 0;
	$num_digits = strlen($number);
	$number_out = '';
	$i = 0;
	while ($i + 1 <= strlen($number))
	{
		$current_digit = substr($number, $i, ($i + 1) - $num_digits);
		if ($current_digit == '.') {
			$i = $num_digits + 1;
			$num_left_dec = strlen($number_whole);
			$num_right_dec = ($num_left_dec + 1) - $num_digits;
		} else {
			$number_whole = $number_whole . $current_digit;
			$i = $i + 1;
		}
	}
	if ($num_digits > 3 && $precision < ($num_digits - $num_left_dec - 1) && $precision >= 0) {
		$i = $precision;
		$addable = 1;
		while ($i > 0) {
			$addable = $addable * .1;
			$i = $i - 1;
		} 
		$number_out = substr($number, 0, $num_right_dec + $precision) + $addable;
	} else {
		$number_out = $number;
	}
	return $number_out;
  }

Step 4: In includes/functions/general.php
FIND:

// Wrapper function for round()
  function tep_round($number, $precision) {
    if (strpos($number, '.') && (strlen(substr($number, strpos($number, '.')+1)) > $precision)) {
      $number = substr($number, 0, strpos($number, '.') + 1 + $precision + 1);

      if (substr($number, -1) >= 5) {
        if ($precision > 1) {
          $number = substr($number, 0, -1) + ('0.' . str_repeat(0, $precision-1) . '1');
        } elseif ($precision == 1) {
          $number = substr($number, 0, -1) + 0.1;
        } else {
          $number = substr($number, 0, -1) + 1;
        }
      } else {
        $number = substr($number, 0, -1);
      }
    }

    return $number;
  }

ADD AFTER ABOVE CODE:

// Round up function for non whole numbers by GREG DEETH
// The value for the precision variable determines how many digits after the decimal and rounds the last digit up to the next value
// Precision = 0 -> xx.xxxx = x+
// Precision = 1 -> xx.xxxx = xx.+
// Precision = 2 -> xx.xxxx = xx.x+
  function tep_round_up($number, $precision) {
	$number_whole = '';
	$num_left_dec = 0;
	$num_right_dec = 0;
	$num_digits = strlen($number);
	$number_out = '';
	$i = 0;
	while ($i + 1 <= strlen($number))
	{
		$current_digit = substr($number, $i, ($i + 1) - $num_digits);
		if ($current_digit == '.') {
			$i = $num_digits + 1;
			$num_left_dec = strlen($number_whole);
			$num_right_dec = ($num_left_dec + 1) - $num_digits;
		} else {
			$number_whole = $number_whole . $current_digit;
			$i = $i + 1;
		}
	}
	if ($num_digits > 3 && $precision < ($num_digits - $num_left_dec - 1) && $precision >= 0) {
		$i = $precision;
		$addable = 1;
		while ($i > 0) {
			$addable = $addable * .1;
			$i = $i - 1;
		} 
		$number_out = substr($number, 0, $num_right_dec + $precision) + $addable;
	} else {
		$number_out = $number;
	}
	return $number_out;
  }

Step 5: In admin/modules.php (only much older versions will need this)
FIND:

if (tep_not_null($action)) {
    switch ($action) {
      case 'save':
        while (list($key, $value) = each($HTTP_POST_VARS['configuration'])) {

ADD AFTER ABOVE CODE:

  if( is_array( $value ) )
{
          $value = implode( ", ", $value);
  $value = ereg_replace (", --none--", "", $value);
}

Step 6: SQL changes
Phpmyadmin
configuration table –> structure
edit set_function from 255 to 1020

Step 7: Install USPS module from admin panel and configure

TIPS:
1. phpMyAdmin to update the database -> configuration TABLE
and CHANGE “set_function” to TEXT from VARCHAR.
Afterwards:
A. Remove the USPS module in the admin
B. Re-install the USPS module in the admin
C. The options will appear

2. Make sure you have set your store’s country and postal code in admin -> Configuration -> Shipping/Packaging, as these are used in the rate quote request and if not valid will cause an error.

3. Check for configuration Shipping / Packaging link for Country of Origin and Postal code
This will affect to display USPS shipping rate so please set the value.

Hope it will help you….

Speak Your Mind

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: