You are here

function commerce_registration_commerce_checkout_router in Commerce Registration 7.2

Implements hook_commerce_checkout_router().

Skips the registration form step if there are no registration enabled product line items in the cart.

File

./commerce_registration.module, line 1746
Commerce Registration module code.

Code

function commerce_registration_commerce_checkout_router($order, $checkout_page) {

  // Check for registration checkout page.
  if ($checkout_page['page_id'] === "registration") {
    $registration_required = FALSE;
    $order_wrapper = entity_metadata_wrapper('commerce_order', $order);

    // Loop through line items.
    foreach ($order_wrapper->commerce_line_items as $line_item_wrapper) {
      if (!in_array($line_item_wrapper->type
        ->value(), commerce_product_line_item_types())) {
        continue;
      }
      $product_id = (int) $line_item_wrapper->commerce_product->product_id
        ->value();
      if (commerce_registration_product_has_registration_field($product_id) && registration_status('commerce_product', $product_id, TRUE) == 1) {

        // Registration field found so stay on the page.
        $registration_required = TRUE;
        break;
      }
    }

    // No registration found.
    if (!$registration_required) {

      // Update order status.
      $order = commerce_order_status_update($order, 'checkout_' . $checkout_page['next_page'], FALSE, TRUE, t('Registration not required for these products. Skipping this checkout step.'));

      // Go to the next page in checkout.
      drupal_goto('checkout/' . $order->order_id . '/' . $checkout_page['next_page']);
    }
  }
}