@ordergroove/offers 2.27.9 → 2.27.12-alpha-PR-650-2.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 +23 -0
- package/dist/bundle-report.html +9 -9
- package/dist/examples.js +12 -1
- package/dist/examples.js.map +1 -1
- package/dist/offers.js +19 -19
- package/dist/offers.js.map +2 -2
- package/package.json +3 -3
- package/src/core/__tests__/api.spec.js +3 -1
- package/src/core/api.js +2 -1
- package/src/shopify/__tests__/shopifyReducer.spec.js +19 -22
- package/src/shopify/shopifyMiddleware.ts +1 -0
- package/src/shopify/shopifyReducer.js +25 -7
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ordergroove/offers",
|
|
3
|
-
"version": "2.27.
|
|
3
|
+
"version": "2.27.12-alpha-PR-650-2.0+35919fca",
|
|
4
4
|
"description": "offer state component",
|
|
5
5
|
"author": "Eugenio Lattanzio <eugenio63@gmail.com>",
|
|
6
6
|
"homepage": "https://github.com/ordergroove/plush-toys#readme",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"throttle-debounce": "^2.1.0"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
|
-
"@ordergroove/offers-templates": "^0.4.
|
|
46
|
+
"@ordergroove/offers-templates": "^0.4.15-alpha-PR-650-2.20+35919fca"
|
|
47
47
|
},
|
|
48
|
-
"gitHead": "
|
|
48
|
+
"gitHead": "35919fca6889ceec7109bc7f9f806160303966ef"
|
|
49
49
|
}
|
|
@@ -221,7 +221,9 @@ describe('api.fetchOrders', () => {
|
|
|
221
221
|
|
|
222
222
|
it('should call endpoint default params', async () => {
|
|
223
223
|
await underTest('https://host.com', { some: 'auth' }, 2, 'foo');
|
|
224
|
-
expect(fetchMock.lastUrl(MATCHED)).toEqual(
|
|
224
|
+
expect(fetchMock.lastUrl(MATCHED)).toEqual(
|
|
225
|
+
'https://host.com/orders/?status=2&ordering=foo&exclude_prepaid_orders=true'
|
|
226
|
+
);
|
|
225
227
|
});
|
|
226
228
|
});
|
|
227
229
|
|
package/src/core/api.js
CHANGED
|
@@ -337,32 +337,29 @@ describe('offerId', () => {
|
|
|
337
337
|
|
|
338
338
|
describe('optedin', () => {
|
|
339
339
|
it('should return optins given action SETUP_CART', () => {
|
|
340
|
-
const actual = optedin(
|
|
341
|
-
|
|
342
|
-
{
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
{
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
selling_plan: {
|
|
350
|
-
id: 'yum selling plan id 1'
|
|
351
|
-
}
|
|
340
|
+
const actual = optedin([], {
|
|
341
|
+
type: constants.SETUP_CART,
|
|
342
|
+
payload: {
|
|
343
|
+
items: [
|
|
344
|
+
{
|
|
345
|
+
key: 'yum item key 1',
|
|
346
|
+
selling_plan_allocation: {
|
|
347
|
+
selling_plan: {
|
|
348
|
+
id: 'yum selling plan id 1'
|
|
352
349
|
}
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
350
|
+
}
|
|
351
|
+
},
|
|
352
|
+
{
|
|
353
|
+
key: 'yum item key 2',
|
|
354
|
+
selling_plan_allocation: {
|
|
355
|
+
selling_plan: {
|
|
356
|
+
id: 'yum selling plan id 2'
|
|
360
357
|
}
|
|
361
358
|
}
|
|
362
|
-
|
|
363
|
-
|
|
359
|
+
}
|
|
360
|
+
]
|
|
364
361
|
}
|
|
365
|
-
);
|
|
362
|
+
});
|
|
366
363
|
|
|
367
364
|
expect(actual).toEqual([
|
|
368
365
|
{
|
|
@@ -165,13 +165,17 @@ export const offerId = (state = '', action) => 'native-shopify-offer';
|
|
|
165
165
|
export const optedin = (state = [], action) => {
|
|
166
166
|
if (constants.SETUP_CART === action.type) {
|
|
167
167
|
const cart = action.payload;
|
|
168
|
-
return
|
|
169
|
-
(
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
168
|
+
return state
|
|
169
|
+
.filter(it => !it.id.includes(':'))
|
|
170
|
+
.concat(
|
|
171
|
+
cart.items.reduce(
|
|
172
|
+
(acc, cur) =>
|
|
173
|
+
cur.selling_plan_allocation
|
|
174
|
+
? [...acc, { id: cur.key, frequency: `${cur.selling_plan_allocation.selling_plan.id}` }]
|
|
175
|
+
: acc,
|
|
176
|
+
[]
|
|
177
|
+
)
|
|
178
|
+
);
|
|
175
179
|
}
|
|
176
180
|
if (constants.RECEIVE_OFFER === action.type) {
|
|
177
181
|
const { autoship, autoship_by_default, in_stock, offer: offerEl } = action.payload;
|
|
@@ -186,6 +190,20 @@ export const optedin = (state = [], action) => {
|
|
|
186
190
|
state
|
|
187
191
|
);
|
|
188
192
|
}
|
|
193
|
+
|
|
194
|
+
if (constants.SETUP_PRODUCT === action.type) {
|
|
195
|
+
const productIds = action.payload.variants.map(variant => variant.id).map(id => `${id}`);
|
|
196
|
+
const sellingPlanGroup = getOGSellingPlanGroup(action.payload);
|
|
197
|
+
const frequencies = sellingPlanGroup?.selling_plans?.map(({ id }) => `${id}`);
|
|
198
|
+
// if the product is in the list of variants and its frequency isn't a valid selling plan, replace with the first valid selling plan
|
|
199
|
+
return state.map(cur => ({
|
|
200
|
+
...cur,
|
|
201
|
+
frequency:
|
|
202
|
+
productIds.some(id => id === cur.id) && !frequencies.some(freq => freq === cur.frequency)
|
|
203
|
+
? frequencies[0]
|
|
204
|
+
: cur.frequency
|
|
205
|
+
}));
|
|
206
|
+
}
|
|
189
207
|
return coreOptedin(state, action);
|
|
190
208
|
};
|
|
191
209
|
|