@ordergroove/offers 2.35.6 → 2.35.8-alpha-PR-831-1.26

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ordergroove/offers",
3
- "version": "2.35.6",
3
+ "version": "2.35.8-alpha-PR-831-1.26+837c516f",
4
4
  "description": "offer state component",
5
5
  "author": "Eugenio Lattanzio <eugenio63@gmail.com>",
6
6
  "homepage": "https://github.com/ordergroove/plush-toys#readme",
@@ -45,8 +45,8 @@
45
45
  "throttle-debounce": "^2.1.0"
46
46
  },
47
47
  "devDependencies": {
48
- "@ordergroove/offers-templates": "^0.9.5",
48
+ "@ordergroove/offers-templates": "^0.9.6",
49
49
  "@types/lodash.memoize": "^4.1.9"
50
50
  },
51
- "gitHead": "0110539ccd5202a8c19a67fa44e4d924dd597e89"
51
+ "gitHead": "837c516f9418cb8720c90fd955373945bea4d5f2"
52
52
  }
@@ -28,6 +28,17 @@ import { DEFAULT_OFFER_MODULE } from '../core/constants';
28
28
 
29
29
  const memoizeKey = (...args) => JSON.stringify(args);
30
30
 
31
+ let hasLogged = false;
32
+ function logMulticurrencyWarning(storeCurrency, primaryCurrency) {
33
+ // only log once
34
+ if (!hasLogged) {
35
+ console.warn(
36
+ `Hiding Ordergroove offer since the store currency ${storeCurrency} does not match your configured currency ${primaryCurrency} and you are not setup for multicurrency. Contact your Ordergroove rep for next steps.`
37
+ );
38
+ hasLogged = true;
39
+ }
40
+ }
41
+
31
42
  export const productAndComponents = memoize(
32
43
  (product, components) => Object.assign({ components }, product),
33
44
  memoizeKey
@@ -308,10 +319,26 @@ export class Offer extends TemplateElement {
308
319
  return this.preview || window.og.previewMode;
309
320
  }
310
321
 
322
+ get shouldRenderOffer() {
323
+ if (this.config && this.config.storeCurrency && this.config.merchantSettings) {
324
+ const shouldRender =
325
+ this.config.merchantSettings.multicurrency_enabled ||
326
+ this.config.storeCurrency === this.config.merchantSettings.currency_code;
327
+ if (!shouldRender) {
328
+ logMulticurrencyWarning(this.config.storeCurrency, this.config.merchantSettings.currency_code);
329
+ }
330
+ return shouldRender;
331
+ }
332
+
333
+ return true;
334
+ }
335
+
311
336
  render() {
312
- return html`
313
- <slot></slot>
314
- `;
337
+ return this.shouldRenderOffer
338
+ ? html`
339
+ <slot></slot>
340
+ `
341
+ : null;
315
342
  }
316
343
 
317
344
  get defaultFrequency() {
@@ -301,3 +301,71 @@ describe('previewMode', () => {
301
301
  expect(el.preview).toEqual('upsell');
302
302
  });
303
303
  });
