wickes-css2 2.111.0-develop.1 → 2.111.0-why-not-add.1

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 (112) hide show
  1. package/build/css/category-main.css +1 -1
  2. package/build/css/homepage-main.css +1 -1
  3. package/build/css/kitchen-plp-main.css +1 -1
  4. package/build/css/main.css +1 -1
  5. package/build/css/my-account-main-v2.css +1 -1
  6. package/build/css/my-account-main.css +1 -1
  7. package/build/css/pages/page_personal-details.css +1 -1
  8. package/build/css/pages/page_product-details-v2.css +1 -1
  9. package/build/css/pdp-main-before-combine.css +1 -1
  10. package/build/css/pdp-main-critical.css +1 -1
  11. package/build/css/pdp-main-non-critical.css +1 -1
  12. package/build/css/pdp-main.css +1 -1
  13. package/build/css/plp-main.css +1 -1
  14. package/build/css/store-locator-main.css +1 -1
  15. package/build/js/account-hub.min.js +1 -1
  16. package/build/js/basket.min.js +1 -1
  17. package/build/js/bloomreach-widget.min.js +1 -0
  18. package/build/js/bundle.min.js +1 -1
  19. package/build/js/checkout.min.js +1 -1
  20. package/build/js/emulation.min.js +3026 -217
  21. package/build/js/general.bundle.min.js +1 -1
  22. package/build/js/merged-checkout.min.js +1 -1
  23. package/build/js/page/bloomreach-widget.js +1213 -0
  24. package/build/js/page/utils/create-count-stepper.js +30 -9
  25. package/build/js/page/utils/create-loading-button.js +37 -0
  26. package/build/js/page/utils/create-toast.js +79 -0
  27. package/build/js/page/utils/custom-dropdown.js +80 -0
  28. package/build/js/pdp-count-stepper.min.js +1 -1
  29. package/build/js/pdp.bundle.min.js +1 -1
  30. package/build/js/plp.bundle.min.js +1 -1
  31. package/build/js/project-list.min.js +1 -1
  32. package/build/js/saving-shopping-list.min.js +1 -1
  33. package/package.json +1 -1
  34. package/src/components/base/button.hbs +23 -5
  35. package/src/components/bloomreach/complete-card-dropdown.hbs +47 -0
  36. package/src/components/bloomreach/complete-card-skeleton.hbs +19 -0
  37. package/src/components/bloomreach/complete-card.hbs +138 -0
  38. package/src/components/bloomreach/complete-divider.hbs +3 -0
  39. package/src/components/bloomreach/complete-summary-skeleton.hbs +12 -0
  40. package/src/components/bloomreach/complete-summary.hbs +43 -0
  41. package/src/components/bloomreach/complete-wrapper.hbs +1 -0
  42. package/src/components/bloomreach/complete-your-project.hbs +21 -0
  43. package/src/components/gift-cards.hbs +1 -1
  44. package/src/elements/checkbox.hbs +8 -1
  45. package/src/js/components/general/cart-slider.js +19 -6
  46. package/src/js/emulation/bloomreach-widget-calculations.js +140 -0
  47. package/src/js/emulation/bloomreach-widget-loading.js +11 -0
  48. package/src/js/emulation/mock.js +3098 -1
  49. package/src/js/emulation/notify-me.js +1 -1
  50. package/src/js/page/bloomreach-widget.js +1213 -0
  51. package/src/js/page/utils/create-count-stepper.js +30 -9
  52. package/src/js/page/utils/create-loading-button.js +37 -0
  53. package/src/js/page/utils/create-toast.js +79 -0
  54. package/src/js/page/utils/custom-dropdown.js +80 -0
  55. package/src/page_product-details-banner.html +0 -1
  56. package/src/page_product-details-big-wins-disabled-delivery.html +0 -1
  57. package/src/page_product-details-big-wins-non-registered.html +0 -1
  58. package/src/page_product-details-big-wins-out-nearest.html +0 -1
  59. package/src/page_product-details-big-wins-unhappy.html +0 -1
  60. package/src/page_product-details-big-wins.html +0 -1
  61. package/src/page_product-details-billie.html +0 -1
  62. package/src/page_product-details-bloomreach.html +130 -0
  63. package/src/page_product-details-calculator.html +0 -1
  64. package/src/page_product-details-cashback-v2.html +0 -1
  65. package/src/page_product-details-clearpay.html +0 -1
  66. package/src/page_product-details-cnc-error-notification.html +0 -1
  67. package/src/page_product-details-cnc-success-notification-vat.html +0 -1
  68. package/src/page_product-details-cnc-success-notification.html +0 -1
  69. package/src/page_product-details-default-store.html +0 -1
  70. package/src/page_product-details-energy-efficiency.html +0 -1
  71. package/src/page_product-details-flooring-with-pr-placeholder.html +0 -1
  72. package/src/page_product-details-flooring.html +0 -1
  73. package/src/page_product-details-gallery-actual.html +0 -1
  74. package/src/page_product-details-mfe-calculator.html +0 -1
  75. package/src/page_product-details-minimum-v2.html +0 -1
  76. package/src/page_product-details-mtm-doors.html +0 -1
  77. package/src/page_product-details-only-clearpay.html +0 -1
  78. package/src/page_product-details-paint-mixing.html +0 -1
  79. package/src/page_product-details-saved-pl.html +0 -1
  80. package/src/page_product-details-tile-steps-klarna-widget-with-method-ids.html +0 -1
  81. package/src/page_product-details-tile-steps-logout.html +0 -1
  82. package/src/page_product-details-tile-steps-no-new-project-list.html +0 -1
  83. package/src/page_product-details-tile-steps-with-klarna.html +0 -1
  84. package/src/page_product-details-tile-steps.html +0 -1
  85. package/src/page_product-details-v2.html +0 -1
  86. package/src/page_product-details-vat.html +0 -1
  87. package/src/page_product-details-wisdom-mcfc-registered.html +0 -1
  88. package/src/page_product-details-wisdom-mcfc.html +0 -1
  89. package/src/page_product-details-wisdom-oos-registered.html +0 -1
  90. package/src/page_product-details-wisdom-oos.html +0 -1
  91. package/src/page_product-details-wisdom-registered.html +0 -1
  92. package/src/page_product-details-wisdom.html +0 -1
  93. package/src/page_product-details-with-favourite.html +0 -1
  94. package/src/page_product-details-with-global-search-v2.html +7 -1
  95. package/src/page_product-details_no-previous-default.html +0 -1
  96. package/src/page_track-my-order-result.html +1 -0
  97. package/src/partials/scripts.hbs +1 -0
  98. package/src/scss/common/_common.scss +1 -0
  99. package/src/scss/common/_elements.scss +13 -1
  100. package/src/scss/common/_loading-button.scss +49 -0
  101. package/src/scss/components/_notifications.scss +86 -5
  102. package/src/scss/components/bloomreach/_bloomreach.scss +3 -0
  103. package/src/scss/components/bloomreach/_complete-card-dropdown.scss +174 -0
  104. package/src/scss/components/bloomreach/_complete-card.scss +408 -0
  105. package/src/scss/components/bloomreach/_complete-your-project.scss +207 -0
  106. package/src/scss/helpers/_variables.scss +1 -0
  107. package/src/scss/pages/page_product-details-v2.scss +45 -2
  108. package/src/scss/pdp-main-critical.scss +0 -1
  109. package/src/scss/pdp-main.scss +1 -1
  110. package/src/sitemap.html +6 -0
  111. package/src/scss/components/_pdp-action-v2-critical.scss +0 -27
  112. package/src/scss/components/_pdp-action-v2.scss +0 -27
