Cart link doesn't respect Availability Checker

Created on 21 April 2025, about 14 hours ago

Problem/Motivation

The availability checker API constrains adding an item to the cart via the add-to-cart form. An example implementation can be found in the commerce_order_test test module, where items with SKUs starting with TEST_ cannot be added to the cart. In such a case user will see the following (or similar) message:

Side Table is not available with a quantity of 1.

However, this module allows adding all product variations, regardless of their availability status.

Proposed resolution

Check availability before adding the item to the cart. Return 403 if the item cannot be added to the cart.

πŸ› Bug report
Status

Active

Version

1.0

Component

Code

Created by

πŸ‡³πŸ‡΄Norway zaporylie

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @zaporylie
  • πŸ‡ΊπŸ‡ΈUnited States rszrama

    I'm not sure what the correct course of action should be here, to be honest. On the one hand, availability checkers should be respected, but on the other hand, how they are respected can be context dependent.

    I believe this is why, for example, the cart manager itself does not check availability before creating an order item. Additionally, I'm pretty sure Commerce only checks availability after the add to cart has occurred via the order processor, but I could be wrong.

    In this case, I'd almost suggest we leave the default behavior as is but optionally execute availability checking first, rendering the message upon failure. (The problem is, that message is pretty non-specific ... but it's the best we have atm.)

    Generally speaking, the availability system needs work. Will link to this from our internal Commerce channel for discussion in a future breaking release.

  • Pipeline finished with Success
    about 5 hours ago
    Total: 184s
    #478705
Production build 0.71.5 2024