wickes-css2 2.110.0 → 2.111.0-complete-your-project.2

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