1

I've tried finding a solution to this myself, but have so far been very unlucky in that regard.
To save you checking the tags, this question is about:

  • Drupal Commerce 8.x-2.0-beta6
  • Drupal 8.2.7

Question I want different checkout flows on different products, and while I can find plenty of documentation on how to create these, I cannot find anywhere, how you tell the product which flow it should use.

I have tried searching, going to every commerce backend page on my install, searching through the questions here, and looked at commit messages in the hope that they would shed light on it.

Can anyone help me with this? I would greatly appreciate it.

Thanks in advance.

1

You need to implement a checkout flow resolver.

Look at the default resolver for an example: https://github.com/drupalcommerce/commerce/blob/8.x-2.x/modules/checkout/src/Resolver/DefaultCheckoutFlowResolver.php And don't forget the matching services.yml entry: https://github.com/drupalcommerce/commerce/blob/8.x-2.x/modules/checkout/commerce_checkout.services.yml#L7 (You don't need to set the priority on yours though, it's -100 here so that DefaultCheckoutFlowResolver runs last)

0

Although above answer is marked I will give more verbose info. You need to make a resolver service so it can "hook" into commerce_checkout.checkout_flow_resolver service collector

  commerce_checkout.chain_checkout_flow_resolver:
    class: Drupal\commerce_checkout\Resolver\ChainCheckoutFlowResolver
    tags:
      - { name: service_collector, call: addResolver, tag: commerce_checkout.checkout_flow_resolver }

, how that works, you can find here more about it. https://www.drupal.org/docs/8/api/services-and-dependency-injection/service-tags

Once you have that and resolver uses your service instead of default one(works on first come first serve basis), you will be able to make custom flow depending on your code, for example in your resolve method you could have something like this

if ($free && $numerical) {
  return CheckoutFlow::load('direct');
}
// If numerical product but non free, go to to the download checkout
elseif (!$free && $numerical) {
  return CheckoutFlow::load('download');
}

there is a good example how to do that here in this tutorial https://www.flocondetoile.fr/blog/working-drupal-commerce-2-checkout-flows

and more on commerce resolvers can be found here https://docs.drupalcommerce.org/commerce2/developer-guide/core/understanding-resolvers

EDIT: Also to acutally use a resolver you need to either create it in UI https://docs.drupalcommerce.org/commerce2/developer-guide/checkout/create-custom-checkout-flow

or add it into config/install, check here for example https://www.drupal.org/project/commerce_stripe_payment_request_button

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.