304
+
305
+ describe('multi-currency', () => {
306
+ async function getOfferElement(config) {
307
+ const element = new Offer();
308
+ element.innerHTML = `
309
+ <p>Offer content</p>
310
+ `;
311
+ element.config = config;
312
+ await appendToBody(element);
313
+ return element;
314
+ }
315
+
316
+ function assertOfferShown(element) {
317
+ expect(element.querySelector('*').assignedSlot).not.toBeNull();
318
+ }
319
+
320
+ function assertOfferHidden(element) {
321
+ expect(element.querySelector('*').assignedSlot).toBeNull();
322
+ }
323
+
324
+ it('should show the offer when config not set', async () => {
325
+ const element = await getOfferElement();
326
+ assertOfferShown(element);
327
+ });
328
+
329
+ it('should show the offer if store currency not available', async () => {
330
+ const element = await getOfferElement({
331
+ merchantSettings: {
332
+ currency_code: 'USD',
333
+ multicurrency_enabled: false
334
+ }
335
+ });
336
+ assertOfferShown(element);
337
+ });
338
+
339
+ it('should show the offer when store currency matches primary currency', async () => {
340
+ const element = await getOfferElement({
341
+ storeCurrency: 'MXN',
342
+ merchantSettings: {
343
+ currency_code: 'MXN',
344
+ multicurrency_enabled: false
345
+ }
346
+ });
347
+ assertOfferShown(element);
348
+ });
349
+
350
+ it('should hide the offer when multicurrency not enabled and store currency does not match primary currency', async () => {
351
+ const element = await getOfferElement({
352
+ storeCurrency: 'MXN',
353
+ merchantSettings: {
354
+ currency_code: 'USD',
355
+ multicurrency_enabled: false
356
+ }
357
+ });
358
+ assertOfferHidden(element);
359
+ });
360
+
361
+ it('should show the offer when multicurrency enabled and store currency does not match primary currency', async () => {
362
+ const element = await getOfferElement({
363
+ storeCurrency: 'MXN',
364
+ merchantSettings: {
365
+ currency_code: 'USD',
366
+ multicurrency_enabled: true
367
+ }
368
+ });
369
+ assertOfferShown(element);
370
+ });
371
+ });
@@ -312,3 +312,8 @@ export const setProductToSubscribe = (product, productToSubscribe) => ({
312
312
  type: constants.SET_PRODUCT_TO_SUBSCRIBE,
313
313
  payload: { product, productToSubscribe }
314
314
  });
315
+
316
+ export const receiveMerchantSettings = settings => ({
317
+ type: constants.RECEIVE_MERCHANT_SETTINGS,
318
+ payload: settings
319
+ });
@@ -42,6 +42,7 @@ export const SET_PRODUCT_TO_SUBSCRIBE = 'SET_PRODUCT_TO_SUBSCRIBE';
42
42
  export const RECEIVE_PRODUCT_PLANS = 'RECEIVE_PRODUCT_PLANS';
43
43
  export const SETUP_PRODUCT = 'SETUP_PRODUCT';
44
44
  export const SETUP_CART = 'SETUP_CART';
45
+ export const RECEIVE_MERCHANT_SETTINGS = 'RECEIVE_MERCHANT_SETTINGS';
45
46
  export const DEFAULT_OFFER_MODULE = 'pdp';
46
47
  export const ENV_DEV = 'dev';
47
48
  export const ENV_STAGING = 'staging';
@@ -400,6 +400,13 @@ export const config = (
400
400
  frequenciesEveryPeriod: [],
401
401
  frequencies: action.payload.frequencies ? action.payload.frequencies.map(stringifyFrequency) : state.frequencies
402
402
  };
403
+ case constants.RECEIVE_MERCHANT_SETTINGS:
404
+ return {
405
+ ...state,
406
+ merchantSettings: {
407
+ ...action.payload
408
+ }
409
+ };
403
410
  default:
404
411
  return state;
405
412
  }
package/src/make-api.js CHANGED
@@ -82,6 +82,10 @@ export default function makeApi(store) {
82
82
  store.dispatch(actions.setAuthUrl(authUrl));
83
83
  return this;
84
84
  },
85
+ receiveMerchantSettings(settings) {
86
+ store.dispatch(actions.receiveMerchantSettings(settings));
87
+ return this;
88
+ },
85
89
  getProductsForPurchasePost(productIds = []) {
86
90
  return adapters.getProductsForPurchasePost(store.getState(), productIds);
87
91
  },
