getShippingMethods (JS API v2)

Version 2 API only.

getShippingMethods

Method Signature

[ShippingEstimate] ultraCart.getShippingMethods();

Description

Retrieves available shipping methods. This list may change as address information is filled in, so call this method repeatedly rather than storing the result locally to ensure the cart page is always accurate.

Result

an array of ShippingEstimate objects representing all the shipping methods currently available to the customer based on their item selection and address location.

function renderShipping() {
  var c = ultraCart.getCart();
  var choice = ultraCart.getShippingChoice();
  var methods = ultraCart.getShippingMethods();

  // if no default, select the first one.  should be the cheapest.
  if (!choice && methods && methods.length) {
    choice = methods[0].name;
  }

  // unbind any existing options before overwriting to avoid leaks.
  jQuery('[name=shippingMethod]').unbind('.ultraCart');

  if (methods) {
    var html = '';
    for (var i = 0; i < methods.length; i++) {
      var checked = (choice && choice.name && methods[i].name && choice.name == methods[i].name);

      html += "<div class='shippingMethod'>";
      html += "<div class='shippingName'>";
      html += "<input class='shippingField' name='shippingMethod' type='radio' value='" + methods[i].name + "' " + (checked ? "checked='checked'" : "") + " />";
      html += methods[i].displayName;
      html += "<\/div><div class='shippingPrice'>";
      html += nf.toCurrency(methods[i].cost);
      html += "<\/div><div style='clear:both'></div></div>";
    }
  }

  jQuery('#shippingMethods').html(html);
  jQuery('[name=shippingMethod]').bind('click.ultraCart', chooseShipping);

}