1

I have setup a Drupal Commerce website (using Drupal 7) with two shipping options:

  1. Delivery by courier company
  2. Pickup from store

The next step in checkout process is to choose the payment method. BUT... if the second choice (pickup from store) is chosen, the only available payment method is Pay at store (offline payment). I have managed to show only this option through Rules. So far so good.

My concern is that for better user experience I have to make this step skipped. So after the Shipping step where the user selects the Pickup from store option, the next logical step is the Review pane for a final review by the user before complete the checkout process.

I have read that the Payment selection method (checkout step) is required for the Payment Redirection (I fail to understand it).

I have already tried to use hook_commerce_checkout_router, checking the $order shipping line and use the drupal_goto function redirect to the review page. My custom function is the following:

function <myModule>_commerce_checkout_router($order, $checkout_page) {
  global $user;

  if ($checkout_page['page_id']=='checkout') {
    if (!empty($order->commerce_order_total['und']['0']['data']['components']['2']) && ($order->commerce_order_total['und']['0']['data']['components']['2']['name']=='flat_rate_from_store')) {
      drupal_goto('checkout/' . $order->order_id . '/' . $checkout_page['next_page']);
    }
  }
}

I get error "The page isn’t redirecting properly". It is the same result as if someone is at the shipping step and manually tried to enter at the url the /review.

Do you think is possible to achieve skipping this step to speed up the checkout process or I have to give up trying ? At year 2017 it is very important to give a user the best and the most logical way to move around in a website. Useless steps and clicks slow down the process and maybe end in frustration.

1 Answer 1

2

The problem is you're redirecting without also updating the order's status. The checkout router determines access to a checkout page by matching the order status to the URL, and it will prevent access to any page the order doesn't appear to have reached yet.

In your case, you should just use the same API function the Payment module uses when it needs to redirect past the off-site payment redirect page because an on-site payment method was used. The function is commerce_payment_redirect_pane_next_page() and you can view the function signature and docs in commerce_payment.module.

2
  • Your help is at the right direction @ryan-szrama. I don't know if i am at the right direction! I copy the commerce_payment_redirect_pane_next_page and create myModule_redirect_pane_next_page call it before drupal_goto function and it seems that works. But having the post #1 code above, the review page (my next page) is shown either Next button, either Go Back button... How can i call redirect_pane_next_page on Next button and redirect_pane_previous_page on Back button ?
    – PERIPC
    Commented Jun 11, 2017 at 22:58
  • I don't really follow, to be honest. This approach should let you skip pages you need to once the router tries to load them. If you need to interrupt the process to work through the next / previous buttons, you'd alter the checkout form to supply your own button submission logic. Commented Jun 13, 2017 at 0:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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