4

I'm using the Commerce framework. I'm trying to understand exactly how "Order Types" and "Order Item Types" work. (I've consulted the docs; they don't really address this question.)

So far, I've deduced that:

  • The Checkout Flow that Drupal uses is determined by the Order Type that's in play.
  • Every Order has an Order Type.
  • Every Order Item has an Order Item Type.
  • Every Order Item Type belongs to an Order Type.

...but that's as far as I've gotten. I'm trying to understand:

  • What rules does Drupal use to decide which Order Type it's dealing with? (That is, how does it know which Order Type is in play?)
  • At what point in the is this decision made? (When the user first adds an item to their cart? When they begin the checkout process? At some other point?)

Thanks!

0
1

To pose my question a bit differently: using only the Drupal web dashboard, how can I configure Drupal to use a particular checkout flow in a particular scenario?

From a UI perspective, here is how it works:

  1. Product Type -- Points to a Product Variation Type.

  2. Product Variation Type -- Points to an Order Item Type.

  3. Order Item Type -- Points to an Order Type.

  4. Order Type -- Points to a checkout flow and workflow.

  5. Checkout Flow

Side Note: When creating these you should do it in reverse order, as for example 1. depends on 2. to be created already.

So when you add a product to the cart, Drupal checks the chain from 1 to 4.

If at 4. product A has a different Order Type than Product B then a separate cart is created. Even if both order types have the same checkout flow and workflow.

Now when you go to /cart you should see two separate carts.

enter image description here

Note: There is a bug where it doesn't display the Product name on the top cart, you can get around it by adding order item title to the cart form view, as I did, as you can see in the last column.

So whichever you decide to checkout, that workflow is used and for that particular cart. Which means you would have to checkout two separate times in order to buy product A and B in this scenario.

1
  • 1
    THANK YOU! I spent five hours yesterday clicking around the admin, poring over ERDs, making my own diagrams, etc. You explained it in a couple of paragraphs. I'll mark this as the accepted answer once I've had a chance to play with it a bit. Dec 22 '20 at 13:49
2

What rules does Drupal use to decide which Order Type it's dealing with?

That's determined by order type resolvers (implementing OrderTypeResolverInterface in this case). Such resolvers are given an order item, and must use that to determine the type of order.

Out of the box, the default resolver (DefaultOrderTypeResolver) uses the bundle of the given order item, which will be an order item type ID, to load that item type entity, and get the associated order type ID from it.

At what point in the is this decision made?

There are probably multiple places that decision is made (creating orders in the admin UI for example), but in terms of the cart, it happens when the cart is created, which in turn happens when an item is first added to it via the standard AddToCartForm submission.

So I think it's fair to say that the type of an order that originated from a cart will always be the type associated with the first item that was added to it.

1
  • Thanks for the reply. However, I'm afraid this is a bit over my head. I'm not writing any custom code – I'm just using the commerce modules out of the box. To pose my question a bit differently: using only the Drupal web dashboard, how can I configure Drupal to use a particular checkout flow in a particular scenario? (I'm not trying to achieve any specific goal at the moment. I'm just trying to understand how the pieces fit together.) Dec 21 '20 at 21:07

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.