@ordergroove/offers 2.27.18 → 2.27.19-alpha-PR-659-2.1
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.27.
|
|
3
|
+
"version": "2.27.19-alpha-PR-659-2.1+ce990eef",
|
|
4
4
|
"description": "offer state component",
|
|
5
5
|
"author": "Eugenio Lattanzio <eugenio63@gmail.com>",
|
|
6
6
|
"homepage": "https://github.com/ordergroove/plush-toys#readme",
|
|
@@ -45,5 +45,5 @@
|
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"@ordergroove/offers-templates": "^0.4.15"
|
|
47
47
|
},
|
|
48
|
-
"gitHead": "
|
|
48
|
+
"gitHead": "ce990eef6d106e43adf08c563903844bd8d45e13"
|
|
49
49
|
}
|
package/src/core/actions.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { resolveAuth } from '@ordergroove/auth';
|
|
2
2
|
import * as constants from './constants';
|
|
3
3
|
import { api } from './api';
|
|
4
|
-
import
|
|
5
|
-
import { safeProductId } from './utils';
|
|
4
|
+
import { safeOgFrequency, safeProductId } from './utils';
|
|
6
5
|
|
|
7
6
|
export const optinProduct = (product, frequency, offer) => ({
|
|
8
7
|
type: constants.OPTIN_PRODUCT,
|
|
@@ -231,10 +230,11 @@ export const receiveConvertOneTime = (response, product) => ({
|
|
|
231
230
|
payload: { response, product }
|
|
232
231
|
});
|
|
233
232
|
|
|
234
|
-
export const createIu = (product, order, quantity, subscribed = false,
|
|
233
|
+
export const createIu = (product, order, quantity, subscribed = false, initialFrequency = null) =>
|
|
235
234
|
function createIuThunk(dispatch, getState) {
|
|
236
235
|
const {
|
|
237
236
|
auth,
|
|
237
|
+
config,
|
|
238
238
|
environment: { legoUrl },
|
|
239
239
|
previewUpsellOffer,
|
|
240
240
|
offerId: offer
|
|
@@ -242,6 +242,8 @@ export const createIu = (product, order, quantity, subscribed = false, frequency
|
|
|
242
242
|
|
|
243
243
|
if (!auth) return dispatch(unauthorized('No auth set.'));
|
|
244
244
|
|
|
245
|
+
const frequency = safeOgFrequency(initialFrequency, config);
|
|
246
|
+
|
|
245
247
|
const requestAction = requestCreateOneTime(product, order, quantity, offer);
|
|
246
248
|
|
|
247
249
|
dispatch(requestAction);
|
package/src/core/utils.ts
CHANGED
|
@@ -45,6 +45,24 @@ export const safeProductId = product => {
|
|
|
45
45
|
}
|
|
46
46
|
return productId;
|
|
47
47
|
};
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Returns the OG frequency if platform is running on selling plans
|
|
51
|
+
* @param initialFrequency
|
|
52
|
+
* @param param1
|
|
53
|
+
*/
|
|
54
|
+
export const safeOgFrequency = (initialFrequency, config) => {
|
|
55
|
+
if (platform?.shopify_selling_plans) {
|
|
56
|
+
const ix = config?.frequencies?.indexOf(initialFrequency);
|
|
57
|
+
if (ix >= 0 && config?.frequenciesEveryPeriod[ix]) {
|
|
58
|
+
return config?.frequenciesEveryPeriod[ix];
|
|
59
|
+
} else {
|
|
60
|
+
throw `OG Can't convert selling_plain_id ${initialFrequency} to OG frequency every period`;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return initialFrequency;
|
|
64
|
+
};
|
|
65
|
+
|
|
48
66
|
/**
|
|
49
67
|
* Attempts to auto initialize the offer library reading the merchantId and env from
|
|
50
68
|
* integration script i.e. <script src="http://static.ordergroove...."/>.
|
|
@@ -5,7 +5,6 @@ import {
|
|
|
5
5
|
config,
|
|
6
6
|
inStock,
|
|
7
7
|
offer,
|
|
8
|
-
offerId,
|
|
9
8
|
optedin,
|
|
10
9
|
productOffer,
|
|
11
10
|
productPlans,
|
|
@@ -328,14 +327,6 @@ describe('offer', () => {
|
|
|
328
327
|
});
|
|
329
328
|
});
|
|
330
329
|
|
|
331
|
-
describe('offerId', () => {
|
|
332
|
-
it('should return shopify constant', () => {
|
|
333
|
-
const actual = offerId();
|
|
334
|
-
|
|
335
|
-
expect(actual).toEqual('native-shopify-offer');
|
|
336
|
-
});
|
|
337
|
-
});
|
|
338
|
-
|
|
339
330
|
describe('optedin', () => {
|
|
340
331
|
it('should return optins given action SETUP_CART', () => {
|
|
341
332
|
const actual = optedin([], {
|
|
@@ -16,6 +16,7 @@ import baseReducer, {
|
|
|
16
16
|
nextUpcomingOrder,
|
|
17
17
|
optedin as coreOptedin,
|
|
18
18
|
optedout,
|
|
19
|
+
offerId,
|
|
19
20
|
previewStandardOffer,
|
|
20
21
|
previewUpsellOffer,
|
|
21
22
|
productToSubscribe,
|
|
@@ -178,8 +179,6 @@ export const inStock = (state = {}, action) => {
|
|
|
178
179
|
|
|
179
180
|
export const offer = (state = {}, action) => state;
|
|
180
181
|
|
|
181
|
-
export const offerId = (state = '', action) => 'native-shopify-offer';
|
|
182
|
-
|
|
183
182
|
export const optedin = (state = [], action) => {
|
|
184
183
|
if (constants.SETUP_CART === action.type) {
|
|
185
184
|
const cart = action.payload;
|