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
Comment #2
bojanz commentedThe 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.
Comment #3
joachim commented> 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!
Comment #4
joachim commentedComment #5
daniel korteHow about something like this?
Comment #7
andyg5000I 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.
Comment #8
mglamanDiscussed 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.
Comment #9
mglamanComment #10
mglamanI 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.
Comment #11
mglamanSo we have three options:
AvailabilityOrderItemAwareInterfaceto 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 OrderItemInterfaceComment #12
jsacksick commentedSo the different approach can be found in #3138952: Make the AvailabilityManager order aware.
Comment #13
mglaman🥳
Fixed in #3138952: Make the AvailabilityManager order aware, which leverages a more robust AvailabilityManager API. See it's change record for details.