Skip to content

Commit 5687d25

Browse files
feat(storefront): SD-10935 Update behaviour to delay displaying the alert message until all required product options are selected
1 parent 1ff7a31 commit 5687d25

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

77
## Draft
8+
- Update behaviour to delay displaying the alert message until all required product options are selected [#2535](https://github.com/bigcommerce/cornerstone/pull/2535)
89

910
## 6.16.0 (01-15-2025)
1011
- Remove escaping of "=" symbol for <head> for blog and brand [#2528](https://github.com/bigcommerce/cornerstone/pull/2528)

assets/js/theme/common/product-details-base.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,11 +223,16 @@ export default class ProductDetailsBase {
223223
/**
224224
* Update the view of price, messages, SKU and stock options when a product option changes
225225
* @param {Object} data Product attribute data
226+
* @param {Object} content Product attribute content
227+
* @param {Boolean} shouldMessageAppear indicates if product attributes form has no validity problems
228+
* and message can be shown to User
226229
*/
227-
updateView(data, content = null) {
230+
updateView(data, content, shouldMessageAppear = true) {
228231
const viewModel = this.getViewModel(this.$scope);
229232

230-
this.showMessageBox(data.stock_message || data.purchasing_message);
233+
if (shouldMessageAppear) {
234+
this.showMessageBox(data.stock_message || data.purchasing_message);
235+
}
231236

232237
if (data.price instanceof Object) {
233238
this.updatePriceView(viewModel, data.price);

assets/js/theme/common/product-details.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@ export default class ProductDetails extends ProductDetailsBase {
255255
const $changedOption = $(event.target);
256256
const $form = $changedOption.parents('form');
257257
const productId = $('[name="product_id"]', $form).val();
258+
const isFormValid = $form[0].checkValidity();
258259

259260
// Do not trigger an ajax request if it's a file or if the browser doesn't support FormData
260261
if ($changedOption.attr('type') === 'file' || window.FormData === undefined) {
@@ -264,8 +265,9 @@ export default class ProductDetails extends ProductDetailsBase {
264265
utils.api.productAttributes.optionChange(productId, $form.serialize(), 'products/bulk-discount-rates', (err, response) => {
265266
const productAttributesData = response.data || {};
266267
const productAttributesContent = response.content || {};
268+
267269
this.updateProductAttributes(productAttributesData);
268-
this.updateView(productAttributesData, productAttributesContent);
270+
this.updateView(productAttributesData, productAttributesContent, isFormValid);
269271
this.updateProductDetailsData();
270272
bannerUtils.dispatchProductBannerEvent(productAttributesData);
271273

0 commit comments

Comments
 (0)