@@ -163,7 +167,7 @@ export default function makeApi(store) {
163
167
  * @param {*} env
164
168
  * @param {*} authUrl
165
169
  */
166
- initialize(merchantId, env, authUrl) {
170
+ initialize(merchantId, env, authUrl, merchantSettings) {
167
171
  // settings resolves once, before anything.
168
172
  if (isReady) {
169
173
  console.warn('og.offers has been initialized already. Skipping.');
@@ -175,6 +179,7 @@ export default function makeApi(store) {
175
179
  // dont re-trigger actions if value is the same. allowing set new authurl only
176
180
  if (merchantId && merchantId !== state.merchantId) offers.setMerchantId(merchantId);
177
181
  if (env && env !== state.environment?.name) offers.setEnvironment(env);
182
+ if (merchantSettings) offers.receiveMerchantSettings(merchantSettings);
178
183
  // allow set new authUrl
179
184
  if (authUrl) offers.setAuthUrl(authUrl);
180
185
 
@@ -435,16 +435,18 @@ describe('config', () => {
435
435
  }
436
436
  }
437
437
  );
438
- expect(actual).toEqual({
439
- prepaidSellingPlans: {
440
- 43017264201944: [
441
- {
442
- numberShipments: 4,
443
- sellingPlan: '2146042072'
444
- }
445
- ]
446
- }
447
- });
438
+ expect(actual).toEqual(
439
+ jasmine.objectContaining({
440
+ prepaidSellingPlans: {
441
+ 43017264201944: [
442
+ {
443
+ numberShipments: 4,
444
+ sellingPlan: '2146042072'
445
+ }
446
+ ]
447
+ }
448
+ })
449
+ );
448
450
  });
449
451
 
450
452
  it('should add prepaidSellingPlans on top of old ones', () => {
@@ -502,28 +504,30 @@ describe('config', () => {
502
504
  }
503
505
  }
504
506
  );
505
- expect(actual).toEqual({
506
- prepaidSellingPlans: {
507
- 43017264201944: [
508
- {
509
- numberShipments: 4,
510
- sellingPlan: '2146042071'
511
- }
512
- ],
513
- 43017264201946: [
514
- {
515
- numberShipments: 3,
516
- sellingPlan: '2146042072'
517
- }
518
- ],
519
- 43017264201945: [
520
- {
521
- numberShipments: 5,
522
- sellingPlan: '2146042073'
523
- }
524
- ]
525
- }
526
- });
507
+ expect(actual).toEqual(
508
+ jasmine.objectContaining({
509
+ prepaidSellingPlans: {
510
+ 43017264201944: [
511
+ {
512
+ numberShipments: 4,
513
+ sellingPlan: '2146042071'
514
+ }
515
+ ],
516
+ 43017264201946: [
517
+ {
518
+ numberShipments: 3,
519
+ sellingPlan: '2146042072'
520
+ }
521
+ ],
522
+ 43017264201945: [
523
+ {
524
+ numberShipments: 5,
525
+ sellingPlan: '2146042073'
526
+ }
527
+ ]
528
+ }
529
+ })
530
+ );
527
531
  });
528
532
 
529
533
  it('should return unmodified state given unsupported action', () => {
@@ -259,7 +259,7 @@ export const config = (
259
259
 
260
260
  if (constants.SETUP_PRODUCT === action.type) {
261
261
  const {
262
- payload: { product }
262
+ payload: { product, currency }
263
263
  } = action;
264
264
  let configToAdd = {};
265
265
  // pay as you go selling plans
@@ -294,7 +294,8 @@ export const config = (
294
294
  }
295
295
  return {
296
296
  ...state,
297
- ...configToAdd
297
+ ...configToAdd,
298
+ storeCurrency: currency
298
299
  };
299
300
  }
300
301
 
@@ -328,6 +329,15 @@ export const config = (
328
329
  };
329
330
  }
330
331
 
332
+ if (constants.RECEIVE_MERCHANT_SETTINGS === action.type) {
333
+ return {
334
+ ...state,
335
+ merchantSettings: {
336
+ ...action.payload
337
+ }
338
+ };
339
+ }
340
+
331
341
  return state;
332
342
  };
333
343