type:
snippet
category:
shipping
name:
Live shipping rates with a fixed rate fall back for heavy shipments
versions:
0.6.0, 0.7.0, 0.7.1, 0.7.2, 1.0
reference:
http://forum.foxycart.com/comments.php?DiscussionID=1789&page=2#Item_17
tags:
snippets, shipping, advance
date:
2011-05-27

Live shipping rates with a fixed rate fall back for heavy shipments

Versions 0.7.1 and older: Note that applying javascript shipping modifications using either live or flat rates where you are setting custom values has been found to not work as expected for subscription based products where you need the shipping to apply to each subscription renewal. A fix is in place for versions 0.7.2 and newer.

Using version 2.0? There is a new snippet available for our latest version, available from here.

This script is designed to run after the shipping rates are returned - specifically with an error. A second script provided below is run each time the shipping rates return, but work with the 'free ground shipping' option enabled. The script runs whenever only the free ground shipping option is returned (meaning that the live shipping rates weren't able to ship that order). Paste either option just before the closing </head> tag of your checkout template.

<script type="text/javascript">
jQuery(document).ajaxComplete(function(event, request, settings) {
  if (settings.url.indexOf('GetShippingCost') != -1) {
    if (request.responseText.indexOf('Error') != -1) {
      // Do whatever you want in here
      alert('error');
    }
  }
});
</script>

You can add anything you want within that code, and it will only be run when the shipping rate requests returns with an error.

With the following option, you need to enable “Free Ground Shipping” option within the shipping section of the administration. You can rename those options to be whatever you like from within the language section also - so it could be “Large Shipment Fee” or similar.

<script type="text/javascript">
var customFlatRate = 100;
jQuery(document).ajaxComplete(function(event, request, settings) {
  if (settings.url.indexOf('GetShippingCost') != -1) {
    if (jQuery("#fc_shipping_methods_inner").length == 1) {
      jQuery("#shipping_service_59").val('59|'+customFlatRate);
      jQuery("#fc_shipping_methods_inner .fc_shipping_cost").html('<span class="fc_shipping_cost"><span class="fc_currency_symbol">$</span>'+customFlatRate+'</span>');
    } else {
      jQuery("label[for=shipping_service_59]").remove();
    }
  }
});
</script>

This code works by checking the returned shipping results. If only one option is returned, it will be our 'free' option as it doesn't have any restrictions like weight or destination that the live rate carriers do. This custom option is set to whatever is set for the customFlatRate variable at the top of the script. If other options are returned with the shipping, the free option is removed to prevent people selecting it.

Site Tools