@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/CHANGELOG.md +8 -0
- package/dist/bundle-report.html +2 -2
- package/dist/offers.js +28 -28
- package/dist/offers.js.map +3 -3
- package/package.json +2 -2
- package/src/shopify/__tests__/shopifyReducer.spec.js +5 -5
- package/src/shopify/shopifyMiddleware.ts +1 -0
- package/src/shopify/shopifyReducer.js +12 -22
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ordergroove/offers",
|
|
3
|
-
"version": "2.37.2
|
|
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": "
|
|
51
|
+
"gitHead": "7576fcab14c780a395ee0e581b8147525bd96127"
|
|
52
52
|
}
|
|
@@ -147,7 +147,7 @@ describe('autoshipEligible', () => {
|
|
|
147
147
|
});
|
|
148
148
|
});
|
|
149
149
|
|
|
150
|
-
it('should return
|
|
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
|
-
'
|
|
159
|
-
'not-
|
|
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
|
-
'
|
|
172
|
-
'not-
|
|
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
|
-
|
|
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
|
|
179
|
-
|
|
180
|
-
|
|
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
|
|
186
|
-
cur?.selling_plan_allocations?.filter(sellingPlan =>
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
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),
|