Skip to content

Commit

Permalink
feat(storefront): Dispatch an event on productOptionsChanged (bigcomm…
Browse files Browse the repository at this point in the history
…erce#2400)

* feat(storefront): Dispatch an event on productOptionsChanged

Including all the information fetched in the previous request to the API to improve extensibility.

Having this mechanism, developers can set a listener and get as much information as they need regarding the selected option, so a new API call can be potentially avoided for further actions associated this event.

* chore: update CHANGELOG.md
  • Loading branch information
mgarciaebo authored Jan 4, 2024
1 parent 9f95e96 commit c22ed7f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Draft
- Dispatch an event on productOptionsChanged [#2400](https://github.com/bigcommerce/cornerstone/pull/2400)
- Check lang helpers usage and existence of key in translation file [#2403](https://github.com/bigcommerce/cornerstone/pull/2403)
- Display fees on cart page [#2376](https://github.com/bigcommerce/cornerstone/pull/2376)
- Replace Twitter logo with X logo within social sharing and social link components [#2387](https://github.com/bigcommerce/cornerstone/pull/2387)
Expand Down
8 changes: 8 additions & 0 deletions assets/js/theme/common/product-details.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,14 @@ export default class ProductDetails extends ProductDetailsBase {
const $context = $form.parents('.productView').find('.productView-info');
modalFactory('[data-reveal]', { $context });
}

document.dispatchEvent(new CustomEvent('onProductOptionsChanged', {
bubbles: true,
detail: {
content: productAttributesData,
data: productAttributesContent,
},
}));
});
}

Expand Down

0 comments on commit c22ed7f

Please sign in to comment.