2

So I thought I had been pretty clever when in the code for a custom checkout pane, in a custom checkout page, I did this:

function checkout_pane_giftaid_pane_checkout_form($form, &$form_state, $checkout_pane, $order) {
  if($showPane==1){
    //show something awesome
  }
  else {
    $checkout_pages = commerce_checkout_pages();
    commerce_order_status_update($order,'checkout_payment');
    $url = 'checkout/'. $order->order_number  . '/' . $checkout_pages['gift-aid']['next_page'];
    drupal_goto($url);
  }
}

If showPane is equal to 1 it displays the Pane's content, if not it directs you to the next checkout page. This however has presented an issue because I have two custom checkout pages.

The result of this is if you are on 'custom page 2' and press 'Go Back' it goes back to the previous page ('custom page 1'), but if $showPane=0 on this page then the else statement means its set to forward. So a user hits 'go back' on 'custom page 2' and what they see, is this page reload (actually it has gone back to 'custom page 1' where it is told to go to the next page, 'custom page 2').

So my question is this: clearly I have not gone about 'skipping' custom checkout pages in the right way, how would I do it properly?

  • 1
    Would the 'correct' way not be to remove the checkout panes from pages you don't want to show at admin/commerce/config/checkout? If I remember rightly a page that doesn't contain panes won't be shown in the checkout process – Clive Dec 21 '12 at 9:37
  • Hey @Clive sorry should have explained, the Panes showing are dependent on what's in the user's cart. So both should always be live on the site, but obviously depending on cart items, normally only one or the other would show. (One is for gift aid when someone makes a donation, the other is extra fields for when tickets are purchased). Further they need to be on checkout separate pages also, as I have a checkout stage progress bar that dynamically populates for 'gift aid', and 'ticket information'. – Scott Lawrence Dec 21 '12 at 9:38
  • 1
    Sounds like a nice complex workflow :) I don't have time to dig into it right now but have a look at how Commerce Checkout Redirect does the same thing, I'm sure it'll give up some secrets – Clive Dec 21 '12 at 12:06
7

You can use hook_commerce_checkout_router() to skip Commerce Checkout pages.

See the advanced example here: Skipping a Commerce Checkout page in the checkout workflow

/**
 * Implements hook_commerce_checkout_router().
 *
 * Skip the registration checkout page unless required.
 */
function MYMODULE_commerce_checkout_router($order, $checkout_page) {
  global $user;

  if ($checkout_page['page_id'] == 'registration' && $user->uid) {
    $registration_required = FALSE;
    $order_wrapper = entity_metadata_wrapper('commerce_order', $order);
    foreach ($order_wrapper->commerce_line_items as $line_item_wrapper) {
      $line_item = $line_item_wrapper->value();
      if ($line_item->line_item_label == 'Conference Attendee') {
        $registration_required = TRUE;
        break;
      }
    }
    if (!$registration_required) {
      $order = commerce_order_status_update($order, 'checkout_' . $checkout_page['next_page'], FALSE, TRUE, t('Conference Registration was skipped - not required for these products.'));
      drupal_goto('checkout/' . $order->order_id . '/' . $checkout_page['next_page']);
    }
  }
}
  • This. This is the correct way to do it. – Piers Aug 28 '14 at 15:29
0

You may try to use Commerce Express Checkout module.

The Express Checkout button redirects to the Checkout page directly, without going to the Cart first, It also removes the Review page and adds the Payment checkout pane to the Checkout page, so the whole checkout process is done on one page.

Alternatively you can edit one of the existing commerce views e.g. commerce_cart_form or commerce_cart_summary and develop the skip there.

0

This is the same answer that milkovsky posted but is a little more generic; it checks if any of the line items reference products that have registration:

if ($checkout_page['page_id'] == 'registration') {
    module_load_include('inc', 'commerce_registration', 'commerce_registration.rules');

    $registration_required = FALSE;
    $order_wrapper = entity_metadata_wrapper('commerce_order', $order);
    foreach ($order_wrapper->commerce_line_items as $line_item_wrapper) {
      $line_item = $line_item_wrapper->value();
      if (commerce_registration_order_has_registration($line_item)) {
        $registration_required = TRUE;
        break;
      }
    }
    if (!$registration_required) {
      $order = commerce_order_status_update($order, 'checkout_' . $checkout_page['next_page'], FALSE, TRUE, t('Registration was skipped - not required for these products.'));
      drupal_goto('checkout/' . $order->order_id . '/' . $checkout_page['next_page']);
    }
  }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.