I love how in commerce you can decide on which pages your panes should appear.

The problem, however, is that you can only set up 1 single track of a checkout process.

In my case. I need to have a single page checkout for donations, and then a multi-page checkout for normal cart items, and an additional multi-page experience for orders.

Although I was able to use hook_commerce_checkout_page_info(), hook_commerce_checkout_pane_info() and hook_commerce_checkout_router() to address the latter needs, the former (single page donations) is not solvable by these means.

I also tried hook_form_alter to try to glue in additional panes if the order was a donation.. but no dice.

It is currently not possible to dynamically re-arrange panes based on order properties, query strings or other contexts. This is not possible because the "page_id" property of each pane is a singular value that is set once and cached.

You could alter each pane's page_id with the pane_alter function, but not dynamically. You can only do this once on your site's cache clear.. which makes sense if you only wanted to ever show that pane on one page.

commerce_checkout_form and commerce_checkout_form_validate then both run this loop:

foreach (commerce_checkout_panes(array('enabled' => TRUE, 'page' => $checkout_page['page_id'])) as $pane_id => $checkout_pane) {

This locks each use of the form to this singluar, cached page_id property.

I tried using hook_form_alter to get around this but ultimately could not. I ended up re-writing large amounts of form code in order to produce a single-page all panes checkout page for donations that can run along side a standard multi-page process configured in commerce.

I was thinking about putting forth a module to the community that would allow you to create landing pages for single page checkouts. You could use a UI to manage which panes should appear on this single page.

I then started to think it would be cool if you could create multiple variations of the settings set on admin/commerce/config/checkout

You could have multiple checkout experience, each tied to a specific base URL:
'/checkout/%' for default
'/donation/%' for the donation process
'membership/%' for signing up for a membership, etc.

I think it would be pretty straightforward to accomplish this if those loops in commerce_checkout_form and commerce_checkout_form_validate were not specifically calling in panes by a singular, unalterable (after its cached) 'page_id' property.

Perhaps the code be altered to allow an alter function in there.. like this:

  // Add any enabled checkout panes for this page to the form.
  foreach (commerce_checkout_checkout_panes($checkout_page) as $pane_id => $checkout_pane) {

and then add

function commerce_checkout_checkout_panes($checkout_page) {
  $panes = commerce_checkout_panes(array('enabled' => TRUE, 'page' => $checkout_page['page_id']));
  drupal_alter('commerce_checkout_checkout_panes', $checkout_page, $panes);
  return $panes;
}

It would be a minor alteration to commerce that could open up some room for (among other things) this crazy split checkout process i'm dreaming of...

what do you think?

Comments

tmsimont’s picture

Title: Allow dynamic cart processes » Allow dynamic cart page to cart pane relationships with new hook

better title