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