startSectionEdit: $data "plugin_data" is NOT an array! One of your plugins needs an update.
type:
snippet
category:
shipping
name:
Dimensional weights
versions:
0.6.0, 0.7.0, 0.7.1, 0.7.2, 1.0
reference:
http://forum.foxycart.com/comments.php?DiscussionID=1988&page=1
tags:
snippets, shipping, advance
date:
2011-05-27

Dimensional weights

The context is this: we use USPS priority and express for shipping both domestically and internationally, and in a wide range of object sizes. (Not many different objects, but both tiny and inexpensive and huge and expensive.) For domestic addresses, the priority mail and express mail price estimates are reasonably fair, and scale pretty well. But for international, it can get absurd quickly. A tiny $5 object, priced with regular priority mail to the UK costs $26– a bit absurd. It would fit in a flat rate for about $13, but since we ship giant things too, we need some way to separate which objects fit into which packages.

The method is to add a product option to each small item, which I called “sizecode.” An item with sizecode=1 completely fills a USPS flat rate envelope; an item with sizecode=.25 takes up one quarter of a flat rate envelope. We further assume that a USPS priority mail flat rate box can fit four times as much as the envelope. (Note: you can use different assumptions if you like.) The presence of the sizecode option in the cart and checkout page can be hidden through javascript (051 and earlier) or CSS (060+). If any object in the cart does not have the sizecode option specified, the whole game is off– we assume that it won't fit in a small package.

Then, in the FoxyCart admin, we enable USPS domestic priority and express, plus the following five methods: * USPS Express Int'l (package). * USPS Express Int'l flat rate envelope. * USPS Priority Int'l flat rate envelope. * USPS Priority Int'l flat rate box (medium). * USPS Priority Int'l package.

The script, added to the checkout template, is as follows:

<script type = "text/javascript"charset = "utf-8" >
var myCustomShipping = function() {
 
jQuery("label[for='shipping_service_34']").hide();	// USPS Express Int'l package.
jQuery("label[for='shipping_service_35']").hide();	// USPS Express Int'l flat rate envelope.
jQuery("label[for='shipping_service_37']").hide();	// USPS Priority Int'l flat rate envelope.
jQuery("label[for='shipping_service_38']").hide();	// USPS Priority Int'l flat rate box (medium).
jQuery("label[for='shipping_service_40']").hide();	// USPS Priority Int'l package.
 
var shipmentSize = 0;
var Var="sizecode"
for (i in fc_json.products) {
if(Var in fc_json.products[ i ].options)
shipmentSize += fc_json.products[ i ].quantity * parseFloat(fc_json.products[ i ].options.sizecode);
else
shipmentSize = 1000;
}
 
if (shipmentSize <= 1 ) {
jQuery("label[for='shipping_service_35']").show();	//Allow USPS Express Int'l flat rate envelope.
jQuery("label[for='shipping_service_37']").show();	//Allow USPS Priority Int'l flat rate envelope.
}
else if (shipmentSize <= 4 ) {
jQuery("label[for='shipping_service_34']").show();	//Allow USPS Express Int'l package.
jQuery("label[for='shipping_service_38']").show();	//Allow USPS Priority Int'l flat rate box (medium).
jQuery("label[for='shipping_service_40']").show();	// USPS Priority Int'l package.
}
else
{
jQuery("label[for='shipping_service_34']").show();	//Allow USPS Express Int'l package.
jQuery("label[for='shipping_service_40']").show();	// USPS Priority Int'l package.
}
 
}
 
jQuery(document).ready(function() {
jQuery(document).ajaxComplete(function(event, request, settings) {
myCustomShipping();
});
});
</script>

If the package is small enough– under 1 “flat rate envelopes” worth of volume, then USPS Priority and Express flat rate envelope options are allowed. If it's under 4 “flat rate envelopes” worth of volume, then the USPS priority “medium” flat rate box is shown. And otherwise, it shows the standard priority and express rates. One potential concern is that if you show all five rates allowed for that under-one-envelope package, it's a lot of clutter on the page– five options to choose from!– so we actually only show a maximum of three rates at the same time. (Interestingly, in the 1-4 envelope range, Priority International is sometimes cheaper and sometimes more expensive than the Priority International flat rate box.)

Site Tools