Followup to #2506163: Complete the initial product architecture.

Also needed for the add to cart form.

Commerce 1.x has no API for determining if a product is available. This means that modules such as commerce_stock need to register various different validation handlers (on the different add to cart forms) to be able to prevent a product from being added to the cart.
There's also the "Set the product price to NULL from a pricing rule" way of doing it, but it's bad DX.

Solution:
- AvailabilityCheckerInterface (with a check($variation, $quantity) method) -> implemented by services tagged with commerce_product.availability_checker.
The check returns TRUE (available), FALSE (not available), or NULL (no opinion).
We should replace these with value objects later, allowing the return values to be expanded in the future without breaking BC.
- AvailabilityManager service (with the same check method) which gets all of the registered checkers, runs them until it gets a FALSE.
One FALSE means that the variation is not available. This service can maintain a static cache of results.

These classes need to live in commerce_order. We'll make it product entity type agnostic in one of the iterations.

The add to cart form will check the availability of the selected variation, disable the add to cart button if the variation is not available.
It will repeat the same check when the form is submitted.

Use cases:
- Deny availability if the variation "available on" date is before the current date
- Deny availability if the variation is out of stock (commerce_stock or custom stock check)

Comments

bojanz’s picture

Issue summary: View changes
bojanz’s picture

Issue summary: View changes
bojanz’s picture

Status: Active » Fixed
bojanz’s picture

Status: Fixed » Active

Wrong issue.

  • cbanman committed 300ac10 on 8.x-2.x
    Issue #2511266 by cbanman: Create a service for determining variation...
  • bojanz committed 308ed5d on 8.x-2.x
    Merge pull request #225 from crbanman/2511266
    
    Issue #2511266 by cbanman...
bojanz’s picture

Status: Active » Fixed

Status: Fixed » Closed (fixed)

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