@ordergroove/offers 2.27.1 → 2.27.2-alpha-PR-637-7.13
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/dist/bundle-report.html +9 -9
- package/dist/offers.js +26 -26
- package/dist/offers.js.map +2 -2
- package/package.json +3 -3
- package/src/components/Offer.js +6 -5
- package/src/components/Price.js +6 -1
- package/src/core/__tests__/actions-preview.spec.js +73 -0
- package/src/core/actions-preview.js +23 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ordergroove/offers",
|
|
3
|
-
"version": "2.27.
|
|
3
|
+
"version": "2.27.2-alpha-PR-637-7.13+0752025c",
|
|
4
4
|
"description": "offer state component",
|
|
5
5
|
"author": "Eugenio Lattanzio <eugenio63@gmail.com>",
|
|
6
6
|
"homepage": "https://github.com/ordergroove/plush-toys#readme",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
],
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"@ordergroove/auth": "^2.3.0",
|
|
37
|
-
"@ordergroove/offers-live-editor": "^0.4.
|
|
37
|
+
"@ordergroove/offers-live-editor": "^0.4.3-alpha-PR-637-7.184+0752025c",
|
|
38
38
|
"lit-element": "^2.1.0",
|
|
39
39
|
"lodash.memoize": "^4.1.2",
|
|
40
40
|
"logical-expression-parser": "1.0.0",
|
|
@@ -45,5 +45,5 @@
|
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"@ordergroove/offers-templates": "^0.4.12"
|
|
47
47
|
},
|
|
48
|
-
"gitHead": "
|
|
48
|
+
"gitHead": "0752025cec496c059a3c8a89ba92f72eac7d2114"
|
|
49
49
|
}
|
package/src/components/Offer.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { html, css } from 'lit-element';
|
|
2
2
|
import memoize from 'lodash.memoize';
|
|
3
3
|
import { connect } from '../core/connect';
|
|
4
|
-
import { setPreview } from '../core/actions-preview';
|
|
4
|
+
import { setPreview, setPlanPrices } from '../core/actions-preview';
|
|
5
5
|
import {
|
|
6
6
|
fetchOffer,
|
|
7
7
|
productHasChangedComponents,
|
|
@@ -149,11 +149,11 @@ export class Offer extends TemplateElement {
|
|
|
149
149
|
<og-price discount>
|
|
150
150
|
<span slot="prepend">Subscribe and get</span>
|
|
151
151
|
<span slot="append">off</span>
|
|
152
|
-
<og-text key="offerOptInLabel" slot="fallback"></og-text>
|
|
152
|
+
<og-text key="offerOptInLabel" slot="fallback"></og-text>
|
|
153
153
|
</og-price>
|
|
154
154
|
<og-price regular></og-price>
|
|
155
155
|
<og-price subscription></og-price>
|
|
156
|
-
|
|
156
|
+
|
|
157
157
|
</og-optin-button>
|
|
158
158
|
<og-tooltip placement="bottom">
|
|
159
159
|
<div slot="trigger">
|
|
@@ -217,7 +217,7 @@ export class Offer extends TemplateElement {
|
|
|
217
217
|
The product is in your next upcomming order
|
|
218
218
|
</og-when>
|
|
219
219
|
</og-when>
|
|
220
|
-
|
|
220
|
+
|
|
221
221
|
`;
|
|
222
222
|
}
|
|
223
223
|
|
|
@@ -343,7 +343,8 @@ export const ConnectedOffer = connect(mapStateToProps, {
|
|
|
343
343
|
optinProduct,
|
|
344
344
|
setFirstOrderPlaceDate,
|
|
345
345
|
setProductToSubscribe,
|
|
346
|
-
setPreview
|
|
346
|
+
setPreview,
|
|
347
|
+
setPlanPrices
|
|
347
348
|
})(Offer);
|
|
348
349
|
|
|
349
350
|
export default ConnectedOffer;
|
package/src/components/Price.js
CHANGED
|
@@ -26,17 +26,22 @@ export class Price extends withProduct(TemplateElement) {
|
|
|
26
26
|
const currentPlan = plans[frequency] || [];
|
|
27
27
|
if (!currentPlan) return '';
|
|
28
28
|
const [regularPrice, discountRate, subscriptionPrice] = currentPlan;
|
|
29
|
+
|
|
29
30
|
if (subscriptionPrice === regularPrice) return '';
|
|
30
31
|
|
|
31
32
|
if (this.regular) {
|
|
32
33
|
return regularPrice;
|
|
33
34
|
}
|
|
34
|
-
if (this.discount)
|
|
35
|
+
if (this.discount) {
|
|
36
|
+
return discountRate;
|
|
37
|
+
}
|
|
38
|
+
|
|
35
39
|
return subscriptionPrice;
|
|
36
40
|
}
|
|
37
41
|
|
|
38
42
|
render() {
|
|
39
43
|
const value = this.value;
|
|
44
|
+
|
|
40
45
|
if (value)
|
|
41
46
|
return html`
|
|
42
47
|
<slot name="prepend"></slot>
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { setPlanPrices } from '../actions-preview';
|
|
2
|
+
import * as constants from '../constants';
|
|
3
|
+
|
|
4
|
+
describe('setPlanPrices', () => {
|
|
5
|
+
const mockState = {
|
|
6
|
+
productPlans: {
|
|
7
|
+
'mock-product-id': {
|
|
8
|
+
'3_1': [1, 2, 3]
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
const mockDispatch = jasmine.createSpy('dispatch');
|
|
13
|
+
const mockGetState = jasmine.createSpy('mockGetState').and.returnValue(mockState);
|
|
14
|
+
it('should update all preview plans to specified frequency', async () => {
|
|
15
|
+
await setPlanPrices(['mock1', 'mock2', 'mock3'], '3_1', { product: { id: 'mock-product-id' } })(
|
|
16
|
+
mockDispatch,
|
|
17
|
+
mockGetState
|
|
18
|
+
);
|
|
19
|
+
expect(mockDispatch).toHaveBeenCalledWith({
|
|
20
|
+
type: constants.RECEIVE_PRODUCT_PLANS,
|
|
21
|
+
payload: {
|
|
22
|
+
'mock-product-id': {
|
|
23
|
+
'3_1': ['mock1', 'mock2', 'mock3']
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('should should not override baseState', async () => {
|
|
30
|
+
await setPlanPrices(['mock1', 'mock2', 'mock3'], '3_1', { product: { id: 'mock-product-id' } })(
|
|
31
|
+
mockDispatch,
|
|
32
|
+
mockGetState
|
|
33
|
+
);
|
|
34
|
+
expect(mockDispatch).toHaveBeenCalledWith({
|
|
35
|
+
type: constants.RECEIVE_PRODUCT_PLANS,
|
|
36
|
+
payload: {
|
|
37
|
+
'mock-product-id': {
|
|
38
|
+
'3_1': ['mock1', 'mock2', 'mock3']
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
expect(mockState).toEqual({
|
|
43
|
+
productPlans: {
|
|
44
|
+
'mock-product-id': {
|
|
45
|
+
'3_1': [1, 2, 3]
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it('should override all frequencies if all is given', async () => {
|
|
52
|
+
await setPlanPrices(['mock1', 'mock2', 'mock3'], 'all', { product: { id: 'mock-product-id' } })(
|
|
53
|
+
mockDispatch,
|
|
54
|
+
mockGetState
|
|
55
|
+
);
|
|
56
|
+
expect(mockDispatch).toHaveBeenCalledWith({
|
|
57
|
+
type: constants.RECEIVE_PRODUCT_PLANS,
|
|
58
|
+
payload: {
|
|
59
|
+
'mock-product-id': {
|
|
60
|
+
'1_1': ['mock1', 'mock2', 'mock3'],
|
|
61
|
+
'1_2': ['mock1', 'mock2', 'mock3'],
|
|
62
|
+
'1_3': ['mock1', 'mock2', 'mock3'],
|
|
63
|
+
'2_1': ['mock1', 'mock2', 'mock3'],
|
|
64
|
+
'2_2': ['mock1', 'mock2', 'mock3'],
|
|
65
|
+
'2_3': ['mock1', 'mock2', 'mock3'],
|
|
66
|
+
'3_1': ['mock1', 'mock2', 'mock3'],
|
|
67
|
+
'3_2': ['mock1', 'mock2', 'mock3'],
|
|
68
|
+
'3_3': ['mock1', 'mock2', 'mock3']
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
});
|
|
@@ -140,3 +140,26 @@ export const setPreview = (value, oldValue, ownProps) =>
|
|
|
140
140
|
default:
|
|
141
141
|
}
|
|
142
142
|
};
|
|
143
|
+
|
|
144
|
+
export const setPlanPrices = ([regularPrice, discountRate, subscribePrice], frequency = 'all', ownProps) =>
|
|
145
|
+
async function(dispatch, getState) {
|
|
146
|
+
const nextProductPlans = Object.assign(
|
|
147
|
+
{},
|
|
148
|
+
{ [ownProps.product.id]: {} },
|
|
149
|
+
// deep cloning productPlans
|
|
150
|
+
Object.fromEntries(Object.entries(getState()?.productPlans).map(([k, v]) => [k, Object.assign({}, v)])) || {}
|
|
151
|
+
);
|
|
152
|
+
|
|
153
|
+
if (frequency === 'all') {
|
|
154
|
+
['1_1', '1_2', '1_3', '2_1', '2_2', '2_3', '3_1', '3_2', '3_3'].forEach(freq => {
|
|
155
|
+
nextProductPlans[ownProps.product.id][freq] = [regularPrice, discountRate, subscribePrice];
|
|
156
|
+
});
|
|
157
|
+
} else {
|
|
158
|
+
nextProductPlans[ownProps.product.id][frequency] = [regularPrice, discountRate, subscribePrice];
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
await dispatch({
|
|
162
|
+
type: constants.RECEIVE_PRODUCT_PLANS,
|
|
163
|
+
payload: nextProductPlans
|
|
164
|
+
});
|
|
165
|
+
};
|