@ordergroove/offers 2.36.2-alpha-PR-836-2.3 → 2.37.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 +17 -0
- package/dist/bundle-report.html +3 -3
- package/dist/offers.js +22 -22
- package/dist/offers.js.map +3 -3
- package/package.json +2 -2
- package/src/components/Offer.js +25 -11
- package/src/components/__tests__/Offer.spec.js +37 -18
- package/src/shopify/__tests__/shopifyReducer.spec.js +41 -19
- package/src/shopify/shopifyReducer.js +7 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ordergroove/offers",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.37.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": "e702e182ecc53ced69c632d6269bb8f98c778b42"
|
|
52
52
|
}
|
package/src/components/Offer.js
CHANGED
|
@@ -28,16 +28,24 @@ import { DEFAULT_OFFER_MODULE } from '../core/constants';
|
|
|
28
28
|
|
|
29
29
|
const memoizeKey = (...args) => JSON.stringify(args);
|
|
30
30
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
31
|
+
const logOnce = messageFn => {
|
|
32
|
+
let hasLogged = false;
|
|
33
|
+
return (...args) => {
|
|
34
|
+
if (!hasLogged) {
|
|
35
|
+
console.warn(messageFn(...args));
|
|
36
|
+
hasLogged = true;
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const logMulticurrencyWarning = logOnce(
|
|
42
|
+
(storeCurrency, primaryCurrency) =>
|
|
43
|
+
`Hiding Ordergroove offer since the store currency ${storeCurrency} does not match your configured currency ${primaryCurrency} and you are not set up for multicurrency. Contact your Ordergroove representative for next steps.`
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
const logProductSpecificFrequencyListWarning = logOnce(
|
|
47
|
+
() => `Hiding Ordergroove offer since cart offers does not currently support product-specific frequency lists.`
|
|
48
|
+
);
|
|
41
49
|
|
|
42
50
|
export const productAndComponents = memoize(
|
|
43
51
|
(product, components) => Object.assign({ components }, product),
|
|
@@ -327,8 +335,14 @@ export class Offer extends TemplateElement {
|
|
|
327
335
|
this.config.storeCurrency === this.config.merchantSettings.currency_code;
|
|
328
336
|
if (!shouldEnable) {
|
|
329
337
|
logMulticurrencyWarning(this.config.storeCurrency, this.config.merchantSettings.currency_code);
|
|
338
|
+
return false;
|
|
330
339
|
}
|
|
331
|
-
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
// product-specific frequency lists are not supported in cart offers
|
|
343
|
+
if (this.isCart && this.config?.hasProductSpecificFrequencies) {
|
|
344
|
+
logProductSpecificFrequencyListWarning();
|
|
345
|
+
return false;
|
|
332
346
|
}
|
|
333
347
|
|
|
334
348
|
return true;
|
|
@@ -302,25 +302,25 @@ describe('previewMode', () => {
|
|
|
302
302
|
});
|
|
303
303
|
});
|
|
304
304
|
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
}
|
|
305
|
+
async function getOfferElement(config) {
|
|
306
|
+
const element = new Offer();
|
|
307
|
+
element.innerHTML = `
|
|
308
|
+
<p>Offer content</p>
|
|
309
|
+
`;
|
|
310
|
+
element.config = config;
|
|
311
|
+
await appendToBody(element);
|
|
312
|
+
return element;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
function assertOfferShown(element) {
|
|
316
|
+
expect(element.querySelector('*').assignedSlot).not.toBeNull();
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
function assertOfferHidden(element) {
|
|
320
|
+
expect(element.querySelector('*').assignedSlot).toBeNull();
|
|
321
|
+
}
|
|
323
322
|
|
|
323
|
+
describe('multi-currency', () => {
|
|
324
324
|
it('should show the offer when config not set', async () => {
|
|
325
325
|
const element = await getOfferElement();
|
|
326
326
|
assertOfferShown(element);
|
|
@@ -369,3 +369,22 @@ describe('multi-currency', () => {
|
|
|
369
369
|
assertOfferShown(element);
|
|
370
370
|
});
|
|
371
371
|
});
|
|
372
|
+
|
|
373
|
+
describe('product specific frequencies', () => {
|
|
374
|
+
it('should hide the offer when on cart', async () => {
|
|
375
|
+
const element = await getOfferElement({
|
|
376
|
+
hasProductSpecificFrequencies: true
|
|
377
|
+
});
|
|
378
|
+
element.isCart = true;
|
|
379
|
+
await element.updateComplete;
|
|
380
|
+
|
|
381
|
+
assertOfferHidden(element);
|
|
382
|
+
});
|
|
383
|
+
|
|
384
|
+
it('should show the offer when not on cart', async () => {
|
|
385
|
+
const element = await getOfferElement({
|
|
386
|
+
hasProductSpecificFrequencies: true
|
|
387
|
+
});
|
|
388
|
+
assertOfferShown(element);
|
|
389
|
+
});
|
|
390
|
+
});
|
|
@@ -337,34 +337,37 @@ describe('config', () => {
|
|
|
337
337
|
);
|
|
338
338
|
});
|
|
339
339
|
|
|
340
|
+
const defaultSellingPlanPayload = {
|
|
341
|
+
product: {
|
|
342
|
+
selling_plan_groups: [
|
|
343
|
+
{
|
|
344
|
+
name: DEFAULT_PAY_AS_YOU_GO_GROUP_NAME,
|
|
345
|
+
selling_plans: [
|
|
346
|
+
{
|
|
347
|
+
id: 'yum selling plan id 1'
|
|
348
|
+
},
|
|
349
|
+
{
|
|
350
|
+
id: 'yum selling plan id 2'
|
|
351
|
+
}
|
|
352
|
+
]
|
|
353
|
+
}
|
|
354
|
+
]
|
|
355
|
+
}
|
|
356
|
+
};
|
|
357
|
+
|
|
340
358
|
it('should return selling plan ids as frequencies given action SETUP_PRODUCT', () => {
|
|
341
359
|
const actual = config(
|
|
342
360
|
{},
|
|
343
361
|
{
|
|
344
362
|
type: constants.SETUP_PRODUCT,
|
|
345
|
-
payload:
|
|
346
|
-
product: {
|
|
347
|
-
selling_plan_groups: [
|
|
348
|
-
{
|
|
349
|
-
name: DEFAULT_PAY_AS_YOU_GO_GROUP_NAME,
|
|
350
|
-
selling_plans: [
|
|
351
|
-
{
|
|
352
|
-
id: 'yum selling plan id 1'
|
|
353
|
-
},
|
|
354
|
-
{
|
|
355
|
-
id: 'yum selling plan id 2'
|
|
356
|
-
}
|
|
357
|
-
]
|
|
358
|
-
}
|
|
359
|
-
]
|
|
360
|
-
}
|
|
361
|
-
}
|
|
363
|
+
payload: defaultSellingPlanPayload
|
|
362
364
|
}
|
|
363
365
|
);
|
|
364
366
|
|
|
365
367
|
expect(actual).toEqual(
|
|
366
368
|
jasmine.objectContaining({
|
|
367
|
-
frequencies: ['yum selling plan id 1', 'yum selling plan id 2']
|
|
369
|
+
frequencies: ['yum selling plan id 1', 'yum selling plan id 2'],
|
|
370
|
+
hasProductSpecificFrequencies: false
|
|
368
371
|
})
|
|
369
372
|
);
|
|
370
373
|
});
|
|
@@ -462,7 +465,26 @@ describe('config', () => {
|
|
|
462
465
|
|
|
463
466
|
expect(actual).toEqual(
|
|
464
467
|
jasmine.objectContaining({
|
|
465
|
-
frequencies: ['psfl-id-1', 'psfl-id-2', 'psfl-id-3']
|
|
468
|
+
frequencies: ['psfl-id-1', 'psfl-id-2', 'psfl-id-3'],
|
|
469
|
+
hasProductSpecificFrequencies: true
|
|
470
|
+
})
|
|
471
|
+
);
|
|
472
|
+
});
|
|
473
|
+
|
|
474
|
+
it('does not overwrite hasProductSpecificFrequencies on subsequent calls', () => {
|
|
475
|
+
const actual = config(
|
|
476
|
+
{
|
|
477
|
+
hasProductSpecificFrequencies: true
|
|
478
|
+
},
|
|
479
|
+
{
|
|
480
|
+
type: constants.SETUP_PRODUCT,
|
|
481
|
+
payload: defaultSellingPlanPayload
|
|
482
|
+
}
|
|
483
|
+
);
|
|
484
|
+
|
|
485
|
+
expect(actual).toEqual(
|
|
486
|
+
jasmine.objectContaining({
|
|
487
|
+
hasProductSpecificFrequencies: true
|
|
466
488
|
})
|
|
467
489
|
);
|
|
468
490
|
});
|
|
@@ -127,8 +127,8 @@ export const reduceNewOptinsFromOfferResponse = (
|
|
|
127
127
|
}, []);
|
|
128
128
|
|
|
129
129
|
const getOGSellingPlanGroup = product => {
|
|
130
|
-
const productSpecificFrequencySellingPlanGroup = product?.selling_plan_groups.find(
|
|
131
|
-
|
|
130
|
+
const productSpecificFrequencySellingPlanGroup = product?.selling_plan_groups.find(
|
|
131
|
+
isProductSpecificFrequencySellingPlanGroup
|
|
132
132
|
);
|
|
133
133
|
|
|
134
134
|
return (
|
|
@@ -137,6 +137,8 @@ const getOGSellingPlanGroup = product => {
|
|
|
137
137
|
);
|
|
138
138
|
};
|
|
139
139
|
|
|
140
|
+
const isProductSpecificFrequencySellingPlanGroup = group => group.name.startsWith('og_psfl');
|
|
141
|
+
|
|
140
142
|
const productOrVariantInStockReducer = (acc, cur) => ({
|
|
141
143
|
...overrideLineKey(acc, cur.id, cur.available),
|
|
142
144
|
[cur.id]: cur.available
|
|
@@ -285,7 +287,9 @@ export const config = (
|
|
|
285
287
|
frequencies,
|
|
286
288
|
frequenciesEveryPeriod,
|
|
287
289
|
frequenciesText,
|
|
288
|
-
...(defaultFrequency ? { defaultFrequency } : {})
|
|
290
|
+
...(defaultFrequency ? { defaultFrequency } : {}),
|
|
291
|
+
hasProductSpecificFrequencies:
|
|
292
|
+
state.hasProductSpecificFrequencies || isProductSpecificFrequencySellingPlanGroup(sellingPlanGroup)
|
|
289
293
|
};
|
|
290
294
|
}
|
|
291
295
|
|