@ordergroove/offers 2.36.1 → 2.36.2-alpha-PR-836-2.3

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.36.1",
3
+ "version": "2.36.2-alpha-PR-836-2.3+2e663ca9",
4
4
  "description": "offer state component",
5
5
  "author": "Eugenio Lattanzio <eugenio63@gmail.com>",
6
6
  "homepage": "https://github.com/ordergroove/plush-toys#readme",
@@ -48,5 +48,5 @@
48
48
  "@ordergroove/offers-templates": "^0.9.6",
49
49
  "@types/lodash.memoize": "^4.1.9"
50
50
  },
51
- "gitHead": "174743085e4d3672ceb73b8384b5cb897bc41289"
51
+ "gitHead": "2e663ca9c0463a9d7d8040066c32aa187f72c25d"
52
52
  }
@@ -3,6 +3,7 @@ import { productChangeFrequency } from '../core/actions';
3
3
  import { withChildOptions } from '../core/resolveProperties';
4
4
  import { FrequencyStatus, mapStateToProps, frequencyText } from './FrequencyStatus';
5
5
  import { connect } from '../core/connect';
6
+ import { frequencyToSellingPlan } from '../core/utils';
6
7
 
7
8
  export const frequencyEquals = (a, b) => {
8
9
  if (a === null || b === null) return false;
@@ -62,12 +63,10 @@ export class SelectFrequency extends withChildOptions(FrequencyStatus) {
62
63
  } else {
63
64
  result = this._defaultFrequency;
64
65
  }
66
+
65
67
  // this runs for shopify selling plans translated to freq
66
- if (this.frequencies?.length && result && this.config?.frequenciesEveryPeriod) {
67
- const index = this.config.frequenciesEveryPeriod.findIndex(it => it === result);
68
- if (index >= 0) {
69
- return this.frequencies[index];
70
- }
68
+ if (this.config?.frequencies?.length && result && this.config?.frequenciesEveryPeriod?.length) {
69
+ return frequencyToSellingPlan(result, this.config);
71
70
  }
72
71
 
73
72
  return result;
@@ -15,12 +15,20 @@ describe('frequencyToSellingPlan', () => {
15
15
  expect(frequencyToSellingPlan('345', {})).toEqual('345');
16
16
  });
17
17
 
18
- it('should return original frequency if no frequency match', () => {
18
+ it('should return first frequency if no frequency match', () => {
19
19
  expect(
20
20
  frequencyToSellingPlan('1_2', {
21
21
  frequenciesEveryPeriod: ['1_1', '1_3'],
22
22
  frequencies: [123, 789]
23
23
  })
24
+ ).toEqual(123);
25
+ });
26
+
27
+ it('should return original frequency if no frequency match and frequenciesEveryPeriod not defined', () => {
28
+ expect(
29
+ frequencyToSellingPlan('1_2', {
30
+ frequencies: [123, 789]
31
+ })
24
32
  ).toEqual('1_2');
25
33
  });
26
34
  });
package/src/core/utils.ts CHANGED
@@ -70,6 +70,12 @@ export const frequencyToSellingPlan = (ogFrequency, config) => {
70
70
  return config.frequencies[ix];
71
71
  }
72
72
 
73
+ // if we can't find the OG frequency, but we have selling plans, return the first selling plan
74
+ if (config.frequencies?.length > 0 && config.frequenciesEveryPeriod?.length > 0) {
75
+ console.warn(`Unable to find selling plan match for frequency ${ogFrequency}; falling back to first selling plan`);
76
+ return config.frequencies[0];
77
+ }
78
+
73
79
  return ogFrequency;
74
80
  };
75
81
 
@@ -408,6 +408,65 @@ describe('config', () => {
408
408
  );
409
409
  });
410
410
 
411
+ it('should use product-specific frequency selling plan groups if present', () => {
412
+ const actual = config(
413
+ {},
414
+ {
415
+ type: constants.SETUP_PRODUCT,
416
+ payload: {
417
+ product: {
418
+ selling_plan_groups: [
419
+ {
420
+ name: 'og_psfl_2m4m6m',
421
+ options: [
422
+ {
423
+ values: ['2 months', '4 months', '6 months']
424
+ }
425
+ ],
426
+ selling_plans: [
427
+ {
428
+ id: 'psfl-id-1'
429
+ },
430
+ {
431
+ id: 'psfl-id-2'
432
+ },
433
+ {
434
+ id: 'psfl-id-3'
435
+ }
436
+ ]
437
+ },
438
+ {
439
+ name: 'Subscribe and Save',
440
+ options: [
441
+ {
442
+ values: ['month', '2 months', '3 months']
443
+ }
444
+ ],
445
+ selling_plans: [
446
+ {
447
+ id: 'regular-id-1'
448
+ },
449
+ {
450
+ id: 'regular-id-2'
451
+ },
452
+ {
453
+ id: 'regular-id-3'
454
+ }
455
+ ]
456
+ }
457
+ ]
458
+ }
459
+ }
460
+ }
461
+ );
462
+
463
+ expect(actual).toEqual(
464
+ jasmine.objectContaining({
465
+ frequencies: ['psfl-id-1', 'psfl-id-2', 'psfl-id-3']
466
+ })
467
+ );
468
+ });
469
+
411
470
  it('should set prepaidSellingPlans', () => {
412
471
  const sellingPlanGroups = [
413
472
  {
@@ -33,6 +33,7 @@ import {
33
33
  } from '../core/utils';
34
34
 
35
35
  import { getObjectStructuredProductPlans } from '../core/adapters';
36
+
36
37
  import {
37
38
  sellingPlanAllocationsReducer,
38
39
  getSellingPlans,
@@ -126,10 +127,14 @@ export const reduceNewOptinsFromOfferResponse = (
126
127
  }, []);
127
128
 
128
129
  const getOGSellingPlanGroup = product => {
129
- const sellingPlanGroup = product?.selling_plan_groups.find(group => {
130
- return group.name === DEFAULT_PAY_AS_YOU_GO_GROUP_NAME;
131
- });
132
- return sellingPlanGroup;
130
+ const productSpecificFrequencySellingPlanGroup = product?.selling_plan_groups.find(group =>
131
+ group.name.startsWith('og_psfl')
132
+ );
133
+
134
+ return (
135
+ productSpecificFrequencySellingPlanGroup ||
136
+ product?.selling_plan_groups.find(group => group.name === DEFAULT_PAY_AS_YOU_GO_GROUP_NAME)
137
+ );
133
138
  };
134
139
 
135
140
  const productOrVariantInStockReducer = (acc, cur) => ({