Add $form_state to ProductVariationAjaxChangeEvent

Created on 9 December 2018, almost 6 years ago
Updated 2 April 2024, 8 months ago

Problem/Motivation

As a developer, I need to know the context of the add_to_cart form when I subscribe to the ProductEvents::PRODUCT_VARIATION_AJAX_CHANGE event

In other words, I need the $form_state in order to implement custom functionalities when the Cart is being updated.

Common usecases:

  • Compare quantities:
    Let's say my Product Variation has a field_stock holding the remaining stock of this variation. My user select a quantity of 999. I want to compare this quantity from the form against the remaining stock before Ajax reloading of the Variation form (to display a custom message, to trigger an action, to set/unset some other fields...etc)

Proposed resolution

Add the $form_state variable to ProductEvents::PRODUCT_VARIATION_AJAX_CHANGE event in ProductVariationWidgetBase.

This has absolutely no impact on any other parts of the Commerce suite, whatsoever.

Remaining tasks

  • Create a Unit test
  • Review and merge the PR
Feature request
Status

Closed: won't fix

Version

2.0

Component

Product

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024