Community Add-Ons
| Maintainers: | fulluvscents |
USPS Rate V4 Intl Rate V2 - v.1.0
for osCommerce Online Merchant v2.3
USPS Rate V4 Intl Rate V2
This is a clean and simple module, intended to perform it's function efficiently and simply, without any frills or gimmicks.
All domestic and international methods (regular, flat rate, and regional) are included, and you have the choice of which methods to offer your customers.
Customization, to nearly any degree, is available for a fee. Contact me directly (jetta [AT] fulluvscents.com).
Donations can also be sent through PayPal to the same addy and are very appreciated.
Legend:
Download
Report
This is an ADD-ON for USPS USPS Rate V4 Intl Rate V2 - v.1.7
with osc 2.3.1
Goes beyond the weight thresholds and provides the ability to block certain shipping methods by product.
Examples of use:
You ship with flat rate envelopes but have some glass products that shouldn't be shipped in an envelope.
You ship small items and lightweight large items. These items will fit the weight threshold but will not fit a flat rate box dimensionally.
You ship a few hazmat items which can only be shipped by ground, and not air.
You don't have to eliminate the shipping method altogether. You can simply block the method for the appropriate products.
If you cart contains mixed items, and one of them cannot be shipped by a method, it will block that method for the entire order.
Restrictions are made from the PRODUCT edit page in your admin panel.
Only methods that you have in your allowed list (in the usps shipping module panel) will be shown.
Check the methods that you want to RESTRICT for that particular item.
Please use a file compare tool to make the necessary changes to the included files.
Perform the small sql query.
FIXED:
Extra services weren't being multiplied by number of boxes.
AFFECTED FILE:
usps.php
FULL PACKAGE
Compatibility Instructions
Simple Checkout for 2.3.1 v1.3
with
USPS Rate V4 Intl Rate V2 - v.1.7
ALL CHANGES ARE BEING MADE TO CHECKOUT.PHP
1.
Find:
case 'checkEmail':
Add BEFORE:
// USPS START
case 'addUspsServices':
$uspsServices = 0;
foreach($_POST as $key => $val)
if($key != 'action' && $key != 'shipping') $uspsServices += $val;
if (!tep_session_is_registered('shipping')) tep_session_register('shipping');
$shipping = $_POST['shipping'];
list($module, $method) = explode('_', $shipping);
$quote = $shipping_modules->quote($method, $module);
if (isset($quote['error'])) tep_session_unregister('shipping');
elseif ( isset($quote[0]['methods'][0]['title']) && isset($quote[0]['methods'][0]['cost']) )
$shipping = array( 'id' => $shipping,
'title' => $quote[0]['module'] . ' (' . $quote[0]['methods'][0]['title'] . ')',
'cost' => $quote[0]['methods'][0]['cost'] + $uspsServices);
$return['cost'] = $currencies->format($shipping['cost']);
echo json_encode($return);
exit;
// USPS END
2.
Find:
echo ' <tr class="moduleRow shippingRow' . ($quotes[$i]['id'] . '_' . $quotes[$i]['methods'][$j]['id'] == $shipping['id'] ? ' moduleRowSelected' : '') . '"><td>' . $quotes[$i]['methods'][$j]['title'] . '</td>';
echo ' <td>' . $currencies->format(tep_add_tax($quotes[$i]['methods'][$j]['cost'], (isset($quotes[$i]['tax']) ? $quotes[$i]['tax'] : 0))) . '</td>
Replace with:
// USPS START
// echo ' <tr class="moduleRow shippingRow' . ($quotes[$i]['id'] . '_' . $quotes[$i]['methods'][$j]['id'] == $shipping['id'] ? ' moduleRowSelected' : '') . '"><td>' . $quotes[$i]['methods'][$j]['title'] . '</td>';
echo ' <tr class="moduleRow shippingRow' . ($quotes[$i]['id'] . '_' . $quotes[$i]['methods'][$j]['id'] == $shipping['id'] ? ' moduleRowSelected' : '') . '"><td width=80%>' . $quotes[$i]['methods'][$j]['title'] . (isset($quotes[$i]['methods'][$j]['shownString']) ? $quotes[$i]['methods'][$j]['shownString'] : '') . (isset($quotes[$i]['methods'][$j]['customerString']) ? $quotes[$i]['methods'][$j]['customerString'] : '') . '</td>';
// echo ' <td>' . $currencies->format(tep_add_tax($quotes[$i]['methods'][$j]['cost'], (isset($quotes[$i]['tax']) ? $quotes[$i]['tax'] : 0))) . '</td>
echo ' <td id="shippingCost">' . $currencies->format(tep_add_tax($quotes[$i]['methods'][$j]['cost'], (isset($quotes[$i]['tax']) ? $quotes[$i]['tax'] : 0))) . '</td>
// USPS END
3.
Find:
RowsRefresh: function(type)
{
$.ajax(
{
data: 'action=' + type + 'RowsRefresh',
dataType: 'html',
success: function(data)
{
$('#' + type + 'Rows').html(data);
$('[name=' + type + ']').bind('click', (type == 'shipping' ? checkout.shippingSet : checkout.paymentSet));
$('[name=' + type + ']:checked').click();
}
});
},
shippingSet: function()
{
var el = $(this);
$.ajax(
{
data: 'action=shippingSet&shipping=' + $(this).val(),
success: function(data)
{
el.parent().parent().siblings().removeClass('moduleRowSelected');
el.parent().parent().addClass('moduleRowSelected');
checkout.totalsRefresh();
}
});
},
Replace with:
RowsRefresh: function(type)
{
$.ajax(
{
data: 'action=' + type + 'RowsRefresh',
dataType: 'html',
success: function(data)
{
$('#' + type + 'Rows').html(data);
$('[name=' + type + ']').bind('click', (type == 'shipping' ? checkout.shippingSet : checkout.paymentSet));
$('[name=' + type + ']:checked').click();
// USPS START
$('[type=checkbox]', $('#shipping', $('#checkout'))).bind('change', checkout.addUspsServices);
// USPS END
}
});
},
shippingSet: function()
{
var el = $(this);
$.ajax(
{
data: 'action=shippingSet&shipping=' + $(this).val(),
success: function(data)
{
el.parent().parent().siblings().removeClass('moduleRowSelected');
el.parent().parent().addClass('moduleRowSelected');
checkout.totalsRefresh();
// USPS START
$('#shownString, #customerString, #shownStringHide, #shownStringInfo, #customerStringHide, #customerStringInfo', el.parent().parent().parent()).hide();
$('#shownString, #customerString, #shownStringShow, #customerStringShow', el.parent().parent()).show();
// USPS END
}
});
},
// USPS START
addUspsServices: function(e)
{
var el = $(this);
$.ajax(
{
data: 'action=addUspsServices&shipping=usps_' + $(this).attr('id') + '&' + decodeURIComponent($('[type=checkbox]', $(this).parent().parent()).serialize()),
success: function (data){$('#shippingCost', el.parent().parent().parent().parent()).html(data.cost);}
});
},
// USPS END
FULL PACKAGE
This is the last version I plan on contributing until USPS changes their schema again.
ADDED:
Customer option to add extra services.
SUMMARY OF ALL OPTIONS:
1. Choose from all available domestic and international methods.
2. Charge retail or internet rates
3. Sort rates in ascending or descending order.
4. Min/Max weight threshold for each method.
5. Separate handling fee for each method.
6. Show or hide International shipping regulations to your international customers (only works in 2.3 shops)
7. Extra Services (with the following options)
a. Dont include
b. Include, combine with base rate and HIDE the breakdown from the customer.
c. Include, combine with base rate and SHOW the breakdown to the customer (only works in 2.3 shops)
d. Allow the customer to add the service (only works in 2.3 shops)
This contribution was written specifically for 2.3 shops. As with anything, it can be conformed to fit other shops.
Fix display:
FULL PACKAGE
For fix only, in modules/shipping/usps.php
Find:
'shownString' => $shownString);
Replace with:
'shownString' => (string)$shownString);
Compatibility Instructions
Simple Checkout for 2.3.1 v1.3
with
USPS Rate V4 Intl Rate V2 - v.1.6
ALL CHANGES ARE BEING MADE TO CHECKOUT.PHP
1.
Find:
echo ' <tr class="moduleRow shippingRow' . ($quotes[$i]['id'] . '_' . $quotes[$i]['methods'][$j]['id'] == $shipping['id'] ? ' moduleRowSelected' : '') . '"><td>' . $quotes[$i]['methods'][$j]['title'] . '</td>';
Replace with:
// USPS START
// echo ' <tr class="moduleRow shippingRow' . ($quotes[$i]['id'] . '_' . $quotes[$i]['methods'][$j]['id'] == $shipping['id'] ? ' moduleRowSelected' : '') . '"><td>' . $quotes[$i]['methods'][$j]['title'] . '</td>';
echo ' <tr class="moduleRow shippingRow' . ($quotes[$i]['id'] . '_' . $quotes[$i]['methods'][$j]['id'] == $shipping['id'] ? ' moduleRowSelected' : '') . '"><td width=80%>' . $quotes[$i]['methods'][$j]['title'] . (isset($quotes[$i]['methods'][$j]['shownString']) ? $quotes[$i]['methods'][$j]['shownString'] : '') . '</td>';
// USPS END
2.
Find:
shippingSet: function()
{
var el = $(this);
$.ajax(
{
data: 'action=shippingSet&shipping=' + $(this).val(),
success: function(data)
{
el.parent().parent().siblings().removeClass('moduleRowSelected');
el.parent().parent().addClass('moduleRowSelected');
checkout.totalsRefresh();
}
});
},
Replace with:
shippingSet: function()
{
var el = $(this);
$.ajax(
{
data: 'action=shippingSet&shipping=' + $(this).val(),
success: function(data)
{
el.parent().parent().siblings().removeClass('moduleRowSelected');
el.parent().parent().addClass('moduleRowSelected');
checkout.totalsRefresh();
// USPS START
$('#shownString, #shownStringHide, #shownStringInfo,', el.parent().parent().parent()).hide();
$('#shownString, #shownStringShow', el.parent().parent()).show();
// USPS END
}
});
},
A fix to the fix.
Only one method was showing.
Affected file:
usps.php
No changes - FIX ONLY
Affected files:
usps.php
checkout_shipping.php
FULL PACKAGE
Instructions for making this compatible with Dynamic Templates System found here:
http://addons.oscommerce.com/info/7691
In admin/modules.php
find:
case 'save':
reset($HTTP_POST_VARS['configuration']);
while (list($key, $value) = each($HTTP_POST_VARS['configuration'])) {
tep_db_query("update " . TABLE_CONFIGURATION . " set configuration_value = '" . $value . "' where configuration_key = '" . $key . "'");
}
Instead of normal instructions
replace with:
case 'save':
reset($HTTP_POST_VARS['configuration']);
while (list($key, $value) = each($HTTP_POST_VARS['configuration'])) {
// Dynamic Template System Start
if((is_array($value)) && (!empty($value)))
{
if (isset($set) && $set == "boxes")
{
$pages = '';
$count = count($value);
for($i=0 ; $i<$count; $i++)
{
$pages = "$pages$value[$i]";
tep_db_query("update " . TABLE_CONFIGURATION . " set configuration_value = '" . $pages . "' where configuration_key = '" . $key . "'");
}
}
else
{
// USPS START
$value = implode( ", ", $value);
tep_db_query("update " . TABLE_CONFIGURATION . " set configuration_value = '" . $value . "' where configuration_key = '" . $key . "'");
}
// USPS END
}
else tep_db_query("update " . TABLE_CONFIGURATION . " set configuration_value = '" . $value . "' where configuration_key = '" . $key . "'");
// Dynamic Template System End
}
Instructions for making this compatible with Dynamic Templates System found here:
http://addons.oscommerce.com/info/7691
In admin/modules.php, find:
case 'save':
reset($HTTP_POST_VARS['configuration']);
while (list($key, $value) = each($HTTP_POST_VARS['configuration'])) {
tep_db_query("update " . TABLE_CONFIGURATION . " set configuration_value = '" . $value . "' where configuration_key = '" . $key . "'");
}
Instead of normal instructions, replace with:
case 'save':
reset($HTTP_POST_VARS['configuration']);
while (list($key, $value) = each($HTTP_POST_VARS['configuration'])) {
// USPS START
if( is_array( $value ) ) $value = implode( ', ', $value);
// USPS END
// Dynamic Template System Start
if((is_array($value)) && (!empty($value)))
{
if (isset($set) && $set == "boxes")
{
$pages = '';
$count = count($value);
for($i=0 ; $i<$count; $i++)
{
$pages = "$pages$value[$i]";
tep_db_query("update " . TABLE_CONFIGURATION . " set configuration_value = '" . $pages . "' where configuration_key = '" . $key . "'");
}
}
else
{
// USPS START
$value = implode( ", ", $value);
tep_db_query("update " . TABLE_CONFIGURATION . " set configuration_value = '" . $value . "' where configuration_key = '" . $key . "'");
}
// USPS END
}
else tep_db_query("update " . TABLE_CONFIGURATION . " set configuration_value = '" . $value . "' where configuration_key = '" . $key . "'");
// Dynamic Template System End
}
No changes - FIX ONLY:
Wasn't working when only one domestic option was chosen.
If fixing only, then follow the below instructions. Otherwise, this is a full package.
in usps.php find:
for ($i=0; $i<($order->delivery['country']['iso_code_2'] == 'US' ? sizeof($uspsQuote['Package']) : sizeof($uspsQuote['Package']['Service'])); $i++)
{
$Services = array();
$shownServices = array();
$hiddenServices = array();
$hiddenCost = 0;
$shownCost = 0;
$shownString = '';
$types = explode(', ', MODULE_SHIPPING_USPS_TYPES);
if (tep_not_null($uspsQuote['Package'][$i]['Error'])) continue;
if ($order->delivery['country']['iso_code_2'] == 'US')
{
foreach ($uspsQuote['Package'][$i]['Postage']['SpecialServices']['SpecialService'] as $key => $val)
if (tep_not_null($dExtras[$val['ServiceName']]) && ((MODULE_SHIPPING_USPS_RATE_TYPE == 'Online' && $val['AvailableOnline'] == 'true') || (MODULE_SHIPPING_USPS_RATE_TYPE == 'Retail' && $val['Available'] == 'true')))
{
$val['ServiceAdmin'] = $dExtras[$val['ServiceName']];
$Services[] = $val;
}
$cost = MODULE_SHIPPING_USPS_RATE_TYPE == 'Online' && tep_not_null($uspsQuote['Package'][$i]['Postage']['CommercialRate']) ? $uspsQuote['Package'][$i]['Postage']['CommercialRate'] : $uspsQuote['Package'][$i]['Postage']['Rate'];
$type = ($uspsQuote['Package'][$i]['Postage']['MailService']);
}
else
{
foreach ($uspsQuote['Package']['Service'][$i]['ExtraServices']['ExtraService'] as $key => $val)
if (tep_not_null($iExtras[$val['ServiceName']]) && ((MODULE_SHIPPING_USPS_RATE_TYPE == 'Online' && $val['AvailableOnline'] == 'True') || (MODULE_SHIPPING_USPS_RATE_TYPE == 'Retail' && $val['Available'] == 'True')))
{
$val['ServiceAdmin'] = $iExtras[$val['ServiceName']];
$Services[] = $val;
}
$cost = MODULE_SHIPPING_USPS_RATE_TYPE == 'Online' && tep_not_null($uspsQuote['Package']['Service'][$i]['CommercialPostage']) ? $uspsQuote['Package']['Service'][$i]['CommercialPostage'] : $uspsQuote['Package']['Service'][$i]['Postage'];
$type = ($uspsQuote['Package']['Service'][$i]['SvcDescription']);
}
REPLACE WITH:
if (tep_not_null($uspsQuote['Package']['Postage'])) $PackageSize = 1;
else $PackageSize = ($order->delivery['country']['iso_code_2'] == 'US' ? sizeof($uspsQuote['Package']) : sizeof($uspsQuote['Package']['Service']));
for ($i=0; $i<$PackageSize; $i++)
{
$Services = array();
$shownServices = array();
$hiddenServices = array();
$hiddenCost = 0;
$shownCost = 0;
$shownString = '';
$types = explode(', ', MODULE_SHIPPING_USPS_TYPES);
$Package = ($PackageSize == 1 ? $uspsQuote['Package']['Postage'] : ($order->delivery['country']['iso_code_2'] == 'US' ? $uspsQuote['Package'][$i]['Postage'] : $uspsQuote['Package']['Service'][$i]));
if (tep_not_null($Package['Error'])) continue;
if ($order->delivery['country']['iso_code_2'] == 'US')
{
foreach ($Package['SpecialServices']['SpecialService'] as $key => $val)
if (tep_not_null($dExtras[$val['ServiceName']]) && ((MODULE_SHIPPING_USPS_RATE_TYPE == 'Online' && $val['AvailableOnline'] == 'true') || (MODULE_SHIPPING_USPS_RATE_TYPE == 'Retail' && $val['Available'] == 'true')))
{
$val['ServiceAdmin'] = $dExtras[$val['ServiceName']];
$Services[] = $val;
}
$cost = MODULE_SHIPPING_USPS_RATE_TYPE == 'Online' && tep_not_null($Package['CommercialRate']) ? $Package['CommercialRate'] : $Package['Rate'];
$type = ($Package['MailService']);
}
else
{
foreach ($Package['ExtraServices']['ExtraService'] as $key => $val)
if (tep_not_null($iExtras[$val['ServiceName']]) && ((MODULE_SHIPPING_USPS_RATE_TYPE == 'Online' && $val['AvailableOnline'] == 'True') || (MODULE_SHIPPING_USPS_RATE_TYPE == 'Retail' && $val['Available'] == 'True')))
{
$val['ServiceAdmin'] = $iExtras[$val['ServiceName']];
$Services[] = $val;
}
$cost = MODULE_SHIPPING_USPS_RATE_TYPE == 'Online' && tep_not_null($Package['CommercialPostage']) ? $Package['CommercialPostage'] : $Package['Postage'];
$type = ($Package['SvcDescription']);
}
ALSO, not relevant, but there was some extra unused code that can be deleted:
function addServices($val)
{
global $shipping;
mail(STORE_OWNER_EMAIL_ADDRESS, STORE_OWNER, $addServices);
}
FIXES:
None that I can remember.
ADDED OPTIONS:
So exciting.
1. Separate handling fee for each method.
2. Extra services (domestic and international)
ALL available services are shown. You have three options for EACH individual service.
a. Don't include.
b. Include and combine with base rate and HIDE the breakdown from the customer.
c. Include and combine with base rate and SHOW the breakdown to the customer so that they can see exactly what they are paying for.
NOTES: Breakdown can only be shown in 2.3.1 as it requires jquery. If you choose internet pricing, only services available with online labels will be added/shown. Vice versa, if you choose retail, then only services available at counters will be added/shown. There are NO online extra services for international shipping.
3. Show or hide International shipping regulations to your international customers. This info displays their country's restrictions, prohibitions, customs regulations, etc...
NOTE: International regulations can only be shown in 2.3.1 shops, as this requires jquery.
PREVIOUS OPTIONS STILL INTACT:
Weight Thresh-holds for ALL methods, including domestic AND international. This is a necessity when offering flat rate options.
Sorter
Ascending (low to high) or Descending (high to low)
Rate Type
Online (show commercial rates)
Retail (show counter rates)
NOTE: Regional rate boxes do not return retail rates as these can ONLY be shipped with labels printed online.
FULL PACKAGE
For update from previous versions, you'll want to go through the entire set of instructions.
FIXES:
Moved:
admin/includes/functions/general/general.php
to:
admin/includes/functions/general.php
(oops)
ADDED OPTIONS:
Weight Thresh-holds for ALL methods, including domestic AND international. This is a necessity when offering flat rate options.
PREVIOUS OPTIONS STILL INTACT:
Sorter
Ascending (low to high)
or
Descending (high to low)
Rate Type
Online (show commercial rates)
Retail (show counter rates)
NOTE: Regional rate boxes do not return retail rates as these can ONLY be shipped with labels printed online.
FULL PACKAGE
For update from previous versions, replace/update the following:
catalog/includes/modules/shipping/usps.php
admin/includes/functions/general.php
admin/modules.php
Uninstall and reinstall from admin panel to update settings.
FIXES:
Changed dimensions for international methods so that all methods are returned.
ADDED OPTIONS:
Sorter
Ascending (low to high)
or
Descending (high to low)
Rate Type
Online (show commercial rates)
Retail (show counter rates)
NOTE: Regional rate boxes do not return retail rates as these can ONLY be shipped with labels printed online.
FULL PACKAGE
For update from v1.0, replace the following:
catalog/includes/modules/shipping/usps.php
USPS Rate V4 Intl Rate V2
This is a clean and simple module, intended to perform it's function efficiently and simply, without any frills or gimmicks.
All domestic and international methods (regular, flat rate, and regional) are included, and you have the choice of which methods to offer your customers.
Donations can also be sent through PayPal to the same addy and are very appreciated.
