Over at Commerce License, we have a problem with the availability checker unable to tell the difference between these two situations:

- the customer is attempting to purchase a product and availability is being checked
- a Commerce Recurring recurring order is being processed and availability is being checked

-- see https://www.drupal.org/project/commerce_license/issues/2933291#comment-1... for more detail.

At the moment, short of poking around in the backtrace (!!!) to check whether it's Commerce Recurring doing the order processing, I don't see how Commerce License can distinguish.

I think the best fix would be if the Context object could additionally take a parameter for the current $order.

Comments

joachim created an issue. See original summary.

bojanz’s picture

The whole point of the context object is to use it when the $order is not available (on product pages for example), otherwise we'd just pass the $order everywhere.

So we'll need to figure out an alternative. I'll give it some thought.

joachim’s picture

> The whole point of the context object is to use it when the $order is not available (on product pages for example), otherwise we'd just pass the $order everywhere.

In this situation, we need to know:

- is the availability being checked without an order (on product pages), or for an order refresh?
- if it's for an order, what's the type?

I can see that being something that the availability system generally needs to know.

Eg, a ticket sales website would want to consider that tickets in a cart are no longer available, so it doesn't more tickets than exist. So for that, your AM would report all the tickets are gone while some tickets are in cart or checkout. But you would not want the order refresh process that fires in checkout to use that, and remove the tickets from that customer's cart!

joachim’s picture

Title: Context object should also have the order » AvailabilityManager needs to be aware of the order, if there is one
Category: Feature request » Task
daniel korte’s picture

Status: Active » Needs review
StatusFileSize
new809 bytes

How about something like this?

Status: Needs review » Needs work

The last submitted patch, 5: 2937041-add-order-type-context-5.patch, failed testing. View results

andyg5000’s picture

I had the same issue with tax resolvers and Bojanz shot that down too :)

There's clearly a problem and modules are relying on backtrace for availability conditions.

I don't see why we can't pass it if it's available. We just need to make sure the modules extending it know that it's not always available in the documentation I guess.

Seems like we should pass the full object too because I'm sure there will be other use cases beyond the order type.

mglaman’s picture

Assigned: Unassigned » mglaman

Discussed various approaches with @jsacksick. The basic implementation will be: the $data object for the context will contain the order item. This is the least invasive option for backward compatibility. It's not my first choice, but it's what we have to do. I'll be updating this issue with the next steps and related issues.

mglaman’s picture

mglaman’s picture

I opened #3138667: Provide low-level interfaces for orders and order items. This is a large ambitious and possibly bad idea to create interfaces for orders and order items like PurchasableEntityInterface, which makes it easier for the availability manager to "know" about order items.

mglaman’s picture

So we have three options:

  1. Implement the new interfaces in #10. We then provide a AvailabilityOrderItemAwareInterface to set the order item, if available on the availability manager and checks when implemented. This is what the tax subsystem does when the tax type must be known. It could be confusing because we now have two OrderInterface and OrderItemInterface
  2. We know that an order item is available, within Commerce, whenever we invoke the availability manager. Just shove the order item into the context $data array.
  3. @jsacksick is proposing we deprecate the current availability manager and make a new one inside of the order module, which requires an order item and not purchasable entity
jsacksick’s picture

So the different approach can be found in #3138952: Make the AvailabilityManager order aware.

mglaman’s picture

Status: Needs work » Closed (outdated)

🥳

Fixed in #3138952: Make the AvailabilityManager order aware, which leverages a more robust AvailabilityManager API. See it's change record for details.