wickes-css2 2.113.0-develop.18 → 2.113.0-develop.19

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.
@@ -226,22 +226,9 @@ Wick.BloomreachWidget = {
226
226
  },
227
227
 
228
228
  getWasPriceFormatted(product) {
229
- const displayPrice = Wick.BloomreachWidget.getDisplayPrice(product);
230
- const wasPrice = Wick.BloomreachWidget.getWasPrice(product);
231
-
232
- if (wasPrice && wasPrice.formattedValue) {
233
- return wasPrice.formattedValue;
234
- }
235
-
236
- if (typeof wasPrice === 'number') {
237
- return Wick.BloomreachWidget.formatPrice(wasPrice);
238
- }
239
-
240
- if (wasPrice) {
241
- return `${displayPrice.currencySymbol || '£'}${wasPrice}`;
242
- }
243
-
244
- return '';
229
+ return Wick.BloomreachWidget.formatPromotionalPrice(
230
+ Wick.BloomreachWidget.getWasPrice(product)
231
+ );
245
232
  },
246
233
 
247
234
  getExcVatWasPrice(product) {
@@ -251,15 +238,7 @@ Wick.BloomreachWidget = {
251
238
  (displayPriceExclusiveVat && displayPriceExclusiveVat.wasPrice) ||
252
239
  (priceExclusiveVat && priceExclusiveVat.wasPrice);
253
240
 
254
- if (wasPrice && wasPrice.formattedValue) {
255
- return wasPrice.formattedValue;
256
- }
257
-
258
- if (typeof wasPrice === 'number') {
259
- return Wick.BloomreachWidget.formatPrice(wasPrice);
260
- }
261
-
262
- return wasPrice || '';
241
+ return Wick.BloomreachWidget.formatPromotionalPrice(wasPrice);
263
242
  },
264
243
 
265
244
  getProductImage(product, fallbackProduct) {
@@ -284,9 +263,15 @@ Wick.BloomreachWidget = {
284
263
  const displayPriceExcVat = Wick.BloomreachWidget.getDisplayPriceExcVat(product);
285
264
  const wasPriceFormatted = Wick.BloomreachWidget.getWasPriceFormatted(product);
286
265
  const isSwitchVat = !!(window.ACC && window.ACC.app && window.ACC.app.isVatToggleAvailable);
287
- const excVatFormattedValue = options.fallbackExcVat
266
+ const incVatFormattedValue = wasPriceFormatted
267
+ ? Wick.BloomreachWidget.formatPromotionalPrice(displayPrice)
268
+ : Wick.BloomreachWidget.getPriceFormattedValue(displayPrice);
269
+ const excVatValue = options.fallbackExcVat
288
270
  ? Wick.BloomreachWidget.getExcVatFormattedValue(product, displayPrice)
289
271
  : Wick.BloomreachWidget.getPriceFormattedValue(displayPriceExcVat);
272
+ const excVatFormattedValue = wasPriceFormatted
273
+ ? Wick.BloomreachWidget.formatPromotionalPrice(displayPriceExcVat || excVatValue)
274
+ : excVatValue;
290
275
 
291
276
  return {
292
277
  ...product,
@@ -297,7 +282,7 @@ Wick.BloomreachWidget = {
297
282
  Wick.BloomreachWidget.getProductImage(product, options.fallbackProduct),
298
283
  wasPriceFormatted,
299
284
  'switch-vat': isSwitchVat,
300
- incVatFormattedValue: Wick.BloomreachWidget.getPriceFormattedValue(displayPrice),
285
+ incVatFormattedValue,
301
286
  incVatValue: Wick.BloomreachWidget.getPriceValue(displayPrice),
302
287
  excVatFormattedValue,
303
288
  excVatValue: Wick.BloomreachWidget.getPriceValue(displayPriceExcVat),
@@ -361,6 +346,39 @@ Wick.BloomreachWidget = {
361
346
  $(window).off(eventName).on(eventName, Wick.BloomreachWidget.reapplyVatDisplay);
362
347
  },
363
348
 
349
+ formatPromotionalPrice(price) {
350
+ if (price === null || price === undefined) {
351
+ return '';
352
+ }
353
+
354
+ const rawValue =
355
+ typeof price === 'object'
356
+ ? typeof price.value === 'number'
357
+ ? price.value
358
+ : price.formattedValue
359
+ : price;
360
+
361
+ if (rawValue === null || rawValue === undefined || rawValue === '') {
362
+ return '';
363
+ }
364
+
365
+ const value =
366
+ typeof rawValue === 'number'
367
+ ? rawValue
368
+ : Number(`${rawValue}`.replace(/[,£\s]/g, ''));
369
+
370
+ if (!Number.isFinite(value)) {
371
+ return typeof rawValue === 'string' ? rawValue : '';
372
+ }
373
+
374
+ return new Intl.NumberFormat('en-GB', {
375
+ style: 'currency',
376
+ currency: 'GBP',
377
+ minimumFractionDigits: Math.round(Math.abs(value) * 100) % 100 === 0 ? 0 : 2,
378
+ maximumFractionDigits: 2,
379
+ }).format(value);
380
+ },
381
+
364
382
  formatPrice(value) {
365
383
  return new Intl.NumberFormat('en-GB', {
366
384
  style: 'currency',
@@ -70,16 +70,21 @@ export function createCompleteYourProjectView(model, presenter) {
70
70
  if (response.totalWasPrice) {
71
71
  $total.addClass('complete-widget__total-sale');
72
72
 
73
+ const formatPrice = Wick.BloomreachWidget.formatPromotionalPrice;
74
+ const wasPrice = formatPrice(response.totalWasPrice);
75
+ const salePrice = formatPrice(response.totalPrice);
76
+ const excVatWasPrice = formatPrice(totalWasPriceExclusiveVat || response.totalWasPrice);
77
+ const excVatSalePrice = formatPrice(totalPriceExclusiveVat || response.totalPrice);
73
78
  const $priceInc = $price.find(vatInc);
74
79
 
75
80
  if ($priceInc.length) {
76
- $priceInc.text(response.totalWasPrice);
77
- $price.find(vatExc).text(totalWasPriceExclusiveVat || response.totalWasPrice);
78
- $salePrice.find(vatInc).text(response.totalPrice || '');
79
- $salePrice.find(vatExc).text(totalPriceExclusiveVat || response.totalPrice || '');
81
+ $priceInc.text(wasPrice);
82
+ $price.find(vatExc).text(excVatWasPrice);
83
+ $salePrice.find(vatInc).text(salePrice);
84
+ $salePrice.find(vatExc).text(excVatSalePrice);
80
85
  } else {
81
- $price.text(response.totalWasPrice);
82
- $salePrice.text(response.totalPrice || '');
86
+ $price.text(wasPrice);
87
+ $salePrice.text(salePrice);
83
88
  }
84
89
 
85
90
  $salePrice.show();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wickes-css2",
3
- "version": "2.113.0-develop.18",
3
+ "version": "2.113.0-develop.19",
4
4
  "description": "CSS and JS and page templates in use by Wickes",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -81,7 +81,7 @@
81
81
  <span class="including-vat-inherit">{{{incVatFormattedValue}}}</span>
82
82
  <span class="excluding-vat-inherit">{{{excVatFormattedValue}}}</span>
83
83
  {{else}}
84
- {{{price.formattedValue}}}
84
+ {{incVatFormattedValue}}
85
85
  {{/if}}
86
86
  </div>
87
87
  {{else}}
@@ -65,7 +65,7 @@
65
65
  <span class="including-vat-inherit">{{incVatFormattedValue}}</span>
66
66
  <span class="excluding-vat-inherit">{{excVatFormattedValue}}</span>
67
67
  {{else}}
68
- {{price.formattedValue}}
68
+ {{incVatFormattedValue}}
69
69
  {{/if}}
70
70
  </span>
71
71
  {{else}}
@@ -10,7 +10,7 @@ function formatBundlePrice(value) {
10
10
  }
11
11
 
12
12
  function getPriceData(product) {
13
- return product.price || product.displayPrice || {};
13
+ return product.displayPrice || product.price || {};
14
14
  }
15
15
 
16
16
  function getBundleProductPrice(product) {
@@ -479,24 +479,24 @@ Wick.FEMock = {
479
479
 
480
480
  displayPrice: {
481
481
  currencyIso: 'GBP',
482
- value: 9999,
482
+ value: 1605,
483
483
  priceType: 'BUY',
484
- formattedValue: '£9,999.00',
485
- formattedPriceWithoutCurrencySymbol: '16',
484
+ formattedValue: '£1,605.00',
485
+ formattedPriceWithoutCurrencySymbol: '1605.00',
486
486
  currencySymbol: '£',
487
487
  vatRatePercentage: 20,
488
- valueInPence: 999900,
489
- wasPrice: 3000,
488
+ valueInPence: 160500,
489
+ wasPrice: 1899,
490
490
  },
491
491
  displayPriceExclusiveVat: {
492
492
  currencyIso: 'GBP',
493
- value: 9998,
493
+ value: 1337.5,
494
494
  priceType: 'BUY',
495
- formattedValue: '£9,998.00',
496
- formattedPriceWithoutCurrencySymbol: '13.33',
495
+ formattedValue: '£1,337.50',
496
+ formattedPriceWithoutCurrencySymbol: '1337.50',
497
497
  currencySymbol: '£',
498
- valueInPence: 999800,
499
- wasPrice: 2500,
498
+ valueInPence: 133750,
499
+ wasPrice: 1582.5,
500
500
  },
501
501
  },
502
502
  },
@@ -530,22 +530,22 @@ Wick.FEMock = {
530
530
  externalReviewCount: 48,
531
531
  displayPrice: {
532
532
  currencyIso: 'GBP',
533
- value: 9999,
533
+ value: 7.5,
534
534
  priceType: 'BUY',
535
- formattedValue: '£7.5220',
535
+ formattedValue: '£7.50',
536
536
  formattedPriceWithoutCurrencySymbol: '7.50',
537
537
  currencySymbol: '£',
538
538
  vatRatePercentage: 20,
539
- valueInPence: 999900,
539
+ valueInPence: 750,
540
540
  },
541
541
  displayPriceExclusiveVat: {
542
542
  currencyIso: 'GBP',
543
- value: 9998,
543
+ value: 6.25,
544
544
  priceType: 'BUY',
545
545
  formattedValue: '£6.25',
546
546
  formattedPriceWithoutCurrencySymbol: '6.25',
547
547
  currencySymbol: '£',
548
- valueInPence: 999800,
548
+ valueInPence: 625,
549
549
  },
550
550
  },
551
551
  },
@@ -767,16 +767,16 @@ Wick.FEMock = {
767
767
  price: {
768
768
  currencyIso: 'GBP',
769
769
  currencySymbol: '£',
770
- formattedPriceWithoutCurrencySymbol: '16',
771
- formattedValue: '£16',
770
+ formattedPriceWithoutCurrencySymbol: '18.50',
771
+ formattedValue: '£18.50',
772
772
  infoUom: 'L',
773
773
  infoUomDescription: 'L',
774
774
  infoUomPrice: 6.4,
775
775
  priceType: 'BUY',
776
- value: 16,
777
- valueInPence: 1600,
776
+ value: 18.5,
777
+ valueInPence: 1850,
778
778
  vatRatePercentage: 20,
779
- wasPrice: 24,
779
+ wasPrice: 24.5,
780
780
  },
781
781
  images: [
782
782
  {
@@ -1034,16 +1034,16 @@ Wick.FEMock = {
1034
1034
  },
1035
1035
  priceExclusiveVat: {
1036
1036
  currencyIso: 'GBP',
1037
- value: 15,
1037
+ value: 15.42,
1038
1038
  priceType: 'BUY',
1039
- formattedValue: '£15',
1040
- formattedPriceWithoutCurrencySymbol: '15',
1039
+ formattedValue: '£15.42',
1040
+ formattedPriceWithoutCurrencySymbol: '15.42',
1041
1041
  currencySymbol: '£',
1042
1042
  infoUom: 'length',
1043
1043
  infoUomDescription: 'length',
1044
1044
  infoUomPrice: 8.33,
1045
- valueInPence: 1500,
1046
- wasPrice: 20,
1045
+ valueInPence: 1542,
1046
+ wasPrice: 20.42,
1047
1047
  },
1048
1048
  downStreamData: {
1049
1049
  fulfillmentType: 'STANDARD',
@@ -1103,29 +1103,30 @@ Wick.FEMock = {
1103
1103
  isAddedToFavourites: false,
1104
1104
  displayPrice: {
1105
1105
  currencyIso: 'GBP',
1106
- value: 18,
1106
+ value: 18.5,
1107
1107
  priceType: 'BUY',
1108
- formattedValue: '£18',
1109
- formattedPriceWithoutCurrencySymbol: '18',
1108
+ formattedValue: '£18.50',
1109
+ formattedPriceWithoutCurrencySymbol: '18.50',
1110
1110
  currencySymbol: '£',
1111
1111
  infoUom: 'length',
1112
1112
  infoUomDescription: 'length',
1113
1113
  infoUomPrice: 10,
1114
1114
  vatRatePercentage: 20,
1115
- valueInPence: 1800,
1116
- wasPrice: 24,
1115
+ valueInPence: 1850,
1116
+ wasPrice: 24.5,
1117
1117
  },
1118
1118
  displayPriceExclusiveVat: {
1119
1119
  currencyIso: 'GBP',
1120
- value: 15,
1120
+ value: 15.42,
1121
1121
  priceType: 'BUY',
1122
- formattedValue: '£15',
1123
- formattedPriceWithoutCurrencySymbol: '15',
1122
+ formattedValue: '£15.42',
1123
+ formattedPriceWithoutCurrencySymbol: '15.42',
1124
1124
  currencySymbol: '£',
1125
1125
  infoUom: 'length',
1126
1126
  infoUomDescription: 'length',
1127
1127
  infoUomPrice: 8.33,
1128
- valueInPence: 1500,
1128
+ valueInPence: 1542,
1129
+ wasPrice: 20.42,
1129
1130
  },
1130
1131
  displayPromoDescription: '5.51 GBP discount for cart for 250064, 191018',
1131
1132
  displayPromoDescriptionExclusiveVat:
@@ -4038,6 +4039,28 @@ Wick.FEMock = {
4038
4039
 
4039
4040
  Wick.FEMock.dataBloomreach.similarProductsRecommendations = {
4040
4041
  ...Wick.FEMock.dataBloomreach.whyNotAddRecommendations,
4042
+ recommendedProducts: Wick.FEMock.dataBloomreach.whyNotAddRecommendations.recommendedProducts.map(
4043
+ function (recommendation, index) {
4044
+ if (index !== 1) {
4045
+ return recommendation;
4046
+ }
4047
+
4048
+ return {
4049
+ ...recommendation,
4050
+ baseProduct: {
4051
+ ...recommendation.baseProduct,
4052
+ displayPrice: {
4053
+ ...recommendation.baseProduct.displayPrice,
4054
+ wasPrice: 9.99,
4055
+ },
4056
+ displayPriceExclusiveVat: {
4057
+ ...recommendation.baseProduct.displayPriceExclusiveVat,
4058
+ wasPrice: 8.33,
4059
+ },
4060
+ },
4061
+ };
4062
+ }
4063
+ ),
4041
4064
  widgetMetadata: {
4042
4065
  responseId: 'mock-similar-products-response',
4043
4066
  id: 'similar-products-12345',
@@ -226,22 +226,9 @@ Wick.BloomreachWidget = {
226
226
  },
227
227
 
228
228
  getWasPriceFormatted(product) {
229
- const displayPrice = Wick.BloomreachWidget.getDisplayPrice(product);
230
- const wasPrice = Wick.BloomreachWidget.getWasPrice(product);
231
-
232
- if (wasPrice && wasPrice.formattedValue) {
233
- return wasPrice.formattedValue;
234
- }
235
-
236
- if (typeof wasPrice === 'number') {
237
- return Wick.BloomreachWidget.formatPrice(wasPrice);
238
- }
239
-
240
- if (wasPrice) {
241
- return `${displayPrice.currencySymbol || '£'}${wasPrice}`;
242
- }
243
-
244
- return '';
229
+ return Wick.BloomreachWidget.formatPromotionalPrice(
230
+ Wick.BloomreachWidget.getWasPrice(product)
231
+ );
245
232
  },
246
233
 
247
234
  getExcVatWasPrice(product) {
@@ -251,15 +238,7 @@ Wick.BloomreachWidget = {
251
238
  (displayPriceExclusiveVat && displayPriceExclusiveVat.wasPrice) ||
252
239
  (priceExclusiveVat && priceExclusiveVat.wasPrice);
253
240
 
254
- if (wasPrice && wasPrice.formattedValue) {
255
- return wasPrice.formattedValue;
256
- }
257
-
258
- if (typeof wasPrice === 'number') {
259
- return Wick.BloomreachWidget.formatPrice(wasPrice);
260
- }
261
-
262
- return wasPrice || '';
241
+ return Wick.BloomreachWidget.formatPromotionalPrice(wasPrice);
263
242
  },
264
243
 
265
244
  getProductImage(product, fallbackProduct) {
@@ -284,9 +263,15 @@ Wick.BloomreachWidget = {
284
263
  const displayPriceExcVat = Wick.BloomreachWidget.getDisplayPriceExcVat(product);
285
264
  const wasPriceFormatted = Wick.BloomreachWidget.getWasPriceFormatted(product);
286
265
  const isSwitchVat = !!(window.ACC && window.ACC.app && window.ACC.app.isVatToggleAvailable);
287
- const excVatFormattedValue = options.fallbackExcVat
266
+ const incVatFormattedValue = wasPriceFormatted
267
+ ? Wick.BloomreachWidget.formatPromotionalPrice(displayPrice)
268
+ : Wick.BloomreachWidget.getPriceFormattedValue(displayPrice);
269
+ const excVatValue = options.fallbackExcVat
288
270
  ? Wick.BloomreachWidget.getExcVatFormattedValue(product, displayPrice)
289
271
  : Wick.BloomreachWidget.getPriceFormattedValue(displayPriceExcVat);
272
+ const excVatFormattedValue = wasPriceFormatted
273
+ ? Wick.BloomreachWidget.formatPromotionalPrice(displayPriceExcVat || excVatValue)
274
+ : excVatValue;
290
275
 
291
276
  return {
292
277
  ...product,
@@ -297,7 +282,7 @@ Wick.BloomreachWidget = {
297
282
  Wick.BloomreachWidget.getProductImage(product, options.fallbackProduct),
298
283
  wasPriceFormatted,
299
284
  'switch-vat': isSwitchVat,
300
- incVatFormattedValue: Wick.BloomreachWidget.getPriceFormattedValue(displayPrice),
285
+ incVatFormattedValue,
301
286
  incVatValue: Wick.BloomreachWidget.getPriceValue(displayPrice),
302
287
  excVatFormattedValue,
303
288
  excVatValue: Wick.BloomreachWidget.getPriceValue(displayPriceExcVat),
@@ -361,6 +346,39 @@ Wick.BloomreachWidget = {
361
346
  $(window).off(eventName).on(eventName, Wick.BloomreachWidget.reapplyVatDisplay);
362
347
  },
363
348
 
349
+ formatPromotionalPrice(price) {
350
+ if (price === null || price === undefined) {
351
+ return '';
352
+ }
353
+
354
+ const rawValue =
355
+ typeof price === 'object'
356
+ ? typeof price.value === 'number'
357
+ ? price.value
358
+ : price.formattedValue
359
+ : price;
360
+
361
+ if (rawValue === null || rawValue === undefined || rawValue === '') {
362
+ return '';
363
+ }
364
+
365
+ const value =
366
+ typeof rawValue === 'number'
367
+ ? rawValue
368
+ : Number(`${rawValue}`.replace(/[,£\s]/g, ''));
369
+
370
+ if (!Number.isFinite(value)) {
371
+ return typeof rawValue === 'string' ? rawValue : '';
372
+ }
373
+
374
+ return new Intl.NumberFormat('en-GB', {
375
+ style: 'currency',
376
+ currency: 'GBP',
377
+ minimumFractionDigits: Math.round(Math.abs(value) * 100) % 100 === 0 ? 0 : 2,
378
+ maximumFractionDigits: 2,
379
+ }).format(value);
380
+ },
381
+
364
382
  formatPrice(value) {
365
383
  return new Intl.NumberFormat('en-GB', {
366
384
  style: 'currency',
@@ -70,16 +70,21 @@ export function createCompleteYourProjectView(model, presenter) {
70
70
  if (response.totalWasPrice) {
71
71
  $total.addClass('complete-widget__total-sale');
72
72
 
73
+ const formatPrice = Wick.BloomreachWidget.formatPromotionalPrice;
74
+ const wasPrice = formatPrice(response.totalWasPrice);
75
+ const salePrice = formatPrice(response.totalPrice);
76
+ const excVatWasPrice = formatPrice(totalWasPriceExclusiveVat || response.totalWasPrice);
77
+ const excVatSalePrice = formatPrice(totalPriceExclusiveVat || response.totalPrice);
73
78
  const $priceInc = $price.find(vatInc);
74
79
 
75
80
  if ($priceInc.length) {
76
- $priceInc.text(response.totalWasPrice);
77
- $price.find(vatExc).text(totalWasPriceExclusiveVat || response.totalWasPrice);
78
- $salePrice.find(vatInc).text(response.totalPrice || '');
79
- $salePrice.find(vatExc).text(totalPriceExclusiveVat || response.totalPrice || '');
81
+ $priceInc.text(wasPrice);
82
+ $price.find(vatExc).text(excVatWasPrice);
83
+ $salePrice.find(vatInc).text(salePrice);
84
+ $salePrice.find(vatExc).text(excVatSalePrice);
80
85
  } else {
81
- $price.text(response.totalWasPrice);
82
- $salePrice.text(response.totalPrice || '');
86
+ $price.text(wasPrice);
87
+ $salePrice.text(salePrice);
83
88
  }
84
89
 
85
90
  $salePrice.show();