@ordergroove/offers 2.37.2 → 2.38.0
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/CHANGELOG.md +11 -0
- package/dist/bundle-report.html +3 -3
- package/dist/offers.js +26 -26
- package/dist/offers.js.map +3 -3
- package/package.json +2 -2
- package/src/shopify/__tests__/shopifyReducer.spec.js +5 -5
- package/src/shopify/shopifyReducer.js +22 -12
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ordergroove/offers",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.38.0",
|
|
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": "
|
|
51
|
+
"gitHead": "3aeaadda9243d4ff1c851abdb9056b5adc0ad54c"
|
|
52
52
|
}
|
|
@@ -147,7 +147,7 @@ describe('autoshipEligible', () => {
|
|
|
147
147
|
});
|
|
148
148
|
});
|
|
149
149
|
|
|
150
|
-
it('should return
|
|
150
|
+
it('should return true 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
|
-
'sub-
|
|
159
|
-
'not-sub-
|
|
158
|
+
'default-sub-psfl': [sellingPlans.default, sellingPlans.psfl],
|
|
159
|
+
'not-default-sub-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
|
-
'sub-
|
|
172
|
-
'not-sub-
|
|
171
|
+
'default-sub-psfl': true,
|
|
172
|
+
'not-default-sub-psfl': true
|
|
173
173
|
});
|
|
174
174
|
});
|
|
175
175
|
});
|
|
@@ -127,6 +127,7 @@ 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
|
|
130
131
|
const productSpecificFrequencySellingPlanGroup = product?.selling_plan_groups.find(
|
|
131
132
|
isProductSpecificFrequencySellingPlanGroup
|
|
132
133
|
);
|
|
@@ -134,10 +135,20 @@ const getOGSellingPlanGroup = product => {
|
|
|
134
135
|
return productSpecificFrequencySellingPlanGroup || getDefaultSubscriptionSellingPlanGroup(product);
|
|
135
136
|
};
|
|
136
137
|
|
|
138
|
+
const getOGSellingPlanGroups = product => {
|
|
139
|
+
const sellingPlanGroups = (product?.selling_plan_groups || []).filter(
|
|
140
|
+
group => isDefaultSellingPlanGroup(group) || isProductSpecificFrequencySellingPlanGroup(group)
|
|
141
|
+
);
|
|
142
|
+
return sellingPlanGroups;
|
|
143
|
+
};
|
|
144
|
+
|
|
137
145
|
const getDefaultSubscriptionSellingPlanGroup = product => {
|
|
138
|
-
|
|
146
|
+
// retrieve the OG Default Selling Plan Group
|
|
147
|
+
return product?.selling_plan_groups.find(isDefaultSellingPlanGroup);
|
|
139
148
|
};
|
|
140
149
|
|
|
150
|
+
const isDefaultSellingPlanGroup = group => group.name === DEFAULT_PAY_AS_YOU_GO_GROUP_NAME;
|
|
151
|
+
|
|
141
152
|
const isProductSpecificFrequencySellingPlanGroup = group => group.name.startsWith('og_psfl');
|
|
142
153
|
|
|
143
154
|
const productOrVariantInStockReducer = (acc, cur) => ({
|
|
@@ -164,19 +175,18 @@ export const autoshipEligible = (state = {}, action) => {
|
|
|
164
175
|
const {
|
|
165
176
|
payload: { product }
|
|
166
177
|
} = action;
|
|
167
|
-
const
|
|
168
|
-
|
|
169
|
-
|
|
178
|
+
const applicableSellingPlanGroups = getOGSellingPlanGroups(product);
|
|
179
|
+
|
|
180
|
+
const ogSellingPlanIds = new Set(
|
|
181
|
+
applicableSellingPlanGroups.flatMap(group => group.selling_plans.map(sellingPlan => sellingPlan.id)) ?? []
|
|
170
182
|
);
|
|
183
|
+
|
|
171
184
|
return [product, ...(product?.variants || [])]?.reduce((acc, cur) => {
|
|
172
|
-
const
|
|
173
|
-
cur?.selling_plan_allocations?.filter(sellingPlan =>
|
|
174
|
-
|
|
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;
|
|
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;
|
|
180
190
|
|
|
181
191
|
return {
|
|
182
192
|
...overrideLineKey(acc, cur.id, isAutoshipEligible),
|