You are here

function commerce_usps_validate_order in Commerce USPS 7.2

Validate that the order can return a successful rate request.

Parameters

object $order: The order object.

Return value

bool Returns TRUE if the order passes validation.

1 call to commerce_usps_validate_order()
commerce_usps_rate in ./commerce_usps.module
Returns a base price array for a shipping service calculated for the order.

File

./commerce_usps.module, line 114
Defines the USPS shipping method and services for Drupal Commerce.

Code

function commerce_usps_validate_order($order) {
  $shipping_address = commerce_usps_get_order_shipping_address($order);

  // We have to have a shipping address to get rates.
  if (empty($shipping_address)) {
    return FALSE;
  }

  // US shipping addresses require a zipcode.
  if ($shipping_address['country'] == 'US' && empty($shipping_address['postal_code'])) {
    return FALSE;
  }

  // Make sure the order is shippable.
  if (!commerce_usps_get_order_weight($order)) {
    return FALSE;
  }
  return TRUE;
}