PDA

View Full Version : Installing USPS Methods 4.3.0 ALPHA on osCMax v2.0.2



dknowle
04-28-2009, 12:37 PM
I was having no luck getting the USPS module that came with osCMax v2 to calculate shipping charges, so I decided to upgrade to the latest USPS Methods 4.3.0 ALPHA & this solved the problem (at least it appears to working, but this is an ALPHA release & I also have not had much chance to test this module yet).

The installation instructions are for a standard osCommerce installation, so it is a little different for osCMax. For anyone interested in doing this upgrade, you can follow the revised installation instructions below for an installation of osCMax v2.0.2:

**********
* STEP 1 *
**********

Back up your admin and catalog directories and your database. We're not
kidding.


**********
* STEP 2 *
**********

In admin, disable USPS by clicking the red button if this module is currently
enabled. This step is necessary to remove the existing configuration table
variables, which will be replaced when the new module is enabled.


**********
* STEP 3 *
**********

Replace catalog/includes/modules/shipping/usps.php with the file included in
this contribution. DO NOT rename the old usps.php and leave it in the
directory, as doing so will create problems (the modules manager builds the
display from all modules in the directory).


**********
* STEP 4 *
**********

Replace catalog/includes/languages/english/modules/shipping/usps.php with the
file included in this contribution. If your store has other languages,
replicate this file into the other language directories as
catalog/includes/languages/<language>/modules/shipping/usps.php; translate and
edit its content if you are able.

**********
* STEP 5 *
**********

*****************************************
Find This code somewhere around line 895:
*****************************************



// BOF: MOD - USPS Methods 2.5
// Alias function for Store configuration values in the Administration Tool
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;
}
// EOF: MOD - USPS Methods 2.5


REPLACE with:


// BOF: MOD - USPS Methods 4.3.0 ALPHA
// USPS Methods 3.0
// Alias function for Store configuration values in the Administration Tool
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;
}

// USPS Methods. Added by Greg Deeth
// Alias function for Store configuration values in the Administration Tool.
// Creates multiple text input boxes in a list.
// Remember to add blank default values: 1, 2, , , 5, 6, ...
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;
}

// USPS Methods. Added by Greg Deeth
// Alias function for Store configuration values in the Administration Tool.
// Creates a text input box on either side of the option, adds <= OPTION <= and makes a list.
// Remember to add blank default values: 1, 2, , , 5, 6, ...
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;
}
// EOF: MOD - USPS Methods 4.3.0 ALPHA


**********
* STEP 6 *
**********

catalog/includes/functions/general.php

*****************************************
Find This code somewhere around line 335:
*****************************************


////
// 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;
}


***********************************************
INSERT THE FOLLOWING CODE AFTER THE ABOVE LINE:
***********************************************



// BOF: MOD - USPS Methods 4.3.0 ALPHA
////
// 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;
}
// EOF: MOD - USPS Methods 4.3.0 ALPHA


**********
* STEP 7 *
**********
execute the following SQL updates:



UPDATE configuration
SET configuration_value = UPPER(configuration_value),
set_function='tep_cfg_select_multioption(array(''G LOBAL EXPRESS'', ''GLOBAL EXPRESS NON-DOC RECT'', ''GLOBAL EXPRESS NON-DOC NON-RECT'', ''EXPRESS MAIL INT'', ''EXPRESS MAIL INT FLAT RATE ENV'', ''PRIORITY MAIL INT'', ''PRIORITY MAIL INT FLAT RATE ENV'', ''PRIORITY MAIL INT FLAT RATE BOX'', ''FIRST-CLASS MAIL INT''), '
WHERE configuration_key='MODULE_SHIPPING_USPS_TYPES_INTL ';
UPDATE configuration
SET configuration_value = UPPER(configuration_value),
set_function='tep_cfg_select_multioption(array(''E XPRESS'', ''PRIORITY'', ''FIRST CLASS'', ''PARCEL'', ''BPM'', ''LIBRARY'', ''MEDIA''), '
WHERE configuration_key='MODULE_SHIPPING_USPS_TYPES';


**********
* STEP 8 *
**********
Install your USPS module in the admin panel.

*************************
* TROUBLESHOOTING TIPS: *
*************************

1. If you are getting a "parse error" (I had this error) when you click edit in the admin OR
your international options with checkboxes are not showing up in the admin,
you may need to use 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