@ordergroove/offers 2.37.2-alpha-PR-928-3.119 → 2.37.2

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.37.2-alpha-PR-928-3.119+5ee371e3",
3
+ "version": "2.37.2",
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": "5ee371e315b854ac77fdf4f44a718a4d88363d6b"
51
+ "gitHead": "7576fcab14c780a395ee0e581b8147525bd96127"
52
52
  }
@@ -147,7 +147,7 @@ describe('autoshipEligible', () => {
147
147
  });
148
148
  });
149
149
 
150
- it('should return true if there are only PSFL selling plans', () => {
150
+ it('should return false if there are only PSFL selling plans', () => {
151
151
  const actual = autoshipEligible(
152
152
  {},
153
153
  {
@@ -155,8 +155,8 @@ describe('autoshipEligible', () => {
155
155
  payload: getSetupProductPayload({
156
156
  variants: {
157
157
  'single-non-psfl': [sellingPlans.default],
158
- 'default-sub-psfl': [sellingPlans.default, sellingPlans.psfl],
159
- 'not-default-sub-psfl': [sellingPlans.psfl]
158
+ 'sub-eligible-psfl': [sellingPlans.default, sellingPlans.psfl],
159
+ 'not-sub-eligible-psfl': [sellingPlans.psfl]
160
160
  },
161
161
  additionalSellingPlanGroups: {
162
162
  og_psfl_2m: [sellingPlans.psfl]
@@ -168,8 +168,8 @@ describe('autoshipEligible', () => {
168
168
  expect(actual).toEqual({
169
169
  'yum product id': false,
170
170
  'single-non-psfl': true,
171
- 'default-sub-psfl': true,
172
- 'not-default-sub-psfl': true
171
+ 'sub-eligible-psfl': true,
172
+ 'not-sub-eligible-psfl': false
173
173
  });
174
174
  });
175
175
  });
@@ -354,6 +354,7 @@ function synchronizeSellingPlan(store: any, offerElement?: HTMLElement) {
354
354
  const sellingPlanId = getSubscribedFrequency(productId, store);
355
355
 
356
356
  getOrCreateHidden(productIdInput.form, 'selling_plan', sellingPlanId);
357
+ getOrCreateHidden(productIdInput.form, `attributes[og__session]`, store.getState().sessionId);
357
358
  if (offerElement) {
358
359
  // use this to update the product attributes in future
359
360
  }
@@ -127,7 +127,6 @@ export const reduceNewOptinsFromOfferResponse = (
127
127
  }, []);
128
128
 
129
129
  const getOGSellingPlanGroup = product => {
130
- // retrieve an OG Default or PSFL Selling Plan Group, preferring to return PSFL groups if they exist
131
130
  const productSpecificFrequencySellingPlanGroup = product?.selling_plan_groups.find(
132
131
  isProductSpecificFrequencySellingPlanGroup
133
132
  );
@@ -135,20 +134,10 @@ const getOGSellingPlanGroup = product => {
135
134
  return productSpecificFrequencySellingPlanGroup || getDefaultSubscriptionSellingPlanGroup(product);
136
135
  };
137
136
 
138
- const getOGSellingPlanGroups = product => {
139
- const sellingPlanGroups = (product?.selling_plan_groups || []).filter(
140
- group => isDefaultSellingPlanGroup(group) || isProductSpecificFrequencySellingPlanGroup(group)
141
- );
142
- return sellingPlanGroups;
143
- };
144
-
145
137
  const getDefaultSubscriptionSellingPlanGroup = product => {
146
- // retrieve the OG Default Selling Plan Group
147
- return product?.selling_plan_groups.find(isDefaultSellingPlanGroup);
138
+ return product?.selling_plan_groups.find(group => group.name === DEFAULT_PAY_AS_YOU_GO_GROUP_NAME);
148
139
  };
149
140
 
150
- const isDefaultSellingPlanGroup = group => group.name === DEFAULT_PAY_AS_YOU_GO_GROUP_NAME;
151
-
152
141
  const isProductSpecificFrequencySellingPlanGroup = group => group.name.startsWith('og_psfl');
153
142
 
154
143
  const productOrVariantInStockReducer = (acc, cur) => ({
@@ -175,18 +164,19 @@ export const autoshipEligible = (state = {}, action) => {
175
164
  const {
176
165
  payload: { product }
177
166
  } = action;
178
- const applicableSellingPlanGroups = getOGSellingPlanGroups(product);
179
-
180
- const ogSellingPlanIds = new Set(
181
- applicableSellingPlanGroups.flatMap(group => group.selling_plans.map(sellingPlan => sellingPlan.id)) ?? []
167
+ const defaultSellingPlanGroup = getDefaultSubscriptionSellingPlanGroup(product);
168
+ const sellingPlanIdsInDefaultGroup = new Set(
169
+ defaultSellingPlanGroup?.selling_plans.map(sellingPlan => sellingPlan.id) ?? []
182
170
  );
183
-
184
171
  return [product, ...(product?.variants || [])]?.reduce((acc, cur) => {
185
- const productSellingPlansFromOG =
186
- cur?.selling_plan_allocations?.filter(sellingPlan => ogSellingPlanIds.has(sellingPlan.selling_plan_id)) ?? [];
187
- // a product is autoship eligible if it has plans from the default or PSFL selling plan group
188
- // the presence of prepaid selling plans does not mean it is autoship eligible
189
- const isAutoshipEligible = productSellingPlansFromOG.length > 0;
172
+ const productSellingPlansFromDefaultGroup =
173
+ cur?.selling_plan_allocations?.filter(sellingPlan =>
174
+ sellingPlanIdsInDefaultGroup.has(sellingPlan.selling_plan_id)
175
+ ) ?? [];
176
+
177
+ // a product is autoship eligible if it has plans from the default "Subscribe and Save" selling plan group
178
+ // the presence of other selling plans (prepaid, product-specific frequencies) does not mean it is autoship eligible
179
+ const isAutoshipEligible = productSellingPlansFromDefaultGroup.length > 0;
190
180
 
191
181
  return {
192
182
  ...overrideLineKey(acc, cur.id, isAutoshipEligible),