The checkout module provides a default status for the Checkout order state. This is done by building the checkout pages and returning the first page ID key. The consequence of this involves building the checkout page info definitions, which also involves the alters for this. It then builds all checkout panes and their alters as well. That's a lot for just wanting to know the default status.

  $order_states['checkout'] = array(
    'name' => 'checkout',
    'title' => t('Checkout'),
    'description' => t('Orders in this state have begun but not completed the checkout process.'),
    'weight' => -3,
    'default_status' => 'checkout_' . commerce_checkout_first_checkout_page(),
  );

I'm proposing a variable called "commerce_checkout_first_checkout_page" that can be set to programmatically define the first checkout page ID in commerce_checkout_first_checkout_page(). I don't think we need an invoke or alter here. It's just a performance item for implementations that require a lot of alter logic for the checkout pages and it's being called when not needed to just to built order state and status info.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mglaman created an issue. See original summary.

mglaman’s picture

Status: Active » Needs review
FileSize
868 bytes

Here's the patch. If the variable is not set it defaults to key(commerce_checkout_pages(). Maybe we could expose this on the checkout settings form, though. It could be a select list of "Automatic based on first page" or a specific page. It's more of an advanced item that might just deserve developer documentation.

Status: Needs review » Needs work

The last submitted patch, 2: provide_a_way_to_define-2633648-2.patch, failed testing.

mglaman’s picture

Status: Needs work » Needs review
FileSize
1.02 KB
1.87 KB

Here's an updated patch with a test added.

mglaman’s picture

FileSize
1.86 KB

Whoops, synxtax error.

The last submitted patch, 4: provide_a_way_to_define-2633648-3.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 5: provide_a_way_to_define-2633648-5.patch, failed testing.

mglaman’s picture

Assigned: Unassigned » mglaman

Talked it over with rszrama. The idea will be to change commerce_checkout_first_checkout_page() to invoke page info and alter and get the key, bypassing the checkout pane logic and sorting.

    $checkout_pages = module_invoke_all('commerce_checkout_page_info');
    drupal_alter('commerce_checkout_page_info', $checkout_pages);
    return key($checkout_pages);
mglaman’s picture

Status: Needs work » Needs review
FileSize
2.12 KB
1.56 KB

Here's a shot at idea from #8. Also updated test to make sure the static cache of panes is empty, showing we bypassed their init for just checking order state info.

Status: Needs review » Needs work

The last submitted patch, 9: provide_a_way_to_define-2633648-9.patch, failed testing.

mglaman’s picture

Status: Needs work » Needs review
FileSize
1.56 KB

This is what I get for trying to write a patch quick. Fix syntax.

mglaman’s picture

Status: Needs review » Needs work
+++ b/modules/checkout/commerce_checkout.module
@@ -478,7 +478,12 @@ function commerce_checkout_pages() {
+  $checkout_pages = module_invoke_all('commerce_checkout_page_info');
+  drupal_alter('commerce_checkout_page_info', $checkout_pages);
+  uasort($checkout_pages, 'drupal_sort_weight');

This doesn't work because there might not be a weight.

mglaman’s picture

Status: Needs work » Needs review
FileSize
1.76 KB

Here is a new approach that provides a hook to define the default page key.

function hook_commerce_checkout_first_checkout_page() {
  return 'payment';
}

The above code would allow me to ensure an order ends up on Checkout: Payment immediately and no need to fiddle with the checkout router, either. So this is a bonus option beyond performance!

mglaman’s picture

Issue tags: +commerce-sprint
joelpittet’s picture

Status: Needs review » Reviewed & tested by the community

yes please, this has a nice rabbit hole.

joelpittet’s picture

rszrama’s picture

Status: Reviewed & tested by the community » Needs work

Ahh, shoot. This actually needs a re-roll b/c of #2430337: HHVM incompatibility, but it'll let us make sure we preserve the HHVM compatibility.

joelpittet’s picture

Assigned: mglaman » Unassigned
Status: Needs work » Needs review
FileSize
1.79 KB

Re-rolled.

mglaman’s picture

Status: Needs review » Reviewed & tested by the community

I say, back to RTBC! Test pass, nothing changed in patch.

  • rszrama committed b26cbd1 on 7.x-1.x authored by mglaman
    Issue #2633648 by mglaman, joelpittet, rszrama: allow the first checkout...
rszrama’s picture

Status: Reviewed & tested by the community » Fixed

Touched up the comments and changed "page key" to "page ID" to keep in line with the rest of the module.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.