@nuskin/ns-shop 5.20.13 → 5.20.14

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.
@@ -1,253 +0,0 @@
1
- /* eslint-disable */
2
- /**
3
- * Created by chad on 8/2/16.
4
- */
5
-
6
- import FireBaseProductService from './fireBaseProductService.js';
7
- import {ConfigService, RunConfigService, BrowserDetection, LocalStorageUtil, mktRegionMapping, util} from '@nuskin/ns-util';
8
-
9
- const FIREBASE_PRODUCT_KEY = "products";
10
- export default class FirebaseHealthUtil {
11
- constructor(country, language) {
12
- this.country = country;
13
- this.language = language;
14
- this.setConfiguration();
15
- this.loadedFireBaseProducts = FireBaseProductService.getProducts(country, language);
16
- }
17
-
18
- setConfiguration() {
19
- let siteConfigPath = "/content/configuration/global/markets/" + mktRegionMapping[this.country];
20
- let url = window.location.href;
21
- let arr = url.split("/");
22
- let tempRunConfig = {
23
- assessmentApp: false,
24
- language: this.language,
25
- country: this.country,
26
- baseUrl: arr[0] + "//" + arr[2],
27
- siteConfigurationPath: siteConfigPath
28
- };
29
- localStorage.setItem("run-config", JSON.stringify(tempRunConfig));
30
- RunConfigService.setRunConfig(tempRunConfig);
31
-
32
- this.marketConfig = ConfigService.getMarketConfig(true, this.country);
33
- if (typeof this.marketConfig === "undefined" || this.marketConfig === null) {
34
- console.error("Configuration not set. Please set the configuration to use FirebaseHealthUtil.");
35
- }
36
- if (!this.marketConfig.hasOwnProperty("useFirebaseProducts") || !this.marketConfig.useFirebaseProducts) {
37
- console.error("Firebase products not enabled for this market.");
38
- }
39
- }
40
-
41
- isFirebaseEnabledForMarket() {
42
- if (this.marketConfig.hasOwnProperty("useFirebaseProducts") && this.marketConfig.useFirebaseProducts){
43
- return "<span>Enabled</span>";
44
- } else {
45
- return "<span style='color: red;'>Not Enabled</span>";
46
- }
47
- }
48
-
49
- localStorageSpaceRemaining() {
50
- return (LocalStorageUtil.getRemainingLocalStorage() / 1024).toFixed(2) + " KB"
51
- }
52
-
53
- totalLocalStorageSpaceUsed() {
54
- return this.listLocaleStorageValueSizes().total;
55
- }
56
-
57
- fireBaseProductSize() {
58
- let localeStorageValues = this.listLocaleStorageValueSizes();
59
- if (localeStorageValues.hasOwnProperty(FIREBASE_PRODUCT_KEY)) {
60
- return localeStorageValues[FIREBASE_PRODUCT_KEY];
61
- } else {
62
- return (LocalStorageUtil.getByteLength(JSON.stringify(this.loadedFireBaseProducts)) / 1024).toFixed(2) + " KB";
63
- }
64
- }
65
-
66
- isFirebaseLoadedInStorage() {
67
- let localeStorageValues = this.listLocaleStorageValueSizes();
68
- return localeStorageValues.hasOwnProperty(FIREBASE_PRODUCT_KEY);
69
- }
70
-
71
- averageFirebaseProductSize() {
72
- let productSize = this.fireBaseProductSize().split(" ")[0];
73
- let numberOfProducts = this.numberOfProducts().totalProducts;
74
- return (productSize !== 0 && numberOfProducts !== 0) ? (productSize / numberOfProducts).toFixed(2) + " KB" : "Error";
75
- }
76
-
77
- listLocaleStorageValueSizes() {
78
- let _lsTotal=0,_xLen,_x;
79
- let values = {};
80
- for(_x in localStorage) {
81
- if (localStorage.hasOwnProperty(_x)) {
82
- _xLen = (LocalStorageUtil.getByteLength(localStorage[_x] + _x));
83
- _lsTotal += _xLen;
84
- values[_x] = ((_xLen / 1024).toFixed(2) + " KB");
85
- }
86
- }
87
- values["total"] = ((_lsTotal / 1024).toFixed(2) + " KB");
88
- values["totalNum"] = ((_lsTotal / 1024).toFixed(2));
89
- return values;
90
- }
91
-
92
- searchProduct(searchTerm) {
93
- let startTime = Date.now();
94
- let country = this.country;
95
- let language = this.language;
96
- let deferred = $.Deferred();
97
- FireBaseProductService.getProductsBySearchTerm(searchTerm,
98
- country, language, searchProductCallback());
99
-
100
-
101
- function searchProductCallback() {
102
- return function(results) {
103
- if (results.success === true) {
104
- deferred.resolve(results);
105
- } else {
106
- deferred.reject(results);
107
- }
108
- }
109
- }
110
-
111
- return deferred.promise().then(results => {
112
- if (results.success === true) {
113
- let endTime = Date.now();
114
- return {results: results, time: this.formatTimeMS(startTime, endTime), numProducts: results.products.length};
115
- } else {
116
- console.error("Product search failed: " , results);
117
- }
118
- },
119
- results => {
120
- console.error("Product search failed: " , results);
121
- }
122
- );
123
- }
124
-
125
- getProductBySKU(sku) {
126
- let startTime = Date.now();
127
- let product = FireBaseProductService.getProductBySku(sku, this.country, this.language);
128
- if (typeof product !== "undefined" && product !== null) {
129
- let endTime = Date.now();
130
- return {product: product, time: this.formatTimeMS(startTime, endTime)};
131
- } else {
132
- console.warn("SKU not found in firebase product service");
133
- return null;
134
- }
135
- }
136
-
137
- formatTimeMS(startTime, endTime) {
138
- return endTime - startTime;
139
- }
140
-
141
- formatTime(time) {
142
- if (time >= 1000) {
143
- time = time / 1000;
144
- return time.toFixed(2) + " sec";
145
- } else {
146
- return time.toFixed(2) + " ms";
147
- }
148
- }
149
-
150
- getLoadedMarkets() {
151
- let markets = "";
152
- let fireBaseProducts;
153
- try {
154
- fireBaseProducts = JSON.parse(localStorage.getItem(FIREBASE_PRODUCT_KEY));
155
- } catch (e) {
156
- console.error("Could not parse firebase product object: " + e);
157
- }
158
- if (typeof fireBaseProducts !== "undefined" && fireBaseProducts !== null) {
159
- for (let market in fireBaseProducts) {
160
- if (fireBaseProducts.hasOwnProperty(market)) {
161
- markets += market + " ";
162
- }
163
- }
164
- } else if (this.loadedFireBaseProducts.length > 0) {
165
- markets += this.country;
166
- }
167
-
168
- return markets;
169
- }
170
-
171
- numberOfProducts() {
172
- let numProducts = {};
173
- let totalProducts = 0;
174
- let firebaseproducts;
175
- try {
176
- firebaseproducts = JSON.parse(localStorage.getItem(FIREBASE_PRODUCT_KEY));
177
- } catch (e){
178
- console.error("Could not parse firebase products: " + e);
179
- }
180
- if (typeof firebaseproducts !== "undefined" && firebaseproducts !== null) {
181
- if (typeof firebaseproducts !== "undefined" && firebaseproducts !== null) {
182
- for (let market in firebaseproducts) {
183
- if (firebaseproducts.hasOwnProperty(market)) {
184
- totalProducts += (_.size(firebaseproducts[market]) - 1);
185
- numProducts[market] = (_.size(firebaseproducts[market]) -1);
186
- }
187
- }
188
- numProducts.totalProducts = totalProducts;
189
- }
190
- } else if (this.loadedFireBaseProducts.length > 0) {
191
- numProducts[this.country] = this.loadedFireBaseProducts.length;
192
- numProducts.totalProducts = this.loadedFireBaseProducts.length;
193
- } else {
194
- numProducts.totalProducts = totalProducts;
195
- }
196
-
197
- return numProducts;
198
- }
199
-
200
- getFireBaseVersion() {
201
- let firebaseproducts;
202
- try {
203
- firebaseproducts = JSON.parse(localStorage.getItem(FIREBASE_PRODUCT_KEY));
204
- } catch (e){
205
- console.error("Could not parse firebase products: " + e);
206
- }
207
- if (typeof firebaseproducts !== "undefined" && firebaseproducts !== null) {
208
- if (typeof firebaseproducts !== "undefined" && firebaseproducts !== null) {
209
- for (let market in firebaseproducts) {
210
- if (firebaseproducts.hasOwnProperty(market)) {
211
- return firebaseproducts[market].version;
212
- }
213
- }
214
- }
215
- } else if (this.loadedFireBaseProducts.length > 0) {
216
- return "Unknown";
217
- }
218
- }
219
-
220
- clearFirebaseData() {
221
- FireBaseProductService.clearStoredProductData();
222
- }
223
-
224
- loadFirebaseProductData() {
225
- let startTime = Date.now();
226
- let country = this.country;
227
- let language = this.language;
228
-
229
- let deferred = $.Deferred();
230
- FireBaseProductService.loadProducts(country, language, callback);
231
-
232
- function callback() {
233
- deferred.resolve();
234
- }
235
-
236
- return deferred.promise().then(results => {
237
- let endTime = Date.now();
238
- return {time: this.formatTimeMS(startTime, endTime)}
239
- });
240
- }
241
-
242
- loadFireBaseProductsIntoMemory() {
243
- this.loadedFireBaseProducts = FireBaseProductService.getProducts(this.country, this.language);
244
- }
245
-
246
- loadedFromApache() {
247
- if (FireBaseProductService.getLoadedFromApache()) {
248
- return "Apache";
249
- } else {
250
- return "Firebase";
251
- }
252
- }
253
- }
@@ -1,449 +0,0 @@
1
- /* eslint-disable */
2
- import newShop from '../newShop.js';
3
- import {PriceType} from '@nuskin/ns-product-lib';
4
-
5
- let FirebaseProduct = function(parser, priceType, market, user){
6
- this.orderTypes = new $.Hashtable();
7
-
8
- // ---------------------------------------------
9
- //
10
- // Define all public methods.
11
- //
12
- // ---------------------------------------------
13
- this.getAgelocmeKeyPart = function() {
14
- let keyPart = null;
15
-
16
- if (this.agelocme) {
17
- keyPart = this.agelocme.code + '-' + this.agelocme.label + '-' + this.agelocme.name;
18
- }
19
-
20
- return keyPart;
21
- };
22
-
23
- this.getSku = function() {
24
- return this.sku;
25
- };
26
-
27
- this.getHighlightedSku = function() {
28
- let rv = this.sku;
29
- if (this.highlightedSku){
30
- rv = this.highlightedSku;
31
- }
32
- return rv;
33
- };
34
-
35
- this.getTitle = function() {
36
- return this.title;
37
- };
38
-
39
- this.getProductSearchTitle = function() {
40
- return this.getTitle();
41
- };
42
-
43
- this.getProductSearchSku = function() {
44
- return this.getHighlightedSku();
45
- };
46
-
47
- this.getCountry = function() {
48
- return this.cntryCd;
49
- };
50
-
51
- this.getLang = function() {
52
- return this.lang;
53
- };
54
-
55
- this.getShortDescr = function() {
56
- return this.shortDescr;
57
- };
58
-
59
- this.getSize = function() {
60
- return this.size;
61
- };
62
-
63
- this.getLongDescr = function() {
64
- return this.longDescr;
65
- };
66
-
67
- this.getDescription = function() {
68
- let description = this.longDescr;
69
- if (!description || description.length === 0) {
70
- return this.shortDescr;
71
- }
72
- return description;
73
- };
74
-
75
- this.getFullImage = function() {
76
- return this.fullImage.replace("http:", "https:");
77
-
78
- };
79
-
80
- this.getThumbnail = function() {
81
- return this.thumbnail.replace("http:", "https:");
82
-
83
- };
84
-
85
- this.getScanQualified = function() {
86
- return this.scanQualified;
87
- };
88
-
89
- this.getPoints = function() {
90
- return this.points;
91
- };
92
-
93
- this.getPointsFixed = function() {
94
- return parseFloat(this.points.toFixed(2));
95
- };
96
-
97
- this.getCv = function() {
98
- return this.cv;
99
- };
100
-
101
- this.getCvFixed = function() {
102
- return parseFloat(this.cv.toFixed(2));
103
- };
104
-
105
- this.getPv = function() {
106
- return this.pv;
107
- };
108
-
109
- this.getPvFixed = function() {
110
- return parseFloat(this.pv.toFixed(2));
111
- };
112
-
113
- this.getPriceType = function() {
114
- return this.priceType;
115
- };
116
-
117
- this.getDivision = function() {
118
- return this.division;
119
- };
120
-
121
- this.getBackOrderDate = function() {
122
- return this.backOrderDate;
123
- };
124
-
125
- this.setPriceAndPvFromType = function(_priceType) {
126
- let priceType = _priceType ? _priceType : this.priceType;
127
- this.price = this.getPricing(priceType);
128
- this.cv = this.getCvWithType(priceType);
129
- this.pv = this.getPvWithType(priceType);
130
- this.priceType = priceType;
131
- };
132
-
133
- this.getPrice = function() {
134
- return this.price ? this.price : 0;
135
- };
136
-
137
- this.setPrice = function (price) {
138
- this.price = insureFloat(price);
139
- };
140
-
141
- this.getPriceFixed = function() {
142
- if (typeof this.price === 'number') {
143
- return parseFloat(this.price.toFixed(2));
144
- } else {
145
- return this.getPrice();
146
- }
147
-
148
- };
149
-
150
- this.getPricing = function(type) {
151
- return getPricingFromFirebaseObject(type);
152
- };
153
-
154
- this.getPvWithType = function(type) {
155
- let rv = getPVFromFirebaseObject(type);
156
- if (rv == null) {
157
- // Assumption: we always have WWHL from the service
158
- // default to wholesale if a PV of a particular type is not there
159
- rv = getPVFromFirebaseObject(PriceType.WWHL);
160
- }
161
- return rv;
162
- };
163
-
164
- this.getCvWithType = function(type) {
165
- let rv = getCVFromFirebaseObject(type);
166
- if (rv == null) {
167
- rv = getCVFromFirebaseObject(PriceType.WWHL);
168
- }
169
- return rv;
170
- };
171
-
172
- this.addOrderType = function(orderType) {
173
- this.orderTypes.add(orderType, orderType);
174
- };
175
-
176
- this.hasAdrOption = function() {
177
- return this.orderTypes.containsKey('adr');
178
- };
179
-
180
- this.isAdrOnly = function() {
181
- return this.hasAdrOption() && !this.hasOrderOption();
182
- };
183
-
184
- this.hasMultipleOrderTypes = function() {
185
- return this.hasOrderOption() && this.hasAdrOption();
186
- };
187
-
188
- this.hasOrderOption = function() {
189
- return this.orderTypes.containsKey('order');
190
- };
191
-
192
- this.isDistributor = function() {
193
- return isCustomerType('10');
194
- };
195
-
196
- this.isCustomer = function() {
197
- return isCustomerType('20');
198
- };
199
-
200
- this.isPreferredCustomer = function() {
201
- return isCustomerType('30');
202
- };
203
-
204
- this.toJSON = function() {
205
- let retData = {};
206
- retData.sku = this.sku;
207
- retData.title = this.title;
208
- retData.cntryCd = this.cntryCd;
209
- retData.lang = this.lang;
210
- retData.shortDescr = this.shortDescr;
211
- retData.longDescr = this.longDescr;
212
- retData.fullImage = this.fullImage;
213
- retData.thumbnail = this.thumbnail;
214
- retData.scanQualified = this.scanQualified;
215
- retData.available = this.available;
216
- retData.searchable = this.searchable;
217
- retData.points = this.points;
218
- retData.cv = this.cv;
219
- retData.pv = this.pv;
220
- retData.priceType = this.priceType;
221
- retData.price = this.price;
222
- retData.orderTypes = getKeyArray(this.orderTypes);
223
- retData.custTypes = parser.getCustomerTypes();
224
- retData.division = this.division;
225
- retData.backOrderDate = this.backOrderDate;
226
- retData.agelocme = this.agelocme;
227
-
228
- return retData;
229
- };
230
-
231
- this.isEmpty = function() {
232
- return isFieldEmpty(this.sku) &&
233
- isFieldEmpty(this.title) &&
234
- isFieldEmpty(this.cntryCd) &&
235
- isFieldEmpty(this.lang) &&
236
- isFieldEmpty(this.shortDescr) &&
237
- isFieldEmpty(this.longDescr) &&
238
- isFieldEmpty(this.fullImage) &&
239
- isFieldEmpty(this.thumbnail) &&
240
- isFieldEmpty(this.points) &&
241
- isFieldEmpty(this.cv) &&
242
- isFieldEmpty(this.pv);
243
- };
244
-
245
- // ---------------------------------------------
246
- //
247
- // Define all private methods.
248
- //
249
- // ---------------------------------------------
250
- function getPricingFromFirebaseObject(priceType){
251
- let price;
252
-
253
- switch (priceType) {
254
- case PriceType.ADR:
255
- price = user && !user.isCustomer() ? parser.getAdrPreferredPrice() : parser.getAdrRetailPrice();
256
- break;
257
- case PriceType.ADW:
258
- price = parser.getAdrWholesalePrice();
259
- break;
260
- case PriceType.RTL:
261
- price = user && !user.isCustomer() ? parser.getPreferredPrice() : parser.getRetailPrice();
262
- break;
263
- case PriceType.WHL:
264
- price = parser.getWholesale();
265
- break;
266
- case PriceType.PTS:
267
- price = parser.getPoints();
268
- break;
269
- case PriceType.WADR:
270
- price = user && !user.isCustomer() ? parser.getWebAdrWholesalePrice() : parser.getWebAdrRetailPrice();
271
- break;
272
- case PriceType.WADW:
273
- price = parser.getWebAdrWholesalePrice();
274
- break;
275
- case PriceType.WADWD:
276
- // todo We need to figure out what this maps to.
277
- price = 0.00;
278
- break;
279
- case PriceType.WRTL:
280
- price = user && !user.isCustomer() ? parser.getWebPreferredPrice() : parser.getWebRetailPrice();
281
- break;
282
- case PriceType.WWHL:
283
- price = parser.getWebWholesalePrice();
284
- break;
285
- default:
286
- price = 0.00;
287
- break;
288
- }
289
-
290
- return price;
291
- }
292
-
293
- // todo Verify this logic.
294
- function getPVFromFirebaseObject(priceType){
295
- let pv;
296
-
297
- switch (priceType) {
298
- case PriceType.ADR:
299
- pv = 0.00;
300
- break;
301
- case PriceType.ADW:
302
- pv = parser.getWebWholesalePv();
303
- break;
304
- case PriceType.RTL:
305
- pv = 0.00;
306
- break;
307
- case PriceType.WHL:
308
- pv = parser.getWebWholesalePv();
309
- break;
310
- case PriceType.PTS:
311
- pv = 0.00;
312
- break;
313
- case PriceType.WADR:
314
- pv = 0.00;
315
- break;
316
- case PriceType.WADW:
317
- pv = parser.getWebWholesalePv();
318
- break;
319
- case PriceType.WADWD:
320
- pv = parser.getWebAdrRetailPv();
321
- break;
322
- case PriceType.WRTL:
323
- pv = parser.getWebWholesalePv();
324
- break;
325
- case PriceType.WWHL:
326
- pv = parser.getWebWholesalePv();
327
- break;
328
- default:
329
- pv = 0.00;
330
- break;
331
- }
332
-
333
- return pv;
334
- }
335
-
336
- // todo Verify this logic.
337
- function getCVFromFirebaseObject(priceType){
338
- let cv;
339
-
340
- switch (priceType) {
341
- case PriceType.ADR:
342
- cv = 0.00;
343
- break;
344
- case PriceType.ADW:
345
- cv = parser.getWebWholesaleCv();
346
- break;
347
- case PriceType.RTL:
348
- cv = 0.00;
349
- break;
350
- case PriceType.WHL:
351
- cv = parser.getWebWholesaleCv();
352
- break;
353
- case PriceType.PTS:
354
- cv = 0.00;
355
- break;
356
- case PriceType.WADR:
357
- cv = 0.00;
358
- break;
359
- case PriceType.WADW:
360
- cv = parser.getWebWholesaleCv();
361
- break;
362
- case PriceType.WADWD:
363
- cv = parser.getWebAdrRetailCv();
364
- break;
365
- case PriceType.WRTL:
366
- cv = parser.getWebWholesaleCv();
367
- break;
368
- case PriceType.WWHL:
369
- cv = parser.getWebWholesaleCv();
370
- break;
371
- default:
372
- cv = 0.00;
373
- }
374
-
375
- return cv;
376
- }
377
-
378
- function isFieldEmpty(fieldValue){
379
- return fieldValue === null || fieldValue === undefined || fieldValue.length === 0;
380
- }
381
-
382
- function getKeyArray(jqueryHashtable) {
383
- let keys,
384
- i,
385
- retVal = [];
386
-
387
- if (jqueryHashtable instanceof $.Hashtable) {
388
- keys = Object.keys(jqueryHashtable.items);
389
- for (i = 0; i < keys.length; i++) {
390
- retVal.push(keys[i]);
391
- }
392
- }
393
- return retVal;
394
- }
395
-
396
- function isCustomerType(customerType) {
397
- let isCustomerType = false;
398
- let customerTypes = parser.getCustomerTypes();
399
- for (let i=0;i<customerTypes.length;i++){
400
- if (customerTypes[i] === customerType){
401
- isCustomerType = true;
402
- break;
403
- }
404
- }
405
- return isCustomerType;
406
- }
407
-
408
- function insureFloat(price) {
409
- let floatPrice = parseFloat(price);
410
- return isNaN(floatPrice) ? 0.00 : floatPrice;
411
- }
412
-
413
- // ---------------------------------------------
414
- //
415
- // Constructor
416
- //
417
- // ---------------------------------------------
418
- // Add all the order types;
419
- let orderTypes = parser.getOrderTypes();
420
- for (let i=0;i<orderTypes.length;i++){
421
- this.addOrderType(orderTypes[i]);
422
- }
423
-
424
- this.sku = parser.getSku();
425
- this.title = parser.getName();
426
- this.cntryCd = market;
427
- this.lang = parser.getLanguage();
428
- this.shortDescr = parser.getShortDescription();
429
- this.longDescr = parser.getLongDescription();
430
- this.fullImage = parser.getFullImageUrl();
431
- this.thumbnail = parser.getImageUrl();
432
- this.scanQualified = parser.getScanQualified();
433
- this.available = parser.getAvailable();
434
- this.searchable = parser.getSearchable();
435
- this.points = parser.getPoints();
436
- this.priceType = priceType;
437
- this.division = null;
438
- this.backOrderDate = null;
439
- this.price = this.getPricing(priceType);
440
- this.pv = this.getPvWithType(priceType);
441
- this.cv = this.getCvWithType(priceType);
442
- this.size = parser.getSize();
443
-
444
- this.agelocme = null; // object containing agelocme information (like code, label, name)
445
- };
446
-
447
- newShop.FirebaseProduct = FirebaseProduct;
448
-
449
- export default FirebaseProduct;