You are here

function commerce_cart_checkout_router in Commerce Core 7

Redirects invalid checkout attempts or displays the checkout form if valid.

1 string reference to 'commerce_cart_checkout_router'
commerce_cart_menu in modules/cart/commerce_cart.module
Implements hook_menu().

File

modules/cart/includes/commerce_cart.pages.inc, line 12
The page and form callbacks for use by the shopping cart.

Code

function commerce_cart_checkout_router() {
  global $user;

  // Load the shopping cart order.
  if ($order = commerce_cart_order_load($user->uid)) {
    $wrapper = entity_metadata_wrapper('commerce_order', $order);
  }

  // If no shopping cart order could be found, redirect away from checkout.
  // TODO: Redirect to the cart page instead which would then appear as an
  // empty shopping cart page.
  if (empty($order) || commerce_line_items_quantity($wrapper->commerce_line_items, commerce_product_line_item_types()) == 0) {
    drupal_set_message(t('Add some items to your cart and then try checking out.'));
    drupal_goto(variable_get('commerce_checkout_empty_redirect', ''));
  }
  drupal_goto('checkout/' . $order->order_id);
}