wickes-css2 2.111.0-develop.3 → 2.111.0-develop.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (113) hide show
  1. package/Readme.md +0 -1
  2. package/build/css/category-main.css +1 -1
  3. package/build/css/homepage-main.css +1 -1
  4. package/build/css/kitchen-plp-main.css +1 -1
  5. package/build/css/main.css +1 -1
  6. package/build/css/my-account-main-v2.css +1 -1
  7. package/build/css/my-account-main.css +1 -1
  8. package/build/css/pages/page_personal-details.css +1 -1
  9. package/build/css/pages/page_product-details-v2.css +1 -1
  10. package/build/css/pdp-main-before-combine.css +1 -1
  11. package/build/css/pdp-main-critical.css +1 -1
  12. package/build/css/pdp-main-non-critical.css +1 -1
  13. package/build/css/pdp-main.css +1 -1
  14. package/build/css/plp-main.css +1 -1
  15. package/build/css/store-locator-main.css +1 -1
  16. package/build/js/account-hub.min.js +1 -1
  17. package/build/js/basket.min.js +1 -1
  18. package/build/js/bloomreach-widget.min.js +1 -0
  19. package/build/js/bundle.min.js +1 -1
  20. package/build/js/checkout.min.js +1 -1
  21. package/build/js/emulation.min.js +3024 -218
  22. package/build/js/general.bundle.min.js +1 -1
  23. package/build/js/merged-checkout.min.js +1 -1
  24. package/build/js/page/bloomreach-widget.js +1189 -0
  25. package/build/js/page/utils/create-count-stepper.js +30 -9
  26. package/build/js/page/utils/create-loading-button.js +37 -0
  27. package/build/js/page/utils/create-toast.js +79 -0
  28. package/build/js/page/utils/custom-dropdown.js +80 -0
  29. package/build/js/pdp-count-stepper.min.js +1 -1
  30. package/build/js/pdp.bundle.min.js +1 -1
  31. package/build/js/plp.bundle.min.js +1 -1
  32. package/build/js/project-list.min.js +1 -1
  33. package/build/js/saving-shopping-list.min.js +1 -1
  34. package/package.json +1 -1
  35. package/src/components/base/button.hbs +23 -5
  36. package/src/components/bloomreach/complete-card-dropdown.hbs +47 -0
  37. package/src/components/bloomreach/complete-card-skeleton.hbs +19 -0
  38. package/src/components/bloomreach/complete-card.hbs +138 -0
  39. package/src/components/bloomreach/complete-divider.hbs +3 -0
  40. package/src/components/bloomreach/complete-summary-skeleton.hbs +12 -0
  41. package/src/components/bloomreach/complete-summary.hbs +43 -0
  42. package/src/components/bloomreach/complete-wrapper.hbs +1 -0
  43. package/src/components/bloomreach/complete-your-project.hbs +21 -0
  44. package/src/components/gift-cards.hbs +1 -1
  45. package/src/elements/checkbox.hbs +8 -1
  46. package/src/js/components/general/cart-slider.js +19 -6
  47. package/src/js/emulation/bloomreach-widget-calculations.js +132 -0
  48. package/src/js/emulation/bloomreach-widget-loading.js +11 -0
  49. package/src/js/emulation/mock.js +3098 -1
  50. package/src/js/emulation/notify-me.js +1 -1
  51. package/src/js/page/bloomreach-widget.js +1189 -0
  52. package/src/js/page/utils/create-count-stepper.js +30 -9
  53. package/src/js/page/utils/create-loading-button.js +37 -0
  54. package/src/js/page/utils/create-toast.js +79 -0
  55. package/src/js/page/utils/custom-dropdown.js +80 -0
  56. package/src/page_product-details-banner.html +0 -1
  57. package/src/page_product-details-big-wins-disabled-delivery.html +0 -1
  58. package/src/page_product-details-big-wins-non-registered.html +0 -1
  59. package/src/page_product-details-big-wins-out-nearest.html +0 -1
  60. package/src/page_product-details-big-wins-unhappy.html +0 -1
  61. package/src/page_product-details-big-wins.html +0 -1
  62. package/src/page_product-details-billie.html +0 -1
  63. package/src/page_product-details-bloomreach.html +130 -0
  64. package/src/page_product-details-calculator.html +0 -1
  65. package/src/page_product-details-cashback-v2.html +0 -1
  66. package/src/page_product-details-clearpay.html +0 -1
  67. package/src/page_product-details-cnc-error-notification.html +0 -1
  68. package/src/page_product-details-cnc-success-notification-vat.html +0 -1
  69. package/src/page_product-details-cnc-success-notification.html +0 -1
  70. package/src/page_product-details-default-store.html +0 -1
  71. package/src/page_product-details-energy-efficiency.html +0 -1
  72. package/src/page_product-details-flooring-with-pr-placeholder.html +0 -1
  73. package/src/page_product-details-flooring.html +0 -1
  74. package/src/page_product-details-gallery-actual.html +0 -1
  75. package/src/page_product-details-mfe-calculator.html +0 -1
  76. package/src/page_product-details-minimum-v2.html +0 -1
  77. package/src/page_product-details-mtm-doors.html +0 -1
  78. package/src/page_product-details-only-clearpay.html +0 -1
  79. package/src/page_product-details-paint-mixing.html +0 -1
  80. package/src/page_product-details-saved-pl.html +0 -1
  81. package/src/page_product-details-tile-steps-klarna-widget-with-method-ids.html +0 -1
  82. package/src/page_product-details-tile-steps-logout.html +0 -1
  83. package/src/page_product-details-tile-steps-no-new-project-list.html +0 -1
  84. package/src/page_product-details-tile-steps-with-klarna.html +0 -1
  85. package/src/page_product-details-tile-steps.html +0 -1
  86. package/src/page_product-details-v2.html +0 -1
  87. package/src/page_product-details-vat.html +0 -1
  88. package/src/page_product-details-wisdom-mcfc-registered.html +0 -1
  89. package/src/page_product-details-wisdom-mcfc.html +0 -1
  90. package/src/page_product-details-wisdom-oos-registered.html +0 -1
  91. package/src/page_product-details-wisdom-oos.html +0 -1
  92. package/src/page_product-details-wisdom-registered.html +0 -1
  93. package/src/page_product-details-wisdom.html +0 -1
  94. package/src/page_product-details-with-favourite.html +0 -1
  95. package/src/page_product-details-with-global-search-v2.html +7 -1
  96. package/src/page_product-details_no-previous-default.html +0 -1
  97. package/src/page_track-my-order-result.html +1 -0
  98. package/src/partials/scripts.hbs +1 -0
  99. package/src/scss/common/_common.scss +1 -0
  100. package/src/scss/common/_elements.scss +13 -1
  101. package/src/scss/common/_loading-button.scss +49 -0
  102. package/src/scss/components/_notifications.scss +86 -5
  103. package/src/scss/components/bloomreach/_bloomreach.scss +3 -0
  104. package/src/scss/components/bloomreach/_complete-card-dropdown.scss +174 -0
  105. package/src/scss/components/bloomreach/_complete-card.scss +408 -0
  106. package/src/scss/components/bloomreach/_complete-your-project.scss +207 -0
  107. package/src/scss/helpers/_variables.scss +1 -0
  108. package/src/scss/pages/page_product-details-v2.scss +45 -2
  109. package/src/scss/pdp-main-critical.scss +0 -1
  110. package/src/scss/pdp-main.scss +1 -1
  111. package/src/sitemap.html +6 -0
  112. package/src/scss/components/_pdp-action-v2-critical.scss +0 -27
  113. package/src/scss/components/_pdp-action-v2.scss +0 -27