@@ -0,0 +1,1213 @@
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
+ let timeoutId;
674
+
675
+ const cleanup = function () {
676
+ window.removeEventListener('productAddedToCart', onProductAddedToCart);
677
+ window.clearTimeout(timeoutId);
678
+ };
679
+
680
+ const onProductAddedToCart = function (event) {
681
+ const response = event.detail || {};
682
+
683
+ if (!response.bulkAddToCartData) {
684
+ return;
685
+ }
686
+
687
+ cleanup();
688
+ resolve(response);
689
+ };
690
+
691
+ window.addEventListener('productAddedToCart', onProductAddedToCart);
692
+
693
+ timeoutId = window.setTimeout(function () {
694
+ cleanup();
695
+ reject();
696
+ }, 10000);
697
+
698
+ window.dispatchEvent(
699
+ new CustomEvent(Wick.BloomreachWidget.ADD_PRODUCT_BUNDLE_TO_CART_EVENT, {
700
+ detail: {
701
+ entries: Wick.BloomreachWidget.getAddToCartEntries($root),
702
+ reject: function (error) {
703
+ cleanup();
704
+ reject(error);
705
+ },
706
+ },
707
+ })
708
+ );
709
+ })
710
+ .then(function (response) {
711
+ Wick.BloomreachWidget.handleBulkAddToCartResponse(response);
712
+ })
713
+ .catch(function () {
714
+ Wick.BloomreachWidget.handleBulkAddToCartResponse({
715
+ bulkAddToCartData: {
716
+ messageType: 'error',
717
+ messageText: 'Selected product(s) were not added to basket',
718
+ },
719
+ });
720
+ })
721
+ .finally(function () {
722
+ Wick.BloomreachWidget.loadingButton.stop($button);
723
+ Wick.BloomreachWidget.updateCta($root);
724
+ });
725
+ },
726
+
727
+ reinitCard($card) {
728
+ const { countBtn, completeWidget } = Wick.BloomreachWidget.el;
729
+
730
+ $card.find(countBtn).remove();
731
+
732
+ Wick.BloomreachWidget.initQuantityFields($card);
733
+ Wick.BloomreachWidget.drawRating($card);
734
+ Wick.BloomreachWidget.alignCardBlocks($card.closest(completeWidget));
735
+ },
736
+
737
+ replaceCardWithBaseProduct($dropdown, options = {}) {
738
+ const {
739
+ completeCard,
740
+ recommendationIndexAttr,
741
+ dropdownRoot,
742
+ dropdownErrorClass,
743
+ cardCheckbox,
744
+ } = Wick.BloomreachWidget.el;
745
+
746
+ const $card = $dropdown.closest(completeCard);
747
+ const recommendationIndex = Number($card.attr(recommendationIndexAttr));
748
+ const recommendation = Wick.BloomreachWidget.recommendations[recommendationIndex];
749
+
750
+ if (!recommendation || !recommendation.baseProduct) {
751
+ return null;
752
+ }
753
+
754
+ const productData = Wick.BloomreachWidget.getProductRenderData(
755
+ recommendation.baseProduct,
756
+ recommendationIndex,
757
+ {
758
+ dropdownError: options.dropdownError || false,
759
+ checked: false,
760
+ }
761
+ );
762
+
763
+ const newCardHtml = completeCardTemplate(productData);
764
+ const $newCard = $(newCardHtml);
765
+
766
+ $newCard.attr(recommendationIndexAttr, recommendationIndex);
767
+
768
+ if (options.dropdownError) {
769
+ $newCard.find(dropdownRoot).addClass(dropdownErrorClass);
770
+ }
771
+
772
+ $card.replaceWith($newCard);
773
+
774
+ $newCard.find(cardCheckbox).prop('checked', false);
775
+
776
+ $newCard
777
+ .find(Wick.BloomreachWidget.el.quantityInput)
778
+ .val(1)
779
+ .data(Wick.BloomreachWidget.el.previousQuantityData, 1)
780
+ .removeData(Wick.BloomreachWidget.el.quantityReadyData)
781
+ .removeData(Wick.BloomreachWidget.el.countStepperInitializedData);
782
+
783
+ Wick.BloomreachWidget.reinitCard($newCard);
784
+
785
+ return $newCard;
786
+ },
787
+
788
+ replaceCardWithVariant($dropdown, selectedValue) {
789
+ const {
790
+ completeCard,
791
+ recommendationIndexAttr,
792
+ selectedClass,
793
+ dropdownRoot,
794
+ selectedValueData,
795
+ cardCheckbox,
796
+ } = Wick.BloomreachWidget.el;
797
+
798
+ const $card = $dropdown.closest(completeCard);
799
+ const recommendationIndex = Number($card.attr(recommendationIndexAttr));
800
+ const recommendation = Wick.BloomreachWidget.recommendations[recommendationIndex];
801
+
802
+ if (!recommendation) {
803
+ return null;
804
+ }
805
+
806
+ const variantProduct = Wick.BloomreachWidget.findVariantProduct(
807
+ recommendation,
808
+ selectedValue
809
+ );
810
+
811
+ if (!variantProduct) {
812
+ return null;
813
+ }
814
+
815
+ const productData = Wick.BloomreachWidget.getProductRenderData(
816
+ {
817
+ ...variantProduct,
818
+ variantOptions: recommendation.baseProduct.variantOptions,
819
+ },
820
+ recommendationIndex,
821
+ {
822
+ fallbackProduct: recommendation.baseProduct,
823
+ checked: true,
824
+ selectedDropdownValue: selectedValue,
825
+ }
826
+ );
827
+
828
+ const newCardHtml = completeCardTemplate(productData);
829
+ const $newCard = $(newCardHtml);
830
+
831
+ $newCard.attr(recommendationIndexAttr, recommendationIndex);
832
+ $newCard.addClass(selectedClass);
833
+
834
+ const $newDropdown = $newCard.find(dropdownRoot);
835
+
836
+ if ($newDropdown.length) {
837
+ $newDropdown.data(selectedValueData, selectedValue);
838
+ }
839
+
840
+ $card.replaceWith($newCard);
841
+
842
+ $newCard.find(cardCheckbox).prop('checked', true);
843
+
844
+ $newCard
845
+ .find(Wick.BloomreachWidget.el.quantityInput)
846
+ .val(1)
847
+ .data(Wick.BloomreachWidget.el.previousQuantityData, 1)
848
+ .removeData(Wick.BloomreachWidget.el.quantityReadyData)
849
+ .removeData(Wick.BloomreachWidget.el.countStepperInitializedData);
850
+
851
+ Wick.BloomreachWidget.reinitCard($newCard);
852
+
853
+ return $newCard;
854
+ },
855
+
856
+ handleDropdownSelect($dropdown, selectedValue) {
857
+ const $card = $dropdown.closest(Wick.BloomreachWidget.el.completeCard);
858
+ const recommendationIndex = $card.attr(Wick.BloomreachWidget.el.recommendationIndexAttr);
859
+ const currentValue = Wick.BloomreachWidget.dropdownCurrent[recommendationIndex];
860
+
861
+ if (`${currentValue}` === `${selectedValue}`) {
862
+ return;
863
+ }
864
+
865
+ Wick.BloomreachWidget.dropdownCurrent[recommendationIndex] = selectedValue;
866
+
867
+ const $completeWidget = $dropdown.closest(Wick.BloomreachWidget.el.completeWidget);
868
+ const isPlaceholder = !selectedValue;
869
+
870
+ if (isPlaceholder) {
871
+ Wick.BloomreachWidget.setDropdownError($dropdown, true);
872
+ Wick.BloomreachWidget.setDropdownCheckboxState($dropdown, false, false);
873
+ Wick.BloomreachWidget.replaceCardWithBaseProduct($dropdown, {
874
+ dropdownError: true,
875
+ });
876
+
877
+ if ($completeWidget.length) {
878
+ Wick.BloomreachWidget.dispatchCalculateTotal($completeWidget);
879
+ }
880
+
881
+ return;
882
+ }
883
+
884
+ Wick.BloomreachWidget.setDropdownError($dropdown, false);
885
+ Wick.BloomreachWidget.setDropdownCheckboxState($dropdown, true, false);
886
+ Wick.BloomreachWidget.replaceCardWithVariant($dropdown, selectedValue);
887
+
888
+ if ($completeWidget.length) {
889
+ Wick.BloomreachWidget.dispatchCalculateTotal($completeWidget);
890
+ }
891
+ },
892
+
893
+ bindDropdowns() {
894
+ const {
895
+ dropdownRoot,
896
+ dropdownToggle,
897
+ dropdownValue,
898
+ dropdownOption,
899
+ dropdownOpenClass,
900
+ dropdownOptionSelectedClass,
901
+ } = Wick.BloomreachWidget.el;
902
+
903
+ Wick.BloomreachWidget.dropdown = createDropdown({
904
+ root: dropdownRoot,
905
+ toggle: dropdownToggle,
906
+ value: dropdownValue,
907
+ option: dropdownOption,
908
+ openClass: dropdownOpenClass,
909
+ selectedClass: dropdownOptionSelectedClass,
910
+ namespace: 'bloomreachDropdown',
911
+ onSelect($dropdown, $option, selectedValue) {
912
+ Wick.BloomreachWidget.handleDropdownSelect($dropdown, selectedValue);
913
+ },
914
+ });
915
+
916
+ Wick.BloomreachWidget.dropdown.bind();
917
+ },
918
+
919
+ bindCardSelection($root) {
920
+ const { completeCard, cardCheckbox, selectedClass } = Wick.BloomreachWidget.el;
921
+
922
+ const $firstCard = $root.find(completeCard).first();
923
+
924
+ $firstCard.find(cardCheckbox).prop('checked', true);
925
+ $firstCard.addClass(selectedClass);
926
+
927
+ $root.off('change.bloomreachCardSelection', cardCheckbox);
928
+ $root.on('change.bloomreachCardSelection', cardCheckbox, function () {
929
+ const $checkbox = $(this);
930
+ const $card = $checkbox.closest(completeCard);
931
+ const $dropdown = $card.find(Wick.BloomreachWidget.el.dropdownRoot);
932
+
933
+ if (
934
+ !$checkbox.prop('checked') &&
935
+ $dropdown.hasClass(Wick.BloomreachWidget.el.dropdownErrorClass)
936
+ ) {
937
+ $card.removeClass(selectedClass);
938
+ return;
939
+ }
940
+
941
+ if (
942
+ $checkbox.prop('checked') &&
943
+ !Wick.BloomreachWidget.validateCardDropdown($card, {
944
+ uncheck: true,
945
+ })
946
+ ) {
947
+ $checkbox.prop('checked', false);
948
+ $card.removeClass(selectedClass);
949
+ return;
950
+ }
951
+
952
+ $card.toggleClass(selectedClass, this.checked);
953
+
954
+ Wick.BloomreachWidget.dispatchCalculateTotal($root);
955
+ });
956
+ },
957
+
958
+ bindDropdownValidation($root) {
959
+ const { cardCheckbox, completeCard } = Wick.BloomreachWidget.el;
960
+
961
+ $root.off('click.bloomreachDropdownValidation', cardCheckbox);
962
+ $root.on('click.bloomreachDropdownValidation', cardCheckbox, function () {
963
+ const $checkbox = $(this);
964
+ const $card = $checkbox.closest(completeCard);
965
+
966
+ if (
967
+ $checkbox.prop('checked') &&
968
+ !Wick.BloomreachWidget.validateCardDropdown($card, {
969
+ uncheck: true,
970
+ })
971
+ ) {
972
+ $checkbox.prop('checked', false);
973
+ $card.removeClass(Wick.BloomreachWidget.el.selectedClass);
974
+ }
975
+ });
976
+ },
977
+
978
+ bindAddToCart($root) {
979
+ const { ctaButton } = Wick.BloomreachWidget.el;
980
+
981
+ $root.off('click.bloomreachAddToCart', ctaButton);
982
+ $root.on('click.bloomreachAddToCart', ctaButton, function (event) {
983
+ event.preventDefault();
984
+
985
+ const $button = $(this);
986
+
987
+ if (
988
+ $button.prop('disabled') ||
989
+ Wick.BloomreachWidget.loadingButton.isLoading($button)
990
+ ) {
991
+ return;
992
+ }
993
+
994
+ Wick.BloomreachWidget.dispatchAddToCart($root, $button);
995
+ });
996
+ },
997
+
998
+ alignBlock(selector, $root) {
999
+ const $els = $root.find(selector);
1000
+
1001
+ $els.css('min-height', '');
1002
+
1003
+ if (!$els.length || Wick.Responsive.getCurrentBreakpoint() !== 'up-lg') {
1004
+ return;
1005
+ }
1006
+
1007
+ let maxHeight = 0;
1008
+
1009
+ $els.each(function () {
1010
+ maxHeight = Math.max(maxHeight, $(this).height());
1011
+ });
1012
+
1013
+ if (maxHeight > 0) {
1014
+ $els.css('min-height', maxHeight + 'px');
1015
+ }
1016
+ },
1017
+
1018
+ alignCardBlocks($root) {
1019
+ const { titleEl, optionsEl } = Wick.BloomreachWidget.el;
1020
+
1021
+ Wick.BloomreachWidget.alignBlock(titleEl, $root);
1022
+ Wick.BloomreachWidget.alignBlock(optionsEl, $root);
1023
+ },
1024
+
1025
+ setInitialSummary($root) {
1026
+ const entries = Wick.BloomreachWidget.getSelectedEntries($root);
1027
+ const firstEntry = entries[0];
1028
+
1029
+ if (!firstEntry || !firstEntry.product) {
1030
+ return;
1031
+ }
1032
+
1033
+ const product = firstEntry.product;
1034
+ const displayPrice = Wick.BloomreachWidget.getDisplayPrice(product);
1035
+ const priceExcVat = Wick.BloomreachWidget.getDisplayPriceExcVat(product);
1036
+ const wasPriceFormatted = Wick.BloomreachWidget.getWasPriceFormatted(product);
1037
+
1038
+ Wick.BloomreachWidget.updateSummary($root, {
1039
+ totalPrice: Wick.BloomreachWidget.getPriceFormattedValue(displayPrice) || '£0.00',
1040
+ totalWasPrice: wasPriceFormatted || null,
1041
+ totalPriceExclusiveVat: Wick.BloomreachWidget.getPriceFormattedValue(priceExcVat),
1042
+ totalWasPriceExclusiveVat: Wick.BloomreachWidget.getExcVatWasPrice(product) || null,
1043
+ });
1044
+ },
1045
+
1046
+ initQuantityField($root, inputSel) {
1047
+ const stepper = createCountStepper({
1048
+ inputSel,
1049
+ min: 1,
1050
+ onChange(qty, inputEl) {
1051
+ const $input = $(inputEl);
1052
+ const $card = $input.closest(Wick.BloomreachWidget.el.completeCard);
1053
+ const $completeWidget = $input.closest(Wick.BloomreachWidget.el.completeWidget);
1054
+ const $checkbox = $card.find(Wick.BloomreachWidget.el.cardCheckbox);
1055
+ const previousQuantity =
1056
+ $input.data(Wick.BloomreachWidget.el.previousQuantityData) || 1;
1057
+
1058
+ if (!$input.data(Wick.BloomreachWidget.el.quantityReadyData)) {
1059
+ $input.data(Wick.BloomreachWidget.el.previousQuantityData, qty || 1);
1060
+ return;
1061
+ }
1062
+
1063
+ if (!Wick.BloomreachWidget.validateCardDropdown($card)) {
1064
+ $input.val(previousQuantity);
1065
+
1066
+ const $minus = $card.find('.count-btn--minus');
1067
+
1068
+ if (previousQuantity <= 1) {
1069
+ $minus.prop('disabled', true);
1070
+ }
1071
+
1072
+ return;
1073
+ }
1074
+
1075
+ $checkbox.prop('checked', true);
1076
+ $card.addClass(Wick.BloomreachWidget.el.selectedClass);
1077
+
1078
+ $input.data(Wick.BloomreachWidget.el.previousQuantityData, qty);
1079
+ $input.trigger('change');
1080
+
1081
+ if ($completeWidget.length) {
1082
+ Wick.BloomreachWidget.dispatchCalculateTotal($completeWidget);
1083
+ }
1084
+ },
1085
+ });
1086
+
1087
+ stepper.init($root);
1088
+
1089
+ $root.find(inputSel).data(Wick.BloomreachWidget.el.quantityReadyData, true);
1090
+
1091
+ Wick.BloomreachWidget.steppers.push(stepper);
1092
+ },
1093
+
1094
+ initQuantityFields($root) {
1095
+ const {
1096
+ quantityInput,
1097
+ countStepperInitializedData,
1098
+ countStepperRoot,
1099
+ previousQuantityData,
1100
+ } = Wick.BloomreachWidget.el;
1101
+
1102
+ $root.find(quantityInput).each(function () {
1103
+ const $input = $(this);
1104
+
1105
+ if ($input.data(countStepperInitializedData)) {
1106
+ return;
1107
+ }
1108
+
1109
+ const inputId = $input.attr('id');
1110
+
1111
+ if (!inputId) {
1112
+ return;
1113
+ }
1114
+
1115
+ $input.data(countStepperInitializedData, true);
1116
+ $input.data(previousQuantityData, parseInt($input.val(), 10) || 1);
1117
+
1118
+ Wick.BloomreachWidget.initQuantityField(
1119
+ $input.closest(countStepperRoot),
1120
+ `#${inputId}`
1121
+ );
1122
+ });
1123
+ },
1124
+
1125
+ formatPrice(value) {
1126
+ return new Intl.NumberFormat('en-GB', {
1127
+ style: 'currency',
1128
+ currency: 'GBP',
1129
+ minimumFractionDigits: 2,
1130
+ maximumFractionDigits: 2,
1131
+ }).format(value);
1132
+ },
1133
+
1134
+ resetWidgetState($root) {
1135
+ $root.find(Wick.BloomreachWidget.el.cardCheckbox).prop('checked', false);
1136
+
1137
+ $root
1138
+ .find(Wick.BloomreachWidget.el.completeCard)
1139
+ .removeClass(Wick.BloomreachWidget.el.selectedClass);
1140
+
1141
+ $root
1142
+ .find(Wick.BloomreachWidget.el.quantityInput)
1143
+ .val(1)
1144
+ .data(Wick.BloomreachWidget.el.previousQuantityData, 1);
1145
+ },
1146
+
1147
+ resetBackForwardState() {
1148
+ $(Wick.BloomreachWidget.el.completeWidget).each(function () {
1149
+ const $widget = $(this);
1150
+
1151
+ Wick.BloomreachWidget.resetWidgetState($widget);
1152
+ Wick.BloomreachWidget.bindCardSelection($widget);
1153
+ });
1154
+ },
1155
+
1156
+ initRenderedWidget($container) {
1157
+ if (!Wick.BloomreachWidget.toast) {
1158
+ Wick.BloomreachWidget.toast = createToast({
1159
+ template: notificationTemplate,
1160
+ });
1161
+ }
1162
+ if (!Wick.BloomreachWidget.loadingButton) {
1163
+ Wick.BloomreachWidget.loadingButton = createLoadingButton();
1164
+ }
1165
+ const $completeWidget = $container.find(Wick.BloomreachWidget.el.completeWidget);
1166
+
1167
+ if (!$completeWidget.length) {
1168
+ return;
1169
+ }
1170
+
1171
+ Wick.BloomreachWidget.drawRating($completeWidget);
1172
+ Wick.BloomreachWidget.bindCardSelection($completeWidget);
1173
+ Wick.BloomreachWidget.bindDropdowns();
1174
+ Wick.BloomreachWidget.bindDropdownValidation($completeWidget);
1175
+ Wick.BloomreachWidget.bindAddToCart($completeWidget);
1176
+ Wick.BloomreachWidget.initQuantityFields($completeWidget);
1177
+
1178
+ $completeWidget
1179
+ .find(Wick.BloomreachWidget.el.dropdownRoot)
1180
+ .removeClass(Wick.BloomreachWidget.el.dropdownErrorClass);
1181
+
1182
+ Wick.BloomreachWidget.alignCardBlocks($completeWidget);
1183
+ Wick.BloomreachWidget.updateCta($completeWidget);
1184
+ Wick.BloomreachWidget.setInitialSummary($completeWidget);
1185
+ },
1186
+
1187
+ init(payloadData) {
1188
+ const $containers = $(Wick.BloomreachWidget.el.widgetContainer);
1189
+
1190
+ if (!payloadData || !Wick.BloomreachWidget.hasRecommendations(payloadData)) {
1191
+ $containers.find(Wick.BloomreachWidget.el.completeWidget).hide();
1192
+ return;
1193
+ }
1194
+
1195
+ Wick.BloomreachWidget.renderWidgetFromPayload(payloadData);
1196
+ },
1197
+ };
1198
+
1199
+ $(document).ready(function () {
1200
+ Wick.Responsive.onResize(function () {
1201
+ $(Wick.BloomreachWidget.el.widgetContainer).each(function () {
1202
+ const $completeWidget = $(this).find(Wick.BloomreachWidget.el.completeWidget);
1203
+
1204
+ if ($completeWidget.length) {
1205
+ Wick.BloomreachWidget.alignCardBlocks($completeWidget);
1206
+ }
1207
+ });
1208
+ });
1209
+ });
1210
+
1211
+ window.addEventListener('pagehide', function () {
1212
+ Wick.BloomreachWidget.resetBackForwardState();
1213
+ });