In D7, Commerce offered a hook called hook_commerce_cart_attributes_refresh_alter(), offering the following possiblity:

Allows modules to add arbitrary AJAX commands to the array returned from the Add to Cart form attributes refresh.

When a product selection widget's value is changed, whether it is a product select list or a product attribute field widget, the Add to Cart form gets an AJAX refresh. The form will be rebuilt using the new form state and the AJAX callback of the element that was changed will be called. For this form it is commerce_cart_add_to_cart_form_attributes_refresh().

The cart form's particular AJAX refresh function returns an array of AJAX commands that perform HTML replacement on the page. However, other modules may want to interact with the refreshed form. They can use this hook to add additional items to the commands array, which is passed to the hook by reference. Note that the form array and form state cannot be altered, just the array of commands.

Currently, this is not possible in DC2 without altering the form and fully replace the original Ajax callback. I'll post a PR on Github soon and report back here

Comments

agoradesign created an issue. See original summary.

agoradesign’s picture

Status: Active » Needs review
bojanz’s picture

Title: Re-introduce hook_commerce_cart_attributes_refresh_alter » Add ProductEvents::PRODUCT_VARIATION_AJAX_CHANGE

We need to wait for #2716417: Allow rendering of variation fields on the product entity. to land, then add the event as agreed upon.

bojanz’s picture

Status: Needs review » Needs work
agoradesign’s picture

Assigned: Unassigned » agoradesign

Now that #2716417: Allow rendering of variation fields on the product entity. is in, I'll assign this task to me. Will care about this today

agoradesign’s picture

Status: Needs work » Needs review

  • bojanz committed bf9f30d on 8.x-2.x authored by agoradesign
    Issue #2710257 by agoradesign, bojanz: Add ProductEvents::...
bojanz’s picture

Status: Needs review » Fixed

Committed, thanks!

Status: Fixed » Closed (fixed)

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