@@ -0,0 +1,1189 @@
1
+ var Wick = window.Wick || {};
2
+
3
+ import { createCountStepper } from './utils/create-count-stepper';
4
+ import { createEvent } from './utils/create-event';
5
+ import { createDropdown } from './utils/custom-dropdown';
6
+ import { createLoadingButton } from './utils/create-loading-button';
7
+ import { createToast } from './utils/create-toast';
8
+
9
+ const Handlebars = require('hbsfy/runtime');
10
+
11
+ Handlebars.registerPartial('checkbox', require('../../elements/checkbox.hbs'));
12
+ Handlebars.registerPartial('loader', require('../../elements/loader.hbs'));
13
+ Handlebars.registerPartial('button', require('../../components/base/button.hbs'));
14
+ Handlebars.registerPartial(
15
+ 'bloomreach/complete-card-dropdown',
16
+ require('../../components/bloomreach/complete-card-dropdown.hbs')
17
+ );
18
+ Handlebars.registerPartial('notifications', require('../../elements/notifications.hbs'));
19
+
20
+ const notificationTemplate = require('../../elements/notifications.hbs');
21
+ const completeWrapperTemplate = require('../../components/bloomreach/complete-wrapper.hbs');
22
+ const completeDividerTemplate = require('../../components/bloomreach/complete-divider.hbs');
23
+ const completeCardTemplate = require('../../components/bloomreach/complete-card.hbs');
24
+ const completeSummaryTemplate = require('../../components/bloomreach/complete-summary.hbs');
25
+
26
+ Wick.BloomreachWidget = {
27
+ CALCULATE_PRODUCT_BUNDLE_TOTAL_EVENT: 'calculateProductBundleTotal',
28
+ ADD_PRODUCT_BUNDLE_TO_CART_EVENT: 'bulkAddToCart',
29
+
30
+ steppers: [],
31
+ recommendations: [],
32
+ dropdown: null,
33
+ loadingButton: null,
34
+ lastCalculationResponse: null,
35
+ dropdownCurrent: {},
36
+ toast: null,
37
+
38
+ el: {
39
+ cardCheckbox: '.complete-card__select input[type="checkbox"]',
40
+ completeCard: '.complete-card',
41
+ completeWidget: '.complete-widget',
42
+ countBtn: '.count-btn',
43
+ countStepperInitializedData: 'count-stepper-initialized',
44
+ countStepperRoot: '.count-stepper',
45
+ ctaButton: '.complete-widget__cta .btn',
46
+ ctaButtonText: '.loading-button__text',
47
+ ctaButtonLoader: '.loading-button__loader',
48
+ summaryPriceValue: '.complete-widget__price-value',
49
+ summarySalePrice: '.complete-widget__sale-price',
50
+ summaryPriceInc: '.including-vat-inherit',
51
+ summaryPriceExc: '.excluding-vat-inherit',
52
+ summarySalePriceInc: '.including-vat-inherit',
53
+ summarySalePriceExc: '.excluding-vat-inherit',
54
+
55
+ dropdownErrorClass: 'complete-card-dropdown--error',
56
+ dropdownOpenClass: 'complete-card-dropdown--open',
57
+ dropdownOption: '[data-complete-card-dropdown-option]',
58
+ dropdownOptionSelectedClass: 'complete-card-dropdown__option--selected',
59
+ dropdownRoot: '[data-complete-card-dropdown]',
60
+ dropdownToggle: '[data-complete-card-dropdown-toggle]',
61
+ dropdownValue: '[data-complete-card-dropdown-value]',
62
+
63
+ optionsEl: '.complete-card__options',
64
+ previousQuantityData: 'previous-quantity',
65
+ quantityInput: '.tbx_quantity',
66
+ quantityReadyData: 'quantity-ready',
67
+
68
+ recommendationIndexAttr: 'data-recommendation-index',
69
+ selectedClass: 'complete-card--selected',
70
+ selectedValueData: 'selected-value',
71
+ starOverlay: '.star-overlay',
72
+
73
+ titleEl: '.complete-card__title',
74
+
75
+ widgetContainer: '[data-complete-widget]',
76
+ widgetContent: '[data-complete-widget-content]',
77
+ widgetWrapper: '[data-complete-widget-wrapper]',
78
+ },
79
+
80
+ badgeColorMap: {
81
+ blue: '#019ee3',
82
+ gray: '#3e3e3e',
83
+ green: '#9acd32',
84
+ red: '#cf000f',
85
+ yellow: '#f7ca18',
86
+ },
87
+
88
+ getCtaText(selectedCount) {
89
+ if (!selectedCount) {
90
+ return 'Add product(s) to basket';
91
+ }
92
+
93
+ return `Add ${selectedCount} product${selectedCount > 1 ? 's' : ''} to basket`;
94
+ },
95
+
96
+ setCtaText($button, text) {
97
+ const { ctaButtonText } = Wick.BloomreachWidget.el;
98
+ const $text = $button.find(ctaButtonText);
99
+
100
+ if ($text.length) {
101
+ $text.text(text);
102
+ return;
103
+ }
104
+
105
+ $button.text(text);
106
+ },
107
+
108
+ getBadgeColor(color) {
109
+ return Wick.BloomreachWidget.badgeColorMap[color] || color;
110
+ },
111
+
112
+ hasRecommendations(payloadData) {
113
+ if (Array.isArray(payloadData)) {
114
+ return payloadData.length > 0;
115
+ }
116
+
117
+ return Boolean(
118
+ payloadData &&
119
+ Array.isArray(payloadData.recommendedProducts) &&
120
+ payloadData.recommendedProducts.length
121
+ );
122
+ },
123
+
124
+ normalizePayload(payloadData) {
125
+ if (Array.isArray(payloadData)) {
126
+ return payloadData;
127
+ }
128
+
129
+ if (payloadData && Array.isArray(payloadData.recommendedProducts)) {
130
+ return payloadData.recommendedProducts;
131
+ }
132
+
133
+ return [];
134
+ },
135
+
136
+ getDisplayPrice(product) {
137
+ return product.displayPrice || product.price || {};
138
+ },
139
+
140
+ dispatchWidgetEvent(eventName, payload) {
141
+ return new Promise(function (resolve, reject) {
142
+ const eventDetail = { resolve, reject };
143
+ const event = createEvent(eventName, payload, eventDetail);
144
+
145
+ window.dispatchEvent(event);
146
+ });
147
+ },
148
+
149
+ getProductImage(product, fallbackProduct) {
150
+ const productImages = product.images || [];
151
+ const fallbackImages = fallbackProduct ? fallbackProduct.images || [] : [];
152
+ const images = productImages.length ? productImages : fallbackImages;
153
+
154
+ return (
155
+ images.find(function (item) {
156
+ return item.format === 'product';
157
+ }) ||
158
+ images.find(function (item) {
159
+ return item.imageType === 'PRIMARY';
160
+ }) ||
161
+ images[0] ||
162
+ {}
163
+ );
164
+ },
165
+
166
+ getDropdownOptions(product) {
167
+ if (!product.variantOptions || !product.variantOptions.length) {
168
+ return [];
169
+ }
170
+
171
+ return product.variantOptions.map(function (variantOption) {
172
+ const qualifiers = variantOption.variantOptionQualifiers || [];
173
+
174
+ const label = qualifiers
175
+ .map(function (qualifier) {
176
+ return qualifier.value;
177
+ })
178
+ .join(', ');
179
+
180
+ return {
181
+ label,
182
+ value: variantOption.code,
183
+ };
184
+ });
185
+ },
186
+
187
+ getSelectedDropdownLabel(options, selectedValue) {
188
+ const selectedOption = options.find(function (option) {
189
+ return option.value === selectedValue;
190
+ });
191
+
192
+ return selectedOption ? selectedOption.label : '';
193
+ },
194
+
195
+ handleBulkAddToCartResponse(response) {
196
+ const bulkData = response && response.bulkAddToCartData;
197
+
198
+ if (!bulkData) {
199
+ return;
200
+ }
201
+
202
+ Wick.BloomreachWidget.toast.show({
203
+ type: bulkData.messageType,
204
+ text: bulkData.messageText,
205
+ });
206
+ },
207
+
208
+ getBadge(product) {
209
+ const promotion = product.potentialPromotions && product.potentialPromotions[0];
210
+ const promotionAttributes = promotion && promotion.customAttributes;
211
+
212
+ if (promotionAttributes && promotionAttributes.overlayText) {
213
+ return {
214
+ text: promotionAttributes.overlayText,
215
+ textColor: Wick.BloomreachWidget.getBadgeColor(
216
+ promotionAttributes.overlayTextColor
217
+ ),
218
+ color: Wick.BloomreachWidget.getBadgeColor(
219
+ promotionAttributes.overlayBackgroundColor
220
+ ),
221
+ };
222
+ }
223
+
224
+ return product.badge;
225
+ },
226
+
227
+ getWasPrice(product) {
228
+ const displayPrice = Wick.BloomreachWidget.getDisplayPrice(product);
229
+
230
+ return displayPrice && displayPrice.wasPrice ? displayPrice.wasPrice : null;
231
+ },
232
+
233
+ getWasPriceFormatted(product) {
234
+ const displayPrice = Wick.BloomreachWidget.getDisplayPrice(product);
235
+ const wasPrice = Wick.BloomreachWidget.getWasPrice(product);
236
+
237
+ if (wasPrice && wasPrice.formattedValue) {
238
+ return wasPrice.formattedValue;
239
+ }
240
+
241
+ if (typeof wasPrice === 'number') {
242
+ return Wick.BloomreachWidget.formatPrice(wasPrice);
243
+ }
244
+
245
+ if (wasPrice) {
246
+ return `${displayPrice.currencySymbol || '£'}${wasPrice}`;
247
+ }
248
+
249
+ return '';
250
+ },
251
+
252
+ getDisplayPriceExcVat(product) {
253
+ return product.displayPriceExclusiveVat || product.priceExclusiveVat || null;
254
+ },
255
+
256
+ getPriceValue(price) {
257
+ return price && typeof price.value === 'number' ? price.value : 0;
258
+ },
259
+
260
+ getPriceFormattedValue(price) {
261
+ if (!price) {
262
+ return '';
263
+ }
264
+
265
+ if (price.formattedValue) {
266
+ return price.formattedValue;
267
+ }
268
+
269
+ if (typeof price.value === 'number') {
270
+ return Wick.BloomreachWidget.formatPrice(price.value);
271
+ }
272
+
273
+ return '';
274
+ },
275
+
276
+ getExcVatWasPrice(product) {
277
+ const displayPriceExclusiveVat = Wick.BloomreachWidget.getDisplayPriceExcVat(product);
278
+ const wasPrice = displayPriceExclusiveVat && displayPriceExclusiveVat.wasPrice;
279
+
280
+ if (wasPrice && wasPrice.formattedValue) {
281
+ return wasPrice.formattedValue;
282
+ }
283
+
284
+ if (typeof wasPrice === 'number') {
285
+ return Wick.BloomreachWidget.formatPrice(wasPrice);
286
+ }
287
+
288
+ return wasPrice || '';
289
+ },
290
+
291
+ getExcVatFormattedValue(displayPrice, product) {
292
+ const excVat = product ? Wick.BloomreachWidget.getDisplayPriceExcVat(product) : null;
293
+ if (excVat && excVat.formattedValue) {
294
+ return excVat.formattedValue;
295
+ }
296
+ if (!displayPrice || typeof displayPrice.value !== 'number') {
297
+ return displayPrice ? displayPrice.formattedValue || '' : '';
298
+ }
299
+ const vatRate = displayPrice.vatRatePercentage || 20;
300
+ return Wick.BloomreachWidget.formatPrice(displayPrice.value / (1 + vatRate / 100));
301
+ },
302
+
303
+ getProductRenderData(product, index, options = {}) {
304
+ const shouldShowDropdown = index !== 0;
305
+ const dropdownOptions = shouldShowDropdown
306
+ ? Wick.BloomreachWidget.getDropdownOptions(product)
307
+ : [];
308
+ const selectedDropdownValue = options.selectedDropdownValue || '';
309
+ const selectedDropdownLabel = Wick.BloomreachWidget.getSelectedDropdownLabel(
310
+ dropdownOptions,
311
+ selectedDropdownValue
312
+ );
313
+ const displayPrice = Wick.BloomreachWidget.getDisplayPrice(product);
314
+ const showFromPrice = Boolean(
315
+ index !== 0 &&
316
+ !selectedDropdownValue &&
317
+ displayPrice &&
318
+ displayPrice.priceType === 'FROM'
319
+ );
320
+
321
+ const wasPriceFormatted = Wick.BloomreachWidget.getWasPriceFormatted(product);
322
+ const excVatFormattedValue = Wick.BloomreachWidget.getExcVatFormattedValue(
323
+ displayPrice,
324
+ product
325
+ );
326
+ const isSwitchVat = !!(window.ACC && window.ACC.app && window.ACC.app.isVatToggleAvailable);
327
+
328
+ const excVatWasPriceFormatted = wasPriceFormatted
329
+ ? Wick.BloomreachWidget.getExcVatWasPrice(product)
330
+ : '';
331
+
332
+ return {
333
+ ...product,
334
+ badge: Wick.BloomreachWidget.getBadge(product),
335
+ price: displayPrice,
336
+ wasPriceFormatted,
337
+ 'switch-vat': isSwitchVat,
338
+ incVatFormattedValue: Wick.BloomreachWidget.getPriceFormattedValue(displayPrice),
339
+ incVatValue: Wick.BloomreachWidget.getPriceValue(displayPrice),
340
+ excVatFormattedValue,
341
+ excVatValue: Wick.BloomreachWidget.getPriceValue(
342
+ Wick.BloomreachWidget.getDisplayPriceExcVat(product)
343
+ ),
344
+ incVatWasPriceFormatted: wasPriceFormatted,
345
+ excVatWasPriceFormatted,
346
+ showFromPrice,
347
+ image:
348
+ options.image ||
349
+ Wick.BloomreachWidget.getProductImage(product, options.fallbackProduct),
350
+ dropdownOptions: dropdownOptions.map(function (option) {
351
+ return {
352
+ ...option,
353
+ selected: option.value === selectedDropdownValue,
354
+ };
355
+ }),
356
+ checkboxId: `${product.code}-${index}`,
357
+ dropdownError: options.dropdownError || false,
358
+ checked: options.checked || false,
359
+ selectedDropdownValue,
360
+ selectedDropdownLabel,
361
+ };
362
+ },
363
+
364
+ renderWidget($container, context) {
365
+ const { widgetContent, widgetWrapper, completeCard, recommendationIndexAttr } =
366
+ Wick.BloomreachWidget.el;
367
+
368
+ const $content = $container.find(widgetContent);
369
+ const recommendations = Wick.BloomreachWidget.normalizePayload(context);
370
+
371
+ if (!$content.length || !recommendations.length) {
372
+ return;
373
+ }
374
+
375
+ Wick.BloomreachWidget.recommendations = recommendations;
376
+
377
+ $content.html(completeWrapperTemplate());
378
+
379
+ const $wrapper = $content.find(widgetWrapper);
380
+
381
+ Wick.BloomreachWidget.dropdownCurrent = {};
382
+
383
+ recommendations.forEach(function (recommendation, index) {
384
+ const product = Wick.BloomreachWidget.getProductRenderData(
385
+ recommendation.baseProduct,
386
+ index
387
+ );
388
+
389
+ $wrapper.append(completeCardTemplate(product));
390
+
391
+ const $card = $wrapper.children(completeCard).last();
392
+
393
+ $card.attr(recommendationIndexAttr, index);
394
+
395
+ if (index === 0 && recommendations.length > 1) {
396
+ $wrapper.append(completeDividerTemplate());
397
+ }
398
+ });
399
+
400
+ const isSwitchVat = !!(window.ACC && window.ACC.app && window.ACC.app.isVatToggleAvailable);
401
+ $content.append(completeSummaryTemplate({ 'switch-vat': isSwitchVat }));
402
+ },
403
+
404
+ renderWidgetFromPayload(payloadData) {
405
+ const { widgetContainer, completeWidget } = Wick.BloomreachWidget.el;
406
+ const $containers = $(widgetContainer);
407
+
408
+ if (!$containers.length) {
409
+ return;
410
+ }
411
+
412
+ if (!Wick.BloomreachWidget.hasRecommendations(payloadData)) {
413
+ $containers.find(completeWidget).hide();
414
+ return;
415
+ }
416
+
417
+ $containers.each(function () {
418
+ const $container = $(this);
419
+
420
+ Wick.BloomreachWidget.renderWidget($container, payloadData);
421
+ Wick.BloomreachWidget.initRenderedWidget($container);
422
+ });
423
+ },
424
+
425
+ drawRating($root) {
426
+ const $ratingOverlay = $root.find('.rating-overlay');
427
+
428
+ $ratingOverlay.each(function () {
429
+ let rating = parseFloat($(this).attr('data-rating')) || 0;
430
+ const $stars = $(this).children(Wick.BloomreachWidget.el.starOverlay);
431
+
432
+ $stars.each(function () {
433
+ const $star = $(this);
434
+
435
+ if (rating >= 1) {
436
+ rating--;
437
+ } else if (rating > 0) {
438
+ const width = Math.asin(2 * rating - 1) / Math.PI + 0.5;
439
+ $star.css('width', width + 'rem');
440
+ rating = 0;
441
+ } else {
442
+ $star.css('width', '0rem');
443
+ }
444
+ });
445
+ });
446
+ },
447
+
448
+ getDropdownCard($dropdown) {
449
+ return $dropdown.closest(Wick.BloomreachWidget.el.completeCard);
450
+ },
451
+
452
+ getDropdownCheckbox($dropdown) {
453
+ return Wick.BloomreachWidget.getDropdownCard($dropdown).find(
454
+ Wick.BloomreachWidget.el.cardCheckbox
455
+ );
456
+ },
457
+
458
+ setDropdownCheckboxState($dropdown, isChecked, shouldTriggerChange = true) {
459
+ const $checkbox = Wick.BloomreachWidget.getDropdownCheckbox($dropdown);
460
+
461
+ if (!$checkbox.length) {
462
+ return;
463
+ }
464
+
465
+ $checkbox.prop('checked', isChecked);
466
+
467
+ if (shouldTriggerChange) {
468
+ $checkbox.trigger('change');
469
+ }
470
+ },
471
+
472
+ setDropdownError($dropdown, hasError) {
473
+ $dropdown.toggleClass(Wick.BloomreachWidget.el.dropdownErrorClass, hasError);
474
+ },
475
+
476
+ validateDropdown($dropdown, options = {}) {
477
+ const isValid = Boolean($dropdown.data(Wick.BloomreachWidget.el.selectedValueData));
478
+
479
+ Wick.BloomreachWidget.setDropdownError($dropdown, !isValid);
480
+
481
+ if (!isValid && options.uncheck) {
482
+ Wick.BloomreachWidget.setDropdownCheckboxState($dropdown, false, false);
483
+ Wick.BloomreachWidget.getDropdownCard($dropdown).removeClass(
484
+ Wick.BloomreachWidget.el.selectedClass
485
+ );
486
+ }
487
+
488
+ return isValid;
489
+ },
490
+
491
+ validateCardDropdown($card, options = {}) {
492
+ const $dropdown = $card.find(Wick.BloomreachWidget.el.dropdownRoot);
493
+
494
+ if (!$dropdown.length) {
495
+ return true;
496
+ }
497
+
498
+ return Wick.BloomreachWidget.validateDropdown($dropdown, options);
499
+ },
500
+
501
+ findVariantProduct(recommendation, selectedValue) {
502
+ if (!recommendation.variantProducts || !recommendation.variantProducts.length) {
503
+ return null;
504
+ }
505
+
506
+ return recommendation.variantProducts.find(function (variantProduct) {
507
+ return String(variantProduct.code) === String(selectedValue);
508
+ });
509
+ },
510
+
511
+ getCardQuantity($card) {
512
+ const $input = $card.find(Wick.BloomreachWidget.el.quantityInput);
513
+ const quantity = parseInt($input.val(), 10);
514
+
515
+ return Number.isNaN(quantity) ? 1 : quantity;
516
+ },
517
+
518
+ getCardProduct($card) {
519
+ const { recommendationIndexAttr, dropdownRoot, selectedValueData } =
520
+ Wick.BloomreachWidget.el;
521
+
522
+ const recommendationIndex = Number($card.attr(recommendationIndexAttr));
523
+ const recommendation = Wick.BloomreachWidget.recommendations[recommendationIndex];
524
+
525
+ if (!recommendation) {
526
+ return null;
527
+ }
528
+
529
+ const $dropdown = $card.find(dropdownRoot);
530
+ const selectedValue = $dropdown.length ? $dropdown.data(selectedValueData) : '';
531
+
532
+ if (selectedValue) {
533
+ return (
534
+ Wick.BloomreachWidget.findVariantProduct(recommendation, selectedValue) ||
535
+ recommendation.baseProduct
536
+ );
537
+ }
538
+
539
+ return recommendation.baseProduct;
540
+ },
541
+
542
+ getSelectedEntries($root) {
543
+ const { completeCard, cardCheckbox } = Wick.BloomreachWidget.el;
544
+ const entries = [];
545
+
546
+ $root.find(completeCard).each(function () {
547
+ const $card = $(this);
548
+ const $checkbox = $card.find(cardCheckbox);
549
+
550
+ if (!$checkbox.prop('checked')) {
551
+ return;
552
+ }
553
+
554
+ const product = Wick.BloomreachWidget.getCardProduct($card);
555
+
556
+ if (!product) {
557
+ return;
558
+ }
559
+
560
+ entries.push({
561
+ product,
562
+ quantity: Wick.BloomreachWidget.getCardQuantity($card),
563
+ });
564
+ });
565
+
566
+ return entries;
567
+ },
568
+
569
+ getAddToCartEntries($root) {
570
+ return Wick.BloomreachWidget.getSelectedEntries($root).map(function (entry) {
571
+ return {
572
+ productCode: entry.product.code,
573
+ quantity: entry.quantity,
574
+ };
575
+ });
576
+ },
577
+
578
+ updateSummary($root, response = {}) {
579
+ const totalPriceExclusiveVat = response.totalPriceExclusiveVat || response.totalExcVatPrice;
580
+
581
+ const totalWasPriceExclusiveVat =
582
+ response.totalWasPriceExclusiveVat || response.totalExcVatWasPrice;
583
+
584
+ const {
585
+ summaryPriceValue,
586
+ summarySalePrice,
587
+ summaryPriceInc,
588
+ summaryPriceExc,
589
+ summarySalePriceInc,
590
+ summarySalePriceExc,
591
+ } = Wick.BloomreachWidget.el;
592
+
593
+ Wick.BloomreachWidget.lastCalculationResponse = response;
594
+
595
+ const $price = $root.find(summaryPriceValue);
596
+ const $salePrice = $root.find(summarySalePrice);
597
+ const $total = $root.find('.complete-widget__total');
598
+
599
+ if (!$price.length) {
600
+ return;
601
+ }
602
+
603
+ if (response.totalWasPrice) {
604
+ $total.addClass('complete-widget__total-sale');
605
+ const $priceInc = $price.find(summaryPriceInc);
606
+
607
+ if ($priceInc.length) {
608
+ $priceInc.text(response.totalWasPrice);
609
+ $price
610
+ .find(summaryPriceExc)
611
+ .text(totalWasPriceExclusiveVat || response.totalWasPrice);
612
+
613
+ $salePrice.find(summarySalePriceInc).text(response.totalPrice || '');
614
+ $salePrice
615
+ .find(summarySalePriceExc)
616
+ .text(totalPriceExclusiveVat || response.totalPrice || '');
617
+ } else {
618
+ $price.text(response.totalWasPrice);
619
+ $salePrice.text(response.totalPrice || '');
620
+ }
621
+
622
+ $salePrice.show();
623
+ return;
624
+ }
625
+
626
+ $total.removeClass('complete-widget__total-sale');
627
+ const $priceInc = $price.find(summaryPriceInc);
628
+ if ($priceInc.length) {
629
+ $priceInc.text(response.totalPrice || '£0.00');
630
+ $price
631
+ .find(summaryPriceExc)
632
+ .text(totalPriceExclusiveVat || response.totalPrice || '£0.00');
633
+
634
+ $salePrice.find(summarySalePriceInc).text('');
635
+ $salePrice.find(summarySalePriceExc).text('');
636
+ $salePrice.hide();
637
+ } else {
638
+ $price.text(response.totalPrice || '£0.00');
639
+ $salePrice.text('').hide();
640
+ }
641
+ },
642
+
643
+ updateCta($root) {
644
+ const { ctaButton, cardCheckbox } = Wick.BloomreachWidget.el;
645
+ const selectedCount = $root.find(cardCheckbox).filter(':checked').length;
646
+ const $cta = $root.find(ctaButton);
647
+
648
+ if (!$cta.length) {
649
+ return;
650
+ }
651
+
652
+ $cta.prop('disabled', !selectedCount);
653
+ Wick.BloomreachWidget.setCtaText($cta, Wick.BloomreachWidget.getCtaText(selectedCount));
654
+ },
655
+
656
+ dispatchCalculateTotal($root) {
657
+ Wick.BloomreachWidget.updateCta($root);
658
+
659
+ return Wick.BloomreachWidget.dispatchWidgetEvent(
660
+ Wick.BloomreachWidget.CALCULATE_PRODUCT_BUNDLE_TOTAL_EVENT,
661
+ {
662
+ entries: Wick.BloomreachWidget.getSelectedEntries($root),
663
+ }
664
+ ).then(function (response) {
665
+ Wick.BloomreachWidget.updateSummary($root, response);
666
+ });
667
+ },
668
+
669
+ dispatchAddToCart($root, $button) {
670
+ Wick.BloomreachWidget.loadingButton.start($button);
671
+
672
+ return new Promise(function (resolve, reject) {
673
+ const eventDetail = { resolve, reject };
674
+ const event = createEvent(
675
+ Wick.BloomreachWidget.ADD_PRODUCT_BUNDLE_TO_CART_EVENT,
676
+ {
677
+ entries: Wick.BloomreachWidget.getAddToCartEntries($root),
678
+ },
679
+ eventDetail
680
+ );
681
+
682
+ window.dispatchEvent(event);
683
+ })
684
+ .then(function (response) {
685
+ Wick.BloomreachWidget.handleBulkAddToCartResponse(response);
686
+
687
+ Wick.MiniBasketSliderFE.isMiniBasketLoaded = false;
688
+ })
689
+ .catch(function () {
690
+ Wick.BloomreachWidget.handleBulkAddToCartResponse({
691
+ bulkAddToCartData: {
692
+ messageType: 'error',
693
+ messageText: 'Selected product(s) were not added to basket',
694
+ },
695
+ });
696
+ })
697
+ .finally(function () {
698
+ Wick.BloomreachWidget.loadingButton.stop($button);
699
+ Wick.BloomreachWidget.updateCta($root);
700
+ });
701
+ },
702
+
703
+ reinitCard($card) {
704
+ const { countBtn, completeWidget } = Wick.BloomreachWidget.el;
705
+
706
+ $card.find(countBtn).remove();
707
+
708
+ Wick.BloomreachWidget.initQuantityFields($card);
709
+ Wick.BloomreachWidget.drawRating($card);
710
+ Wick.BloomreachWidget.alignCardBlocks($card.closest(completeWidget));
711
+ },
712
+
713
+ replaceCardWithBaseProduct($dropdown, options = {}) {
714
+ const {
715
+ completeCard,
716
+ recommendationIndexAttr,
717
+ dropdownRoot,
718
+ dropdownErrorClass,
719
+ cardCheckbox,
720
+ } = Wick.BloomreachWidget.el;
721
+
722
+ const $card = $dropdown.closest(completeCard);
723
+ const recommendationIndex = Number($card.attr(recommendationIndexAttr));
724
+ const recommendation = Wick.BloomreachWidget.recommendations[recommendationIndex];
725
+
726
+ if (!recommendation || !recommendation.baseProduct) {
727
+ return null;
728
+ }
729
+
730
+ const productData = Wick.BloomreachWidget.getProductRenderData(
731
+ recommendation.baseProduct,
732
+ recommendationIndex,
733
+ {
734
+ dropdownError: options.dropdownError || false,
735
+ checked: false,
736
+ }
737
+ );
738
+
739
+ const newCardHtml = completeCardTemplate(productData);
740
+ const $newCard = $(newCardHtml);
741
+
742
+ $newCard.attr(recommendationIndexAttr, recommendationIndex);
743
+
744
+ if (options.dropdownError) {
745
+ $newCard.find(dropdownRoot).addClass(dropdownErrorClass);
746
+ }
747
+
748
+ $card.replaceWith($newCard);
749
+
750
+ $newCard.find(cardCheckbox).prop('checked', false);
751
+
752
+ $newCard
753
+ .find(Wick.BloomreachWidget.el.quantityInput)
754
+ .val(1)
755
+ .data(Wick.BloomreachWidget.el.previousQuantityData, 1)
756
+ .removeData(Wick.BloomreachWidget.el.quantityReadyData)
757
+ .removeData(Wick.BloomreachWidget.el.countStepperInitializedData);
758
+
759
+ Wick.BloomreachWidget.reinitCard($newCard);
760
+
761
+ return $newCard;
762
+ },
763
+
764
+ replaceCardWithVariant($dropdown, selectedValue) {
765
+ const {
766
+ completeCard,
767
+ recommendationIndexAttr,
768
+ selectedClass,
769
+ dropdownRoot,
770
+ selectedValueData,
771
+ cardCheckbox,
772
+ } = Wick.BloomreachWidget.el;
773
+
774
+ const $card = $dropdown.closest(completeCard);
775
+ const recommendationIndex = Number($card.attr(recommendationIndexAttr));
776
+ const recommendation = Wick.BloomreachWidget.recommendations[recommendationIndex];
777
+
778
+ if (!recommendation) {
779
+ return null;
780
+ }
781
+
782
+ const variantProduct = Wick.BloomreachWidget.findVariantProduct(
783
+ recommendation,
784
+ selectedValue
785
+ );
786
+
787
+ if (!variantProduct) {
788
+ return null;
789
+ }
790
+
791
+ const productData = Wick.BloomreachWidget.getProductRenderData(
792
+ {
793
+ ...variantProduct,
794
+ variantOptions: recommendation.baseProduct.variantOptions,
795
+ },
796
+ recommendationIndex,
797
+ {
798
+ fallbackProduct: recommendation.baseProduct,
799
+ checked: true,
800
+ selectedDropdownValue: selectedValue,
801
+ }
802
+ );
803
+
804
+ const newCardHtml = completeCardTemplate(productData);
805
+ const $newCard = $(newCardHtml);
806
+
807
+ $newCard.attr(recommendationIndexAttr, recommendationIndex);
808
+ $newCard.addClass(selectedClass);
809
+
810
+ const $newDropdown = $newCard.find(dropdownRoot);
811
+
812
+ if ($newDropdown.length) {
813
+ $newDropdown.data(selectedValueData, selectedValue);
814
+ }
815
+
816
+ $card.replaceWith($newCard);
817
+
818
+ $newCard.find(cardCheckbox).prop('checked', true);
819
+
820
+ $newCard
821
+ .find(Wick.BloomreachWidget.el.quantityInput)
822
+ .val(1)
823
+ .data(Wick.BloomreachWidget.el.previousQuantityData, 1)
824
+ .removeData(Wick.BloomreachWidget.el.quantityReadyData)
825
+ .removeData(Wick.BloomreachWidget.el.countStepperInitializedData);
826
+
827
+ Wick.BloomreachWidget.reinitCard($newCard);
828
+
829
+ return $newCard;
830
+ },
831
+
832
+ handleDropdownSelect($dropdown, selectedValue) {
833
+ const $card = $dropdown.closest(Wick.BloomreachWidget.el.completeCard);
834
+ const recommendationIndex = $card.attr(Wick.BloomreachWidget.el.recommendationIndexAttr);
835
+ const currentValue = Wick.BloomreachWidget.dropdownCurrent[recommendationIndex];
836
+
837
+ if (`${currentValue}` === `${selectedValue}`) {
838
+ return;
839
+ }
840
+
841
+ Wick.BloomreachWidget.dropdownCurrent[recommendationIndex] = selectedValue;
842
+
843
+ const $completeWidget = $dropdown.closest(Wick.BloomreachWidget.el.completeWidget);
844
+ const isPlaceholder = !selectedValue;
845
+
846
+ if (isPlaceholder) {
847
+ Wick.BloomreachWidget.setDropdownError($dropdown, true);
848
+ Wick.BloomreachWidget.setDropdownCheckboxState($dropdown, false, false);
849
+ Wick.BloomreachWidget.replaceCardWithBaseProduct($dropdown, {
850
+ dropdownError: true,
851
+ });
852
+
853
+ if ($completeWidget.length) {
854
+ Wick.BloomreachWidget.dispatchCalculateTotal($completeWidget);
855
+ }
856
+
857
+ return;
858
+ }
859
+
860
+ Wick.BloomreachWidget.setDropdownError($dropdown, false);
861
+ Wick.BloomreachWidget.setDropdownCheckboxState($dropdown, true, false);
862
+ Wick.BloomreachWidget.replaceCardWithVariant($dropdown, selectedValue);
863
+
864
+ if ($completeWidget.length) {
865
+ Wick.BloomreachWidget.dispatchCalculateTotal($completeWidget);
866
+ }
867
+ },
868
+
869
+ bindDropdowns() {
870
+ const {
871
+ dropdownRoot,
872
+ dropdownToggle,
873
+ dropdownValue,
874
+ dropdownOption,
875
+ dropdownOpenClass,
876
+ dropdownOptionSelectedClass,
877
+ } = Wick.BloomreachWidget.el;
878
+
879
+ Wick.BloomreachWidget.dropdown = createDropdown({
880
+ root: dropdownRoot,
881
+ toggle: dropdownToggle,
882
+ value: dropdownValue,
883
+ option: dropdownOption,
884
+ openClass: dropdownOpenClass,
885
+ selectedClass: dropdownOptionSelectedClass,
886
+ namespace: 'bloomreachDropdown',
887
+ onSelect($dropdown, $option, selectedValue) {
888
+ Wick.BloomreachWidget.handleDropdownSelect($dropdown, selectedValue);
889
+ },
890
+ });
891
+
892
+ Wick.BloomreachWidget.dropdown.bind();
893
+ },
894
+
895
+ bindCardSelection($root) {
896
+ const { completeCard, cardCheckbox, selectedClass } = Wick.BloomreachWidget.el;
897
+
898
+ const $firstCard = $root.find(completeCard).first();
899
+
900
+ $firstCard.find(cardCheckbox).prop('checked', true);
901
+ $firstCard.addClass(selectedClass);
902
+
903
+ $root.off('change.bloomreachCardSelection', cardCheckbox);
904
+ $root.on('change.bloomreachCardSelection', cardCheckbox, function () {
905
+ const $checkbox = $(this);
906
+ const $card = $checkbox.closest(completeCard);
907
+ const $dropdown = $card.find(Wick.BloomreachWidget.el.dropdownRoot);
908
+
909
+ if (
910
+ !$checkbox.prop('checked') &&
911
+ $dropdown.hasClass(Wick.BloomreachWidget.el.dropdownErrorClass)
912
+ ) {
913
+ $card.removeClass(selectedClass);
914
+ return;
915
+ }
916
+
917
+ if (
918
+ $checkbox.prop('checked') &&
919
+ !Wick.BloomreachWidget.validateCardDropdown($card, {
920
+ uncheck: true,
921
+ })
922
+ ) {
923
+ $checkbox.prop('checked', false);
924
+ $card.removeClass(selectedClass);
925
+ return;
926
+ }
927
+
928
+ $card.toggleClass(selectedClass, this.checked);
929
+
930
+ Wick.BloomreachWidget.dispatchCalculateTotal($root);
931
+ });
932
+ },
933
+
934
+ bindDropdownValidation($root) {
935
+ const { cardCheckbox, completeCard } = Wick.BloomreachWidget.el;
936
+
937
+ $root.off('click.bloomreachDropdownValidation', cardCheckbox);
938
+ $root.on('click.bloomreachDropdownValidation', cardCheckbox, function () {
939
+ const $checkbox = $(this);
940
+ const $card = $checkbox.closest(completeCard);
941
+
942
+ if (
943
+ $checkbox.prop('checked') &&
944
+ !Wick.BloomreachWidget.validateCardDropdown($card, {
945
+ uncheck: true,
946
+ })
947
+ ) {
948
+ $checkbox.prop('checked', false);
949
+ $card.removeClass(Wick.BloomreachWidget.el.selectedClass);
950
+ }
951
+ });
952
+ },
953
+
954
+ bindAddToCart($root) {
955
+ const { ctaButton } = Wick.BloomreachWidget.el;
956
+
957
+ $root.off('click.bloomreachAddToCart', ctaButton);
958
+ $root.on('click.bloomreachAddToCart', ctaButton, function (event) {
959
+ event.preventDefault();
960
+
961
+ const $button = $(this);
962
+
963
+ if (
964
+ $button.prop('disabled') ||
965
+ Wick.BloomreachWidget.loadingButton.isLoading($button)
966
+ ) {
967
+ return;
968
+ }
969
+
970
+ Wick.BloomreachWidget.dispatchAddToCart($root, $button);
971
+ });
972
+ },
973
+
974
+ alignBlock(selector, $root) {
975
+ const $els = $root.find(selector);
976
+
977
+ $els.css('min-height', '');
978
+
979
+ if (!$els.length || Wick.Responsive.getCurrentBreakpoint() !== 'up-lg') {
980
+ return;
981
+ }
982
+
983
+ let maxHeight = 0;
984
+
985
+ $els.each(function () {
986
+ maxHeight = Math.max(maxHeight, $(this).height());
987
+ });
988
+
989
+ if (maxHeight > 0) {
990
+ $els.css('min-height', maxHeight + 'px');
991
+ }
992
+ },
993
+
994
+ alignCardBlocks($root) {
995
+ const { titleEl, optionsEl } = Wick.BloomreachWidget.el;
996
+
997
+ Wick.BloomreachWidget.alignBlock(titleEl, $root);
998
+ Wick.BloomreachWidget.alignBlock(optionsEl, $root);
999
+ },
1000
+
1001
+ setInitialSummary($root) {
1002
+ const entries = Wick.BloomreachWidget.getSelectedEntries($root);
1003
+ const firstEntry = entries[0];
1004
+
1005
+ if (!firstEntry || !firstEntry.product) {
1006
+ return;
1007
+ }
1008
+
1009
+ const product = firstEntry.product;
1010
+ const displayPrice = Wick.BloomreachWidget.getDisplayPrice(product);
1011
+ const priceExcVat = Wick.BloomreachWidget.getDisplayPriceExcVat(product);
1012
+ const wasPriceFormatted = Wick.BloomreachWidget.getWasPriceFormatted(product);
1013
+
1014
+ Wick.BloomreachWidget.updateSummary($root, {
1015
+ totalPrice: Wick.BloomreachWidget.getPriceFormattedValue(displayPrice) || '£0.00',
1016
+ totalWasPrice: wasPriceFormatted || null,
1017
+ totalPriceExclusiveVat: Wick.BloomreachWidget.getPriceFormattedValue(priceExcVat),
1018
+ totalWasPriceExclusiveVat: Wick.BloomreachWidget.getExcVatWasPrice(product) || null,
1019
+ });
1020
+ },
1021
+
1022
+ initQuantityField($root, inputSel) {
1023
+ const stepper = createCountStepper({
1024
+ inputSel,
1025
+ min: 1,
1026
+ onChange(qty, inputEl) {
1027
+ const $input = $(inputEl);
1028
+ const $card = $input.closest(Wick.BloomreachWidget.el.completeCard);
1029
+ const $completeWidget = $input.closest(Wick.BloomreachWidget.el.completeWidget);
1030
+ const $checkbox = $card.find(Wick.BloomreachWidget.el.cardCheckbox);
1031
+ const previousQuantity =
1032
+ $input.data(Wick.BloomreachWidget.el.previousQuantityData) || 1;
1033
+
1034
+ if (!$input.data(Wick.BloomreachWidget.el.quantityReadyData)) {
1035
+ $input.data(Wick.BloomreachWidget.el.previousQuantityData, qty || 1);
1036
+ return;
1037
+ }
1038
+
1039
+ if (!Wick.BloomreachWidget.validateCardDropdown($card)) {
1040
+ $input.val(previousQuantity);
1041
+
1042
+ const $minus = $card.find('.count-btn--minus');
1043
+
1044
+ if (previousQuantity <= 1) {
1045
+ $minus.prop('disabled', true);
1046
+ }
1047
+
1048
+ return;
1049
+ }
1050
+
1051
+ $checkbox.prop('checked', true);
1052
+ $card.addClass(Wick.BloomreachWidget.el.selectedClass);
1053
+
1054
+ $input.data(Wick.BloomreachWidget.el.previousQuantityData, qty);
1055
+ $input.trigger('change');
1056
+
1057
+ if ($completeWidget.length) {
1058
+ Wick.BloomreachWidget.dispatchCalculateTotal($completeWidget);
1059
+ }
1060
+ },
1061
+ });
1062
+
1063
+ stepper.init($root);
1064
+
1065
+ $root.find(inputSel).data(Wick.BloomreachWidget.el.quantityReadyData, true);
1066
+
1067
+ Wick.BloomreachWidget.steppers.push(stepper);
1068
+ },
1069
+
1070
+ initQuantityFields($root) {
1071
+ const {
1072
+ quantityInput,
1073
+ countStepperInitializedData,
1074
+ countStepperRoot,
1075
+ previousQuantityData,
1076
+ } = Wick.BloomreachWidget.el;
1077
+
1078
+ $root.find(quantityInput).each(function () {
1079
+ const $input = $(this);
1080
+
1081
+ if ($input.data(countStepperInitializedData)) {
1082
+ return;
1083
+ }
1084
+
1085
+ const inputId = $input.attr('id');
1086
+
1087
+ if (!inputId) {
1088
+ return;
1089
+ }
1090
+
1091
+ $input.data(countStepperInitializedData, true);
1092
+ $input.data(previousQuantityData, parseInt($input.val(), 10) || 1);
1093
+
1094
+ Wick.BloomreachWidget.initQuantityField(
1095
+ $input.closest(countStepperRoot),
1096
+ `#${inputId}`
1097
+ );
1098
+ });
1099
+ },
1100
+
1101
+ formatPrice(value) {
1102
+ return new Intl.NumberFormat('en-GB', {
1103
+ style: 'currency',
1104
+ currency: 'GBP',
1105
+ minimumFractionDigits: 2,
1106
+ maximumFractionDigits: 2,
1107
+ }).format(value);
1108
+ },
1109
+
1110
+ resetWidgetState($root) {
1111
+ $root.find(Wick.BloomreachWidget.el.cardCheckbox).prop('checked', false);
1112
+
1113
+ $root
1114
+ .find(Wick.BloomreachWidget.el.completeCard)
1115
+ .removeClass(Wick.BloomreachWidget.el.selectedClass);
1116
+
1117
+ $root
1118
+ .find(Wick.BloomreachWidget.el.quantityInput)
1119
+ .val(1)
1120
+ .data(Wick.BloomreachWidget.el.previousQuantityData, 1);
1121
+ },
1122
+
1123
+ resetBackForwardState() {
1124
+ $(Wick.BloomreachWidget.el.completeWidget).each(function () {
1125
+ const $widget = $(this);
1126
+
1127
+ Wick.BloomreachWidget.resetWidgetState($widget);
1128
+ Wick.BloomreachWidget.bindCardSelection($widget);
1129
+ });
1130
+ },
1131
+
1132
+ initRenderedWidget($container) {
1133
+ if (!Wick.BloomreachWidget.toast) {
1134
+ Wick.BloomreachWidget.toast = createToast({
1135
+ template: notificationTemplate,
1136
+ });
1137
+ }
1138
+ if (!Wick.BloomreachWidget.loadingButton) {
1139
+ Wick.BloomreachWidget.loadingButton = createLoadingButton();
1140
+ }
1141
+ const $completeWidget = $container.find(Wick.BloomreachWidget.el.completeWidget);
1142
+
1143
+ if (!$completeWidget.length) {
1144
+ return;
1145
+ }
1146
+
1147
+ Wick.BloomreachWidget.drawRating($completeWidget);
1148
+ Wick.BloomreachWidget.bindCardSelection($completeWidget);
1149
+ Wick.BloomreachWidget.bindDropdowns();
1150
+ Wick.BloomreachWidget.bindDropdownValidation($completeWidget);
1151
+ Wick.BloomreachWidget.bindAddToCart($completeWidget);
1152
+ Wick.BloomreachWidget.initQuantityFields($completeWidget);
1153
+
1154
+ $completeWidget
1155
+ .find(Wick.BloomreachWidget.el.dropdownRoot)
1156
+ .removeClass(Wick.BloomreachWidget.el.dropdownErrorClass);
1157
+
1158
+ Wick.BloomreachWidget.alignCardBlocks($completeWidget);
1159
+ Wick.BloomreachWidget.updateCta($completeWidget);
1160
+ Wick.BloomreachWidget.setInitialSummary($completeWidget);
1161
+ },
1162
+
1163
+ init(payloadData) {
1164
+ const $containers = $(Wick.BloomreachWidget.el.widgetContainer);
1165
+
1166
+ if (!payloadData || !Wick.BloomreachWidget.hasRecommendations(payloadData)) {
1167
+ $containers.find(Wick.BloomreachWidget.el.completeWidget).hide();
1168
+ return;
1169
+ }
1170
+
1171
+ Wick.BloomreachWidget.renderWidgetFromPayload(payloadData);
1172
+ },
1173
+ };
1174
+
1175
+ $(document).ready(function () {
1176
+ Wick.Responsive.onResize(function () {
1177
+ $(Wick.BloomreachWidget.el.widgetContainer).each(function () {
1178
+ const $completeWidget = $(this).find(Wick.BloomreachWidget.el.completeWidget);
1179
+
1180
+ if ($completeWidget.length) {
1181
+ Wick.BloomreachWidget.alignCardBlocks($completeWidget);
1182
+ }
1183
+ });
1184
+ });
1185
+ });
1186
+
1187
+ window.addEventListener('pagehide', function () {
1188
+ Wick.BloomreachWidget.resetBackForwardState();
1189
+ });