@daffodil/cart 0.94.1-rc.0 → 0.95.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/fesm2022/daffodil-cart-driver-in-memory.mjs +1618 -1198
- package/fesm2022/daffodil-cart-driver-in-memory.mjs.map +1 -1
- package/fesm2022/daffodil-cart-driver-magento-2.4.7-testing.mjs +546 -0
- package/fesm2022/daffodil-cart-driver-magento-2.4.7-testing.mjs.map +1 -0
- package/fesm2022/daffodil-cart-driver-magento-2.4.7.mjs +2607 -0
- package/fesm2022/daffodil-cart-driver-magento-2.4.7.mjs.map +1 -0
- package/fesm2022/daffodil-cart-driver-magento-auto-testing.mjs +7 -0
- package/fesm2022/daffodil-cart-driver-magento-auto-testing.mjs.map +1 -0
- package/fesm2022/daffodil-cart-driver-magento-auto.mjs +7 -0
- package/fesm2022/daffodil-cart-driver-magento-auto.mjs.map +1 -0
- package/fesm2022/daffodil-cart-driver-testing.mjs +553 -335
- package/fesm2022/daffodil-cart-driver-testing.mjs.map +1 -1
- package/fesm2022/daffodil-cart-driver.mjs +167 -292
- package/fesm2022/daffodil-cart-driver.mjs.map +1 -1
- package/fesm2022/daffodil-cart-routing.mjs +741 -542
- package/fesm2022/daffodil-cart-routing.mjs.map +1 -1
- package/fesm2022/daffodil-cart-state-testing.mjs +288 -193
- package/fesm2022/daffodil-cart-state-testing.mjs.map +1 -1
- package/fesm2022/daffodil-cart-state.mjs +2571 -2800
- package/fesm2022/daffodil-cart-state.mjs.map +1 -1
- package/fesm2022/daffodil-cart-testing.mjs +542 -357
- package/fesm2022/daffodil-cart-testing.mjs.map +1 -1
- package/fesm2022/daffodil-cart.mjs +131 -200
- package/fesm2022/daffodil-cart.mjs.map +1 -1
- package/package.json +1 -1
- package/types/daffodil-cart-driver-in-memory.d.ts +273 -292
- package/types/daffodil-cart-driver-magento-2.4.7-testing.d.ts +176 -0
- package/types/daffodil-cart-driver-magento-2.4.7.d.ts +860 -0
- package/types/daffodil-cart-driver-magento-auto-testing.d.ts +1 -0
- package/types/daffodil-cart-driver-magento-auto.d.ts +1 -0
- package/types/daffodil-cart-driver-testing.d.ts +111 -118
- package/types/daffodil-cart-driver.d.ts +219 -262
- package/types/daffodil-cart-routing.d.ts +130 -149
- package/types/daffodil-cart-state-testing.d.ts +115 -114
- package/types/daffodil-cart-state.d.ts +1126 -1173
- package/types/daffodil-cart-testing.d.ts +146 -158
- package/types/daffodil-cart.d.ts +302 -321
- package/fesm2022/daffodil-cart-driver-magento-testing.mjs +0 -332
- package/fesm2022/daffodil-cart-driver-magento-testing.mjs.map +0 -1
- package/fesm2022/daffodil-cart-driver-magento.mjs +0 -2273
- package/fesm2022/daffodil-cart-driver-magento.mjs.map +0 -1
- package/types/daffodil-cart-driver-magento-testing.d.ts +0 -188
- package/types/daffodil-cart-driver-magento.d.ts +0 -999
|
@@ -1,1205 +1,1625 @@
|
|
|
1
|
-
import * as i1 from
|
|
2
|
-
import * as i0 from
|
|
3
|
-
import {
|
|
4
|
-
import * as i2 from
|
|
5
|
-
import { STATUS } from
|
|
6
|
-
import {
|
|
7
|
-
import { catchError, map } from
|
|
8
|
-
import { DaffCartNotFoundError,
|
|
9
|
-
import {
|
|
10
|
-
import { CommonModule } from
|
|
11
|
-
import * as i1
|
|
12
|
-
import * as i2
|
|
13
|
-
import { faker } from
|
|
14
|
-
import { DaffCartTotalTypeEnum } from
|
|
15
|
-
import { createSingleInjectionToken, daffMultiply } from
|
|
16
|
-
|
|
17
|
-
const
|
|
18
|
-
const
|
|
19
|
-
const
|
|
20
|
-
const
|
|
21
|
-
const
|
|
22
|
-
const
|
|
23
|
-
const
|
|
24
|
-
const
|
|
25
|
-
const
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
i0.ɵɵ
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
}
|
|
172
|
-
i0.ɵɵngDeclareClassMetadata({
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
}
|
|
223
|
-
i0.ɵɵngDeclareClassMetadata({
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
i0.ɵɵ
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
1
|
+
import * as i1$1 from "@angular/common/http";
|
|
2
|
+
import * as i0 from "@angular/core";
|
|
3
|
+
import { Inject, Injectable, NgModule, makeEnvironmentProviders } from "@angular/core";
|
|
4
|
+
import * as i2$1 from "angular-in-memory-web-api";
|
|
5
|
+
import { STATUS } from "angular-in-memory-web-api";
|
|
6
|
+
import { of, throwError } from "rxjs";
|
|
7
|
+
import { catchError, map } from "rxjs/operators";
|
|
8
|
+
import { DaffCartNotFoundError, provideDaffCartAddressDriver, provideDaffCartBillingAddressDriver, provideDaffCartCouponDriver, provideDaffCartDriver, provideDaffCartItemDriver, provideDaffCartOrderDriver, provideDaffCartPaymentDriver, provideDaffCartPaymentMethodsDriver, provideDaffCartShippingAddressDriver, provideDaffCartShippingInformationDriver, provideDaffCartShippingMethodsDriver } from "@daffodil/cart/driver";
|
|
9
|
+
import { DAFF_IN_MEMORY_DRIVER_CONFIG, DaffInMemoryBackendDelegate, DaffInMemoryDriverBase, provideDaffInMemoryBackends } from "@daffodil/driver/in-memory";
|
|
10
|
+
import { CommonModule } from "@angular/common";
|
|
11
|
+
import * as i1 from "@daffodil/cart/testing";
|
|
12
|
+
import * as i2 from "@daffodil/product/driver/in-memory";
|
|
13
|
+
import { faker } from "@faker-js/faker/locale/en_US";
|
|
14
|
+
import { DaffCartTotalTypeEnum } from "@daffodil/cart";
|
|
15
|
+
import { createSingleInjectionToken, daffMultiply } from "@daffodil/core";
|
|
16
|
+
const DAFF_CART_IN_MEMORY_CART_COLLECTION_NAME = "cart";
|
|
17
|
+
const DAFF_CART_IN_MEMORY_CART_ITEMS_COLLECTION_NAME = "cart-items";
|
|
18
|
+
const DAFF_CART_IN_MEMORY_CART_ORDER_COLLECTION_NAME = "cart-order";
|
|
19
|
+
const DAFF_CART_IN_MEMORY_CART_COUPON_COLLECTION_NAME = "cart-coupon";
|
|
20
|
+
const DAFF_CART_IN_MEMORY_CART_ADDRESS_COLLECTION_NAME = "cart-address";
|
|
21
|
+
const DAFF_CART_IN_MEMORY_CART_SHIPPING_ADDRESS_COLLECTION_NAME = "cart-shipping-address";
|
|
22
|
+
const DAFF_CART_IN_MEMORY_CART_BILLING_ADDRESS_COLLECTION_NAME = "cart-billing-address";
|
|
23
|
+
const DAFF_CART_IN_MEMORY_CART_PAYMENT_METHODS_COLLECTION_NAME = "cart-payment-methods";
|
|
24
|
+
const DAFF_CART_IN_MEMORY_CART_SHIPPING_METHODS_COLLECTION_NAME = "cart-shipping-methods";
|
|
25
|
+
const DAFF_CART_IN_MEMORY_CART_PAYMENT_COLLECTION_NAME = "cart-payment";
|
|
26
|
+
const DAFF_CART_IN_MEMORY_CART_SHIPPING_COLLECTION_NAME = "cart-shipping-information";
|
|
27
|
+
var DaffInMemoryCartService = class DaffInMemoryCartService extends DaffInMemoryDriverBase {
|
|
28
|
+
constructor(http, config) {
|
|
29
|
+
super(config, DAFF_CART_IN_MEMORY_CART_COLLECTION_NAME);
|
|
30
|
+
this.http = http;
|
|
31
|
+
}
|
|
32
|
+
get(cartId) {
|
|
33
|
+
return this.http.get(`${this.url}/${cartId}`).pipe(catchError((error) => throwError(() => new DaffCartNotFoundError(error.message))), map((result) => ({
|
|
34
|
+
response: result,
|
|
35
|
+
errors: []
|
|
36
|
+
})));
|
|
37
|
+
}
|
|
38
|
+
addToCart(productId, qty) {
|
|
39
|
+
return this.http.post(this.url + "/addToCart", {
|
|
40
|
+
productId,
|
|
41
|
+
qty
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
clear(cartId) {
|
|
45
|
+
return this.http.post(`${this.url}/${cartId}/clear`, {});
|
|
46
|
+
}
|
|
47
|
+
create() {
|
|
48
|
+
return this.http.post(this.url, {});
|
|
49
|
+
}
|
|
50
|
+
merge(guestCart, customerCart) {
|
|
51
|
+
return this.http.post(`${this.url}/${guestCart}/merge`, {
|
|
52
|
+
source: guestCart,
|
|
53
|
+
destination: customerCart
|
|
54
|
+
}).pipe(catchError((error) => throwError(() => new DaffCartNotFoundError(error.message))), map((result) => ({
|
|
55
|
+
response: result,
|
|
56
|
+
errors: []
|
|
57
|
+
})));
|
|
58
|
+
}
|
|
59
|
+
static {
|
|
60
|
+
this.ɵfac = i0.ɵɵngDeclareFactory({
|
|
61
|
+
minVersion: "12.0.0",
|
|
62
|
+
version: "22.2.4",
|
|
63
|
+
ngImport: i0,
|
|
64
|
+
type: DaffInMemoryCartService,
|
|
65
|
+
deps: [{ token: i1$1.HttpClient }, { token: i2$1.InMemoryBackendConfig }],
|
|
66
|
+
target: i0.ɵɵFactoryTarget.Injectable
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
static {
|
|
70
|
+
this.ɵprov = i0.ɵɵngDeclareInjectable({
|
|
71
|
+
minVersion: "12.0.0",
|
|
72
|
+
version: "22.2.4",
|
|
73
|
+
ngImport: i0,
|
|
74
|
+
type: DaffInMemoryCartService,
|
|
75
|
+
providedIn: "root"
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
80
|
+
minVersion: "12.0.0",
|
|
81
|
+
version: "22.2.4",
|
|
82
|
+
ngImport: i0,
|
|
83
|
+
type: DaffInMemoryCartService,
|
|
84
|
+
decorators: [{
|
|
85
|
+
type: Injectable,
|
|
86
|
+
args: [{ providedIn: "root" }]
|
|
87
|
+
}],
|
|
88
|
+
ctorParameters: () => [{ type: i1$1.HttpClient }, { type: i2$1.InMemoryBackendConfig }]
|
|
89
|
+
});
|
|
90
|
+
var DaffInMemoryCartItemService = class DaffInMemoryCartItemService extends DaffInMemoryDriverBase {
|
|
91
|
+
constructor(http, config) {
|
|
92
|
+
super(config, DAFF_CART_IN_MEMORY_CART_ITEMS_COLLECTION_NAME);
|
|
93
|
+
this.http = http;
|
|
94
|
+
}
|
|
95
|
+
list(cartId) {
|
|
96
|
+
return this.http.get(`${this.url}/${cartId}/`);
|
|
97
|
+
}
|
|
98
|
+
get(cartId, itemId) {
|
|
99
|
+
return this.http.get(`${this.url}/${cartId}/${itemId}`);
|
|
100
|
+
}
|
|
101
|
+
add(cartId, input) {
|
|
102
|
+
return this.http.post(`${this.url}/${cartId}/`, input);
|
|
103
|
+
}
|
|
104
|
+
update(cartId, itemId, item) {
|
|
105
|
+
return this.http.put(`${this.url}/${cartId}/${itemId}`, item);
|
|
106
|
+
}
|
|
107
|
+
delete(cartId, itemId) {
|
|
108
|
+
return this.http.delete(`${this.url}/${cartId}/${itemId}`);
|
|
109
|
+
}
|
|
110
|
+
static {
|
|
111
|
+
this.ɵfac = i0.ɵɵngDeclareFactory({
|
|
112
|
+
minVersion: "12.0.0",
|
|
113
|
+
version: "22.2.4",
|
|
114
|
+
ngImport: i0,
|
|
115
|
+
type: DaffInMemoryCartItemService,
|
|
116
|
+
deps: [{ token: i1$1.HttpClient }, { token: i2$1.InMemoryBackendConfig }],
|
|
117
|
+
target: i0.ɵɵFactoryTarget.Injectable
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
static {
|
|
121
|
+
this.ɵprov = i0.ɵɵngDeclareInjectable({
|
|
122
|
+
minVersion: "12.0.0",
|
|
123
|
+
version: "22.2.4",
|
|
124
|
+
ngImport: i0,
|
|
125
|
+
type: DaffInMemoryCartItemService,
|
|
126
|
+
providedIn: "root"
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
131
|
+
minVersion: "12.0.0",
|
|
132
|
+
version: "22.2.4",
|
|
133
|
+
ngImport: i0,
|
|
134
|
+
type: DaffInMemoryCartItemService,
|
|
135
|
+
decorators: [{
|
|
136
|
+
type: Injectable,
|
|
137
|
+
args: [{ providedIn: "root" }]
|
|
138
|
+
}],
|
|
139
|
+
ctorParameters: () => [{ type: i1$1.HttpClient }, { type: i2$1.InMemoryBackendConfig }]
|
|
140
|
+
});
|
|
141
|
+
var DaffInMemoryCartBillingAddressService = class DaffInMemoryCartBillingAddressService extends DaffInMemoryDriverBase {
|
|
142
|
+
constructor(http, config) {
|
|
143
|
+
super(config, DAFF_CART_IN_MEMORY_CART_BILLING_ADDRESS_COLLECTION_NAME);
|
|
144
|
+
this.http = http;
|
|
145
|
+
}
|
|
146
|
+
get(cartId) {
|
|
147
|
+
return this.http.get(`${this.url}/${cartId}`);
|
|
148
|
+
}
|
|
149
|
+
update(cartId, address) {
|
|
150
|
+
return this.http.put(`${this.url}/${cartId}`, address);
|
|
151
|
+
}
|
|
152
|
+
static {
|
|
153
|
+
this.ɵfac = i0.ɵɵngDeclareFactory({
|
|
154
|
+
minVersion: "12.0.0",
|
|
155
|
+
version: "22.2.4",
|
|
156
|
+
ngImport: i0,
|
|
157
|
+
type: DaffInMemoryCartBillingAddressService,
|
|
158
|
+
deps: [{ token: i1$1.HttpClient }, { token: i2$1.InMemoryBackendConfig }],
|
|
159
|
+
target: i0.ɵɵFactoryTarget.Injectable
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
static {
|
|
163
|
+
this.ɵprov = i0.ɵɵngDeclareInjectable({
|
|
164
|
+
minVersion: "12.0.0",
|
|
165
|
+
version: "22.2.4",
|
|
166
|
+
ngImport: i0,
|
|
167
|
+
type: DaffInMemoryCartBillingAddressService,
|
|
168
|
+
providedIn: "root"
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
173
|
+
minVersion: "12.0.0",
|
|
174
|
+
version: "22.2.4",
|
|
175
|
+
ngImport: i0,
|
|
176
|
+
type: DaffInMemoryCartBillingAddressService,
|
|
177
|
+
decorators: [{
|
|
178
|
+
type: Injectable,
|
|
179
|
+
args: [{ providedIn: "root" }]
|
|
180
|
+
}],
|
|
181
|
+
ctorParameters: () => [{ type: i1$1.HttpClient }, { type: i2$1.InMemoryBackendConfig }]
|
|
182
|
+
});
|
|
183
|
+
var DaffInMemoryCartPaymentService = class DaffInMemoryCartPaymentService extends DaffInMemoryDriverBase {
|
|
184
|
+
constructor(http, config) {
|
|
185
|
+
super(config, DAFF_CART_IN_MEMORY_CART_PAYMENT_COLLECTION_NAME);
|
|
186
|
+
this.http = http;
|
|
187
|
+
}
|
|
188
|
+
get(cartId) {
|
|
189
|
+
return this.http.get(`${this.url}/${cartId}`);
|
|
190
|
+
}
|
|
191
|
+
update(cartId, payment) {
|
|
192
|
+
return this.http.put(`${this.url}/${cartId}`, { payment });
|
|
193
|
+
}
|
|
194
|
+
updateWithBilling(cartId, payment, address) {
|
|
195
|
+
return this.http.put(`${this.url}/${cartId}`, {
|
|
196
|
+
payment,
|
|
197
|
+
address
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
remove(cartId) {
|
|
201
|
+
return this.http.delete(`${this.url}/${cartId}`);
|
|
202
|
+
}
|
|
203
|
+
static {
|
|
204
|
+
this.ɵfac = i0.ɵɵngDeclareFactory({
|
|
205
|
+
minVersion: "12.0.0",
|
|
206
|
+
version: "22.2.4",
|
|
207
|
+
ngImport: i0,
|
|
208
|
+
type: DaffInMemoryCartPaymentService,
|
|
209
|
+
deps: [{ token: i1$1.HttpClient }, { token: i2$1.InMemoryBackendConfig }],
|
|
210
|
+
target: i0.ɵɵFactoryTarget.Injectable
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
static {
|
|
214
|
+
this.ɵprov = i0.ɵɵngDeclareInjectable({
|
|
215
|
+
minVersion: "12.0.0",
|
|
216
|
+
version: "22.2.4",
|
|
217
|
+
ngImport: i0,
|
|
218
|
+
type: DaffInMemoryCartPaymentService,
|
|
219
|
+
providedIn: "root"
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
};
|
|
223
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
224
|
+
minVersion: "12.0.0",
|
|
225
|
+
version: "22.2.4",
|
|
226
|
+
ngImport: i0,
|
|
227
|
+
type: DaffInMemoryCartPaymentService,
|
|
228
|
+
decorators: [{
|
|
229
|
+
type: Injectable,
|
|
230
|
+
args: [{ providedIn: "root" }]
|
|
231
|
+
}],
|
|
232
|
+
ctorParameters: () => [{ type: i1$1.HttpClient }, { type: i2$1.InMemoryBackendConfig }]
|
|
233
|
+
});
|
|
234
|
+
var DaffInMemoryCartPaymentMethodsService = class DaffInMemoryCartPaymentMethodsService extends DaffInMemoryDriverBase {
|
|
235
|
+
constructor(http, config) {
|
|
236
|
+
super(config, DAFF_CART_IN_MEMORY_CART_PAYMENT_METHODS_COLLECTION_NAME);
|
|
237
|
+
this.http = http;
|
|
238
|
+
}
|
|
239
|
+
list(cartId) {
|
|
240
|
+
return this.http.get(`${this.url}/${cartId}`);
|
|
241
|
+
}
|
|
242
|
+
static {
|
|
243
|
+
this.ɵfac = i0.ɵɵngDeclareFactory({
|
|
244
|
+
minVersion: "12.0.0",
|
|
245
|
+
version: "22.2.4",
|
|
246
|
+
ngImport: i0,
|
|
247
|
+
type: DaffInMemoryCartPaymentMethodsService,
|
|
248
|
+
deps: [{ token: i1$1.HttpClient }, { token: i2$1.InMemoryBackendConfig }],
|
|
249
|
+
target: i0.ɵɵFactoryTarget.Injectable
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
static {
|
|
253
|
+
this.ɵprov = i0.ɵɵngDeclareInjectable({
|
|
254
|
+
minVersion: "12.0.0",
|
|
255
|
+
version: "22.2.4",
|
|
256
|
+
ngImport: i0,
|
|
257
|
+
type: DaffInMemoryCartPaymentMethodsService,
|
|
258
|
+
providedIn: "root"
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
};
|
|
262
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
263
|
+
minVersion: "12.0.0",
|
|
264
|
+
version: "22.2.4",
|
|
265
|
+
ngImport: i0,
|
|
266
|
+
type: DaffInMemoryCartPaymentMethodsService,
|
|
267
|
+
decorators: [{
|
|
268
|
+
type: Injectable,
|
|
269
|
+
args: [{ providedIn: "root" }]
|
|
270
|
+
}],
|
|
271
|
+
ctorParameters: () => [{ type: i1$1.HttpClient }, { type: i2$1.InMemoryBackendConfig }]
|
|
272
|
+
});
|
|
273
|
+
var DaffInMemoryCartShippingAddressService = class DaffInMemoryCartShippingAddressService extends DaffInMemoryDriverBase {
|
|
274
|
+
constructor(http, config) {
|
|
275
|
+
super(config, DAFF_CART_IN_MEMORY_CART_SHIPPING_ADDRESS_COLLECTION_NAME);
|
|
276
|
+
this.http = http;
|
|
277
|
+
}
|
|
278
|
+
get(cartId) {
|
|
279
|
+
return this.http.get(`${this.url}/${cartId}`);
|
|
280
|
+
}
|
|
281
|
+
update(cartId, address) {
|
|
282
|
+
return this.http.put(`${this.url}/${cartId}`, address);
|
|
283
|
+
}
|
|
284
|
+
static {
|
|
285
|
+
this.ɵfac = i0.ɵɵngDeclareFactory({
|
|
286
|
+
minVersion: "12.0.0",
|
|
287
|
+
version: "22.2.4",
|
|
288
|
+
ngImport: i0,
|
|
289
|
+
type: DaffInMemoryCartShippingAddressService,
|
|
290
|
+
deps: [{ token: i1$1.HttpClient }, { token: i2$1.InMemoryBackendConfig }],
|
|
291
|
+
target: i0.ɵɵFactoryTarget.Injectable
|
|
292
|
+
});
|
|
293
|
+
}
|
|
294
|
+
static {
|
|
295
|
+
this.ɵprov = i0.ɵɵngDeclareInjectable({
|
|
296
|
+
minVersion: "12.0.0",
|
|
297
|
+
version: "22.2.4",
|
|
298
|
+
ngImport: i0,
|
|
299
|
+
type: DaffInMemoryCartShippingAddressService,
|
|
300
|
+
providedIn: "root"
|
|
301
|
+
});
|
|
302
|
+
}
|
|
303
|
+
};
|
|
304
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
305
|
+
minVersion: "12.0.0",
|
|
306
|
+
version: "22.2.4",
|
|
307
|
+
ngImport: i0,
|
|
308
|
+
type: DaffInMemoryCartShippingAddressService,
|
|
309
|
+
decorators: [{
|
|
310
|
+
type: Injectable,
|
|
311
|
+
args: [{ providedIn: "root" }]
|
|
312
|
+
}],
|
|
313
|
+
ctorParameters: () => [{ type: i1$1.HttpClient }, { type: i2$1.InMemoryBackendConfig }]
|
|
314
|
+
});
|
|
315
|
+
var DaffInMemoryCartShippingInformationService = class DaffInMemoryCartShippingInformationService extends DaffInMemoryDriverBase {
|
|
316
|
+
constructor(http, config) {
|
|
317
|
+
super(config, DAFF_CART_IN_MEMORY_CART_SHIPPING_COLLECTION_NAME);
|
|
318
|
+
this.http = http;
|
|
319
|
+
}
|
|
320
|
+
get(cartId) {
|
|
321
|
+
return this.http.get(`${this.url}/${cartId}`);
|
|
322
|
+
}
|
|
323
|
+
update(cartId, info) {
|
|
324
|
+
return this.http.put(`${this.url}/${cartId}`, info);
|
|
325
|
+
}
|
|
326
|
+
delete(cartId) {
|
|
327
|
+
return this.http.delete(`${this.url}/${cartId}`);
|
|
328
|
+
}
|
|
329
|
+
static {
|
|
330
|
+
this.ɵfac = i0.ɵɵngDeclareFactory({
|
|
331
|
+
minVersion: "12.0.0",
|
|
332
|
+
version: "22.2.4",
|
|
333
|
+
ngImport: i0,
|
|
334
|
+
type: DaffInMemoryCartShippingInformationService,
|
|
335
|
+
deps: [{ token: i1$1.HttpClient }, { token: i2$1.InMemoryBackendConfig }],
|
|
336
|
+
target: i0.ɵɵFactoryTarget.Injectable
|
|
337
|
+
});
|
|
338
|
+
}
|
|
339
|
+
static {
|
|
340
|
+
this.ɵprov = i0.ɵɵngDeclareInjectable({
|
|
341
|
+
minVersion: "12.0.0",
|
|
342
|
+
version: "22.2.4",
|
|
343
|
+
ngImport: i0,
|
|
344
|
+
type: DaffInMemoryCartShippingInformationService,
|
|
345
|
+
providedIn: "root"
|
|
346
|
+
});
|
|
347
|
+
}
|
|
348
|
+
};
|
|
349
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
350
|
+
minVersion: "12.0.0",
|
|
351
|
+
version: "22.2.4",
|
|
352
|
+
ngImport: i0,
|
|
353
|
+
type: DaffInMemoryCartShippingInformationService,
|
|
354
|
+
decorators: [{
|
|
355
|
+
type: Injectable,
|
|
356
|
+
args: [{ providedIn: "root" }]
|
|
357
|
+
}],
|
|
358
|
+
ctorParameters: () => [{ type: i1$1.HttpClient }, { type: i2$1.InMemoryBackendConfig }]
|
|
359
|
+
});
|
|
360
|
+
var DaffInMemoryCartShippingMethodsService = class DaffInMemoryCartShippingMethodsService extends DaffInMemoryDriverBase {
|
|
361
|
+
constructor(http, config) {
|
|
362
|
+
super(config, DAFF_CART_IN_MEMORY_CART_SHIPPING_METHODS_COLLECTION_NAME);
|
|
363
|
+
this.http = http;
|
|
364
|
+
}
|
|
365
|
+
list(cartId) {
|
|
366
|
+
return this.http.get(`${this.url}/${cartId}`);
|
|
367
|
+
}
|
|
368
|
+
static {
|
|
369
|
+
this.ɵfac = i0.ɵɵngDeclareFactory({
|
|
370
|
+
minVersion: "12.0.0",
|
|
371
|
+
version: "22.2.4",
|
|
372
|
+
ngImport: i0,
|
|
373
|
+
type: DaffInMemoryCartShippingMethodsService,
|
|
374
|
+
deps: [{ token: i1$1.HttpClient }, { token: i2$1.InMemoryBackendConfig }],
|
|
375
|
+
target: i0.ɵɵFactoryTarget.Injectable
|
|
376
|
+
});
|
|
377
|
+
}
|
|
378
|
+
static {
|
|
379
|
+
this.ɵprov = i0.ɵɵngDeclareInjectable({
|
|
380
|
+
minVersion: "12.0.0",
|
|
381
|
+
version: "22.2.4",
|
|
382
|
+
ngImport: i0,
|
|
383
|
+
type: DaffInMemoryCartShippingMethodsService,
|
|
384
|
+
providedIn: "root"
|
|
385
|
+
});
|
|
386
|
+
}
|
|
387
|
+
};
|
|
388
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
389
|
+
minVersion: "12.0.0",
|
|
390
|
+
version: "22.2.4",
|
|
391
|
+
ngImport: i0,
|
|
392
|
+
type: DaffInMemoryCartShippingMethodsService,
|
|
393
|
+
decorators: [{
|
|
394
|
+
type: Injectable,
|
|
395
|
+
args: [{ providedIn: "root" }]
|
|
396
|
+
}],
|
|
397
|
+
ctorParameters: () => [{ type: i1$1.HttpClient }, { type: i2$1.InMemoryBackendConfig }]
|
|
398
|
+
});
|
|
399
|
+
var DaffInMemoryCartOrderService = class DaffInMemoryCartOrderService extends DaffInMemoryDriverBase {
|
|
400
|
+
constructor(http, config) {
|
|
401
|
+
super(config, DAFF_CART_IN_MEMORY_CART_ORDER_COLLECTION_NAME);
|
|
402
|
+
this.http = http;
|
|
403
|
+
}
|
|
404
|
+
placeOrder(cartId, payment) {
|
|
405
|
+
return this.http.post(`${this.url}/${cartId}/`, { payment });
|
|
406
|
+
}
|
|
407
|
+
static {
|
|
408
|
+
this.ɵfac = i0.ɵɵngDeclareFactory({
|
|
409
|
+
minVersion: "12.0.0",
|
|
410
|
+
version: "22.2.4",
|
|
411
|
+
ngImport: i0,
|
|
412
|
+
type: DaffInMemoryCartOrderService,
|
|
413
|
+
deps: [{ token: i1$1.HttpClient }, { token: i2$1.InMemoryBackendConfig }],
|
|
414
|
+
target: i0.ɵɵFactoryTarget.Injectable
|
|
415
|
+
});
|
|
416
|
+
}
|
|
417
|
+
static {
|
|
418
|
+
this.ɵprov = i0.ɵɵngDeclareInjectable({
|
|
419
|
+
minVersion: "12.0.0",
|
|
420
|
+
version: "22.2.4",
|
|
421
|
+
ngImport: i0,
|
|
422
|
+
type: DaffInMemoryCartOrderService,
|
|
423
|
+
providedIn: "root"
|
|
424
|
+
});
|
|
425
|
+
}
|
|
426
|
+
};
|
|
427
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
428
|
+
minVersion: "12.0.0",
|
|
429
|
+
version: "22.2.4",
|
|
430
|
+
ngImport: i0,
|
|
431
|
+
type: DaffInMemoryCartOrderService,
|
|
432
|
+
decorators: [{
|
|
433
|
+
type: Injectable,
|
|
434
|
+
args: [{ providedIn: "root" }]
|
|
435
|
+
}],
|
|
436
|
+
ctorParameters: () => [{ type: i1$1.HttpClient }, { type: i2$1.InMemoryBackendConfig }]
|
|
437
|
+
});
|
|
438
|
+
var DaffInMemoryCartCouponService = class DaffInMemoryCartCouponService extends DaffInMemoryDriverBase {
|
|
439
|
+
constructor(http, config) {
|
|
440
|
+
super(config, DAFF_CART_IN_MEMORY_CART_COUPON_COLLECTION_NAME);
|
|
441
|
+
this.http = http;
|
|
442
|
+
}
|
|
443
|
+
list(cartId) {
|
|
444
|
+
return this.http.get(`${this.url}/${cartId}/`);
|
|
445
|
+
}
|
|
446
|
+
apply(cartId, coupon) {
|
|
447
|
+
return this.http.post(`${this.url}/${cartId}/`, coupon);
|
|
448
|
+
}
|
|
449
|
+
remove(cartId, coupon) {
|
|
450
|
+
return this.http.delete(`${this.url}/${cartId}/${coupon.code}`);
|
|
451
|
+
}
|
|
452
|
+
removeAll(cartId) {
|
|
453
|
+
return this.http.delete(`${this.url}/${cartId}/`);
|
|
454
|
+
}
|
|
455
|
+
static {
|
|
456
|
+
this.ɵfac = i0.ɵɵngDeclareFactory({
|
|
457
|
+
minVersion: "12.0.0",
|
|
458
|
+
version: "22.2.4",
|
|
459
|
+
ngImport: i0,
|
|
460
|
+
type: DaffInMemoryCartCouponService,
|
|
461
|
+
deps: [{ token: i1$1.HttpClient }, { token: i2$1.InMemoryBackendConfig }],
|
|
462
|
+
target: i0.ɵɵFactoryTarget.Injectable
|
|
463
|
+
});
|
|
464
|
+
}
|
|
465
|
+
static {
|
|
466
|
+
this.ɵprov = i0.ɵɵngDeclareInjectable({
|
|
467
|
+
minVersion: "12.0.0",
|
|
468
|
+
version: "22.2.4",
|
|
469
|
+
ngImport: i0,
|
|
470
|
+
type: DaffInMemoryCartCouponService,
|
|
471
|
+
providedIn: "root"
|
|
472
|
+
});
|
|
473
|
+
}
|
|
474
|
+
};
|
|
475
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
476
|
+
minVersion: "12.0.0",
|
|
477
|
+
version: "22.2.4",
|
|
478
|
+
ngImport: i0,
|
|
479
|
+
type: DaffInMemoryCartCouponService,
|
|
480
|
+
decorators: [{
|
|
481
|
+
type: Injectable,
|
|
482
|
+
args: [{ providedIn: "root" }]
|
|
483
|
+
}],
|
|
484
|
+
ctorParameters: () => [{ type: i1$1.HttpClient }, { type: i2$1.InMemoryBackendConfig }]
|
|
485
|
+
});
|
|
486
|
+
var DaffInMemoryCartAddressService = class DaffInMemoryCartAddressService extends DaffInMemoryDriverBase {
|
|
487
|
+
constructor(http, config) {
|
|
488
|
+
super(config, DAFF_CART_IN_MEMORY_CART_ADDRESS_COLLECTION_NAME);
|
|
489
|
+
this.http = http;
|
|
490
|
+
}
|
|
491
|
+
update(cartId, address) {
|
|
492
|
+
return this.http.put(`${this.url}/${cartId}`, address);
|
|
493
|
+
}
|
|
494
|
+
static {
|
|
495
|
+
this.ɵfac = i0.ɵɵngDeclareFactory({
|
|
496
|
+
minVersion: "12.0.0",
|
|
497
|
+
version: "22.2.4",
|
|
498
|
+
ngImport: i0,
|
|
499
|
+
type: DaffInMemoryCartAddressService,
|
|
500
|
+
deps: [{ token: i1$1.HttpClient }, { token: i2$1.InMemoryBackendConfig }],
|
|
501
|
+
target: i0.ɵɵFactoryTarget.Injectable
|
|
502
|
+
});
|
|
503
|
+
}
|
|
504
|
+
static {
|
|
505
|
+
this.ɵprov = i0.ɵɵngDeclareInjectable({
|
|
506
|
+
minVersion: "12.0.0",
|
|
507
|
+
version: "22.2.4",
|
|
508
|
+
ngImport: i0,
|
|
509
|
+
type: DaffInMemoryCartAddressService,
|
|
510
|
+
providedIn: "root"
|
|
511
|
+
});
|
|
512
|
+
}
|
|
513
|
+
};
|
|
514
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
515
|
+
minVersion: "12.0.0",
|
|
516
|
+
version: "22.2.4",
|
|
517
|
+
ngImport: i0,
|
|
518
|
+
type: DaffInMemoryCartAddressService,
|
|
519
|
+
decorators: [{
|
|
520
|
+
type: Injectable,
|
|
521
|
+
args: [{ providedIn: "root" }]
|
|
522
|
+
}],
|
|
523
|
+
ctorParameters: () => [{ type: i1$1.HttpClient }, { type: i2$1.InMemoryBackendConfig }]
|
|
524
|
+
});
|
|
323
525
|
function daffCartInMemoryComputeCartTotals(cart, products) {
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
* frontend would expect from the production platform.
|
|
372
|
-
*
|
|
373
|
-
* The value returned by the hook function will be set to the returned cart's `extra_attributes` field
|
|
374
|
-
* for driver calls that return a cart.
|
|
375
|
-
*
|
|
376
|
-
* Note that this and any `extra_attributes` features are for advanced users
|
|
377
|
-
* and should be used with care.
|
|
378
|
-
*
|
|
379
|
-
* @example Adding the `numberOfCartItems` field to `extra_attributes`
|
|
380
|
-
* ```ts
|
|
381
|
-
* (reqInfo: RequestInfo, cart: DaffCart) => ({
|
|
382
|
-
* numberOfCartItems: cart.items.length
|
|
383
|
-
* })
|
|
384
|
-
* ```
|
|
385
|
-
*/
|
|
386
|
-
token: DAFF_CART_IN_MEMORY_EXTRA_ATTRIBUTES_HOOK,
|
|
387
|
-
/**
|
|
388
|
-
* Provider function for {@link DAFF_CART_IN_MEMORY_EXTRA_ATTRIBUTES_HOOK}.
|
|
389
|
-
*/
|
|
390
|
-
provider: provideDaffCartInMemoryExtraAttributesHook, } = createSingleInjectionToken('DAFF_CART_IN_MEMORY_EXTRA_ATTRIBUTES_HOOK', { factory: () => (reqInfo, cart) => ({}) });
|
|
391
|
-
|
|
392
|
-
/**
|
|
393
|
-
* @inheritdoc
|
|
394
|
-
*/
|
|
395
|
-
class DaffInMemoryBackendCartService {
|
|
396
|
-
constructor(cartFactory, extraFieldsHook, productBackend) {
|
|
397
|
-
this.cartFactory = cartFactory;
|
|
398
|
-
this.extraFieldsHook = extraFieldsHook;
|
|
399
|
-
this.productBackend = productBackend;
|
|
400
|
-
this.collectionName = DAFF_CART_IN_MEMORY_CART_COLLECTION_NAME;
|
|
401
|
-
}
|
|
402
|
-
get(reqInfo) {
|
|
403
|
-
return reqInfo.utils.createResponse$(() => this.getCart(reqInfo));
|
|
404
|
-
}
|
|
405
|
-
post(reqInfo) {
|
|
406
|
-
return reqInfo.utils.createResponse$(() => {
|
|
407
|
-
let ret;
|
|
408
|
-
const action = this.getAction(reqInfo);
|
|
409
|
-
if (reqInfo.id === 'addToCart') {
|
|
410
|
-
// deprecated
|
|
411
|
-
ret = {
|
|
412
|
-
body: {},
|
|
413
|
-
status: STATUS.OK,
|
|
414
|
-
};
|
|
415
|
-
}
|
|
416
|
-
else if (action === 'clear') {
|
|
417
|
-
ret = this.clear(reqInfo);
|
|
418
|
-
}
|
|
419
|
-
else if (action === 'merge') {
|
|
420
|
-
ret = this.merge(reqInfo);
|
|
421
|
-
}
|
|
422
|
-
else {
|
|
423
|
-
ret = this.create(reqInfo);
|
|
424
|
-
}
|
|
425
|
-
return ret;
|
|
426
|
-
});
|
|
427
|
-
}
|
|
428
|
-
/**
|
|
429
|
-
* Gets whatever follows the cart ID section of the request URL.
|
|
430
|
-
*/
|
|
431
|
-
getAction(reqInfo) {
|
|
432
|
-
return reqInfo.url.replace(`/${reqInfo.resourceUrl}${reqInfo.id}/`, '');
|
|
433
|
-
}
|
|
434
|
-
clear(reqInfo) {
|
|
435
|
-
const cart = this.getCart(reqInfo).body;
|
|
436
|
-
cart.items = [];
|
|
437
|
-
return {
|
|
438
|
-
body: {
|
|
439
|
-
...cart,
|
|
440
|
-
extra_attributes: this.extraFieldsHook(reqInfo, cart),
|
|
441
|
-
},
|
|
442
|
-
status: STATUS.OK,
|
|
443
|
-
};
|
|
444
|
-
}
|
|
445
|
-
create(reqInfo) {
|
|
446
|
-
const cart = this.cartFactory.create();
|
|
447
|
-
reqInfo.collection.push(cart);
|
|
448
|
-
return {
|
|
449
|
-
body: {
|
|
450
|
-
id: cart.id,
|
|
451
|
-
},
|
|
452
|
-
status: STATUS.OK,
|
|
453
|
-
};
|
|
454
|
-
}
|
|
455
|
-
merge(reqInfo) {
|
|
456
|
-
const { source, destination, } = reqInfo.utils.getJsonBody(reqInfo.req);
|
|
457
|
-
const sourceCart = reqInfo.utils.findById(reqInfo.collection, source);
|
|
458
|
-
if (!sourceCart) {
|
|
459
|
-
return {
|
|
460
|
-
status: STATUS.NOT_FOUND,
|
|
461
|
-
};
|
|
462
|
-
}
|
|
463
|
-
const destinationCart = reqInfo.utils.findById(reqInfo.collection, destination ? destination : this.create(reqInfo).body.id);
|
|
464
|
-
if (!destinationCart) {
|
|
465
|
-
return {
|
|
466
|
-
status: STATUS.NOT_FOUND,
|
|
467
|
-
};
|
|
468
|
-
}
|
|
469
|
-
destinationCart.items.push(...sourceCart.items);
|
|
470
|
-
reqInfo.collection.push(destinationCart);
|
|
471
|
-
return {
|
|
472
|
-
body: {
|
|
473
|
-
...destinationCart,
|
|
474
|
-
extra_attributes: this.extraFieldsHook(reqInfo, destinationCart),
|
|
475
|
-
},
|
|
476
|
-
status: STATUS.OK,
|
|
477
|
-
};
|
|
478
|
-
}
|
|
479
|
-
getCart(reqInfo) {
|
|
480
|
-
const cart = reqInfo.utils.findById(reqInfo.collection, reqInfo.id);
|
|
481
|
-
return cart
|
|
482
|
-
? {
|
|
483
|
-
body: {
|
|
484
|
-
...daffCartInMemoryComputeCartTotals(cart, this.productBackend.products),
|
|
485
|
-
extra_attributes: this.extraFieldsHook(reqInfo, cart),
|
|
486
|
-
},
|
|
487
|
-
status: STATUS.OK,
|
|
488
|
-
}
|
|
489
|
-
: {
|
|
490
|
-
status: STATUS.NOT_FOUND,
|
|
491
|
-
};
|
|
492
|
-
}
|
|
493
|
-
/** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: DaffInMemoryBackendCartService, deps: [{ token: i1$1.DaffCartFactory }, { token: DAFF_CART_IN_MEMORY_EXTRA_ATTRIBUTES_HOOK }, { token: i2$1.DaffInMemoryBackendProductService }], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
494
|
-
/** @nocollapse */ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: DaffInMemoryBackendCartService, providedIn: 'root' }); }
|
|
526
|
+
const shipping = cart.shipping_information ? faker.number.int({
|
|
527
|
+
min: 0,
|
|
528
|
+
max: 99
|
|
529
|
+
}) : 0;
|
|
530
|
+
const subtotalExcludingTax = cart.items?.reduce((acc, { product_id }) => acc + (products.find(({ id }) => id === product_id)?.price || 0), 0) || 0;
|
|
531
|
+
const discount = faker.number.int({
|
|
532
|
+
min: 0,
|
|
533
|
+
max: subtotalExcludingTax
|
|
534
|
+
});
|
|
535
|
+
const subtotalIncludingTax = subtotalExcludingTax + cart.totals[DaffCartTotalTypeEnum.tax].value;
|
|
536
|
+
const subtotalWithDiscountExcludingTax = subtotalExcludingTax - discount;
|
|
537
|
+
const subtotalWithDiscountIncludingTax = subtotalIncludingTax - discount;
|
|
538
|
+
const grandTotal = subtotalWithDiscountIncludingTax + shipping;
|
|
539
|
+
return {
|
|
540
|
+
...cart,
|
|
541
|
+
totals: {
|
|
542
|
+
...cart.totals,
|
|
543
|
+
[DaffCartTotalTypeEnum.shipping]: {
|
|
544
|
+
...cart.totals[DaffCartTotalTypeEnum.shipping],
|
|
545
|
+
value: shipping
|
|
546
|
+
},
|
|
547
|
+
[DaffCartTotalTypeEnum.subtotalExcludingTax]: {
|
|
548
|
+
...cart.totals[DaffCartTotalTypeEnum.subtotalExcludingTax],
|
|
549
|
+
value: subtotalExcludingTax
|
|
550
|
+
},
|
|
551
|
+
[DaffCartTotalTypeEnum.discount]: {
|
|
552
|
+
...cart.totals[DaffCartTotalTypeEnum.discount],
|
|
553
|
+
value: discount
|
|
554
|
+
},
|
|
555
|
+
[DaffCartTotalTypeEnum.subtotalIncludingTax]: {
|
|
556
|
+
...cart.totals[DaffCartTotalTypeEnum.subtotalIncludingTax],
|
|
557
|
+
value: subtotalIncludingTax
|
|
558
|
+
},
|
|
559
|
+
[DaffCartTotalTypeEnum.subtotalWithDiscountExcludingTax]: {
|
|
560
|
+
...cart.totals[DaffCartTotalTypeEnum.subtotalWithDiscountExcludingTax],
|
|
561
|
+
value: subtotalWithDiscountExcludingTax
|
|
562
|
+
},
|
|
563
|
+
[DaffCartTotalTypeEnum.subtotalWithDiscountIncludingTax]: {
|
|
564
|
+
...cart.totals[DaffCartTotalTypeEnum.subtotalWithDiscountIncludingTax],
|
|
565
|
+
value: subtotalWithDiscountIncludingTax
|
|
566
|
+
},
|
|
567
|
+
[DaffCartTotalTypeEnum.grandTotal]: {
|
|
568
|
+
...cart.totals[DaffCartTotalTypeEnum.grandTotal],
|
|
569
|
+
value: grandTotal
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
};
|
|
495
573
|
}
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
i0.ɵɵ
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
574
|
+
const { token: DAFF_CART_IN_MEMORY_EXTRA_ATTRIBUTES_HOOK, provider: provideDaffCartInMemoryExtraAttributesHook } = createSingleInjectionToken("DAFF_CART_IN_MEMORY_EXTRA_ATTRIBUTES_HOOK", { factory: () => (reqInfo, cart) => ({}) });
|
|
575
|
+
var DaffInMemoryBackendCartService = class DaffInMemoryBackendCartService {
|
|
576
|
+
constructor(cartFactory, extraFieldsHook, productBackend) {
|
|
577
|
+
this.cartFactory = cartFactory;
|
|
578
|
+
this.extraFieldsHook = extraFieldsHook;
|
|
579
|
+
this.productBackend = productBackend;
|
|
580
|
+
this.collectionName = DAFF_CART_IN_MEMORY_CART_COLLECTION_NAME;
|
|
581
|
+
}
|
|
582
|
+
get(reqInfo) {
|
|
583
|
+
return reqInfo.utils.createResponse$(() => this.getCart(reqInfo));
|
|
584
|
+
}
|
|
585
|
+
post(reqInfo) {
|
|
586
|
+
return reqInfo.utils.createResponse$(() => {
|
|
587
|
+
let ret;
|
|
588
|
+
const action = this.getAction(reqInfo);
|
|
589
|
+
if (reqInfo.id === "addToCart") ret = {
|
|
590
|
+
body: {},
|
|
591
|
+
status: STATUS.OK
|
|
592
|
+
};
|
|
593
|
+
else if (action === "clear") ret = this.clear(reqInfo);
|
|
594
|
+
else if (action === "merge") ret = this.merge(reqInfo);
|
|
595
|
+
else ret = this.create(reqInfo);
|
|
596
|
+
return ret;
|
|
597
|
+
});
|
|
598
|
+
}
|
|
599
|
+
getAction(reqInfo) {
|
|
600
|
+
return reqInfo.url.replace(`/${reqInfo.resourceUrl}${reqInfo.id}/`, "");
|
|
601
|
+
}
|
|
602
|
+
clear(reqInfo) {
|
|
603
|
+
const cart = this.getCart(reqInfo).body;
|
|
604
|
+
cart.items = [];
|
|
605
|
+
return {
|
|
606
|
+
body: {
|
|
607
|
+
...cart,
|
|
608
|
+
extra_attributes: this.extraFieldsHook(reqInfo, cart)
|
|
609
|
+
},
|
|
610
|
+
status: STATUS.OK
|
|
611
|
+
};
|
|
612
|
+
}
|
|
613
|
+
create(reqInfo) {
|
|
614
|
+
const cart = this.cartFactory.create();
|
|
615
|
+
reqInfo.collection.push(cart);
|
|
616
|
+
return {
|
|
617
|
+
body: { id: cart.id },
|
|
618
|
+
status: STATUS.OK
|
|
619
|
+
};
|
|
620
|
+
}
|
|
621
|
+
merge(reqInfo) {
|
|
622
|
+
const { source, destination } = reqInfo.utils.getJsonBody(reqInfo.req);
|
|
623
|
+
const sourceCart = reqInfo.utils.findById(reqInfo.collection, source);
|
|
624
|
+
if (!sourceCart) return { status: STATUS.NOT_FOUND };
|
|
625
|
+
const destinationCart = reqInfo.utils.findById(reqInfo.collection, destination ? destination : this.create(reqInfo).body.id);
|
|
626
|
+
if (!destinationCart) return { status: STATUS.NOT_FOUND };
|
|
627
|
+
destinationCart.items.push(...sourceCart.items);
|
|
628
|
+
reqInfo.collection.push(destinationCart);
|
|
629
|
+
return {
|
|
630
|
+
body: {
|
|
631
|
+
...destinationCart,
|
|
632
|
+
extra_attributes: this.extraFieldsHook(reqInfo, destinationCart)
|
|
633
|
+
},
|
|
634
|
+
status: STATUS.OK
|
|
635
|
+
};
|
|
636
|
+
}
|
|
637
|
+
getCart(reqInfo) {
|
|
638
|
+
const cart = reqInfo.utils.findById(reqInfo.collection, reqInfo.id);
|
|
639
|
+
return cart ? {
|
|
640
|
+
body: {
|
|
641
|
+
...daffCartInMemoryComputeCartTotals(cart, this.productBackend.products),
|
|
642
|
+
extra_attributes: this.extraFieldsHook(reqInfo, cart)
|
|
643
|
+
},
|
|
644
|
+
status: STATUS.OK
|
|
645
|
+
} : { status: STATUS.NOT_FOUND };
|
|
646
|
+
}
|
|
647
|
+
static {
|
|
648
|
+
this.ɵfac = i0.ɵɵngDeclareFactory({
|
|
649
|
+
minVersion: "12.0.0",
|
|
650
|
+
version: "22.2.4",
|
|
651
|
+
ngImport: i0,
|
|
652
|
+
type: DaffInMemoryBackendCartService,
|
|
653
|
+
deps: [
|
|
654
|
+
{ token: i1.DaffCartFactory },
|
|
655
|
+
{ token: DAFF_CART_IN_MEMORY_EXTRA_ATTRIBUTES_HOOK },
|
|
656
|
+
{ token: i2.DaffInMemoryBackendProductService }
|
|
657
|
+
],
|
|
658
|
+
target: i0.ɵɵFactoryTarget.Injectable
|
|
659
|
+
});
|
|
660
|
+
}
|
|
661
|
+
static {
|
|
662
|
+
this.ɵprov = i0.ɵɵngDeclareInjectable({
|
|
663
|
+
minVersion: "12.0.0",
|
|
664
|
+
version: "22.2.4",
|
|
665
|
+
ngImport: i0,
|
|
666
|
+
type: DaffInMemoryBackendCartService,
|
|
667
|
+
providedIn: "root"
|
|
668
|
+
});
|
|
669
|
+
}
|
|
670
|
+
};
|
|
671
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
672
|
+
minVersion: "12.0.0",
|
|
673
|
+
version: "22.2.4",
|
|
674
|
+
ngImport: i0,
|
|
675
|
+
type: DaffInMemoryBackendCartService,
|
|
676
|
+
decorators: [{
|
|
677
|
+
type: Injectable,
|
|
678
|
+
args: [{ providedIn: "root" }]
|
|
679
|
+
}],
|
|
680
|
+
ctorParameters: () => [
|
|
681
|
+
{ type: i1.DaffCartFactory },
|
|
682
|
+
{
|
|
683
|
+
type: void 0,
|
|
684
|
+
decorators: [{
|
|
685
|
+
type: Inject,
|
|
686
|
+
args: [DAFF_CART_IN_MEMORY_EXTRA_ATTRIBUTES_HOOK]
|
|
687
|
+
}]
|
|
688
|
+
},
|
|
689
|
+
{ type: i2.DaffInMemoryBackendProductService }
|
|
690
|
+
]
|
|
691
|
+
});
|
|
692
|
+
var DaffInMemoryBackendCartAddressService = class DaffInMemoryBackendCartAddressService {
|
|
693
|
+
constructor(extraFieldsHook) {
|
|
694
|
+
this.extraFieldsHook = extraFieldsHook;
|
|
695
|
+
this.collectionName = DAFF_CART_IN_MEMORY_CART_ADDRESS_COLLECTION_NAME;
|
|
696
|
+
}
|
|
697
|
+
put(reqInfo) {
|
|
698
|
+
return reqInfo.utils.createResponse$(() => ({
|
|
699
|
+
body: this.updateAddress(reqInfo),
|
|
700
|
+
status: STATUS.OK
|
|
701
|
+
}));
|
|
702
|
+
}
|
|
703
|
+
getCart(reqInfo) {
|
|
704
|
+
return reqInfo.utils.findById(reqInfo.collection, reqInfo.id);
|
|
705
|
+
}
|
|
706
|
+
updateAddress(reqInfo) {
|
|
707
|
+
const cart = this.getCart(reqInfo);
|
|
708
|
+
const address = reqInfo.utils.getJsonBody(reqInfo.req);
|
|
709
|
+
cart.billing_address = address;
|
|
710
|
+
cart.shipping_address = address;
|
|
711
|
+
return {
|
|
712
|
+
...cart,
|
|
713
|
+
extra_attributes: this.extraFieldsHook(reqInfo, cart)
|
|
714
|
+
};
|
|
715
|
+
}
|
|
716
|
+
static {
|
|
717
|
+
this.ɵfac = i0.ɵɵngDeclareFactory({
|
|
718
|
+
minVersion: "12.0.0",
|
|
719
|
+
version: "22.2.4",
|
|
720
|
+
ngImport: i0,
|
|
721
|
+
type: DaffInMemoryBackendCartAddressService,
|
|
722
|
+
deps: [{ token: DAFF_CART_IN_MEMORY_EXTRA_ATTRIBUTES_HOOK }],
|
|
723
|
+
target: i0.ɵɵFactoryTarget.Injectable
|
|
724
|
+
});
|
|
725
|
+
}
|
|
726
|
+
static {
|
|
727
|
+
this.ɵprov = i0.ɵɵngDeclareInjectable({
|
|
728
|
+
minVersion: "12.0.0",
|
|
729
|
+
version: "22.2.4",
|
|
730
|
+
ngImport: i0,
|
|
731
|
+
type: DaffInMemoryBackendCartAddressService,
|
|
732
|
+
providedIn: "root"
|
|
733
|
+
});
|
|
734
|
+
}
|
|
735
|
+
};
|
|
736
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
737
|
+
minVersion: "12.0.0",
|
|
738
|
+
version: "22.2.4",
|
|
739
|
+
ngImport: i0,
|
|
740
|
+
type: DaffInMemoryBackendCartAddressService,
|
|
741
|
+
decorators: [{
|
|
742
|
+
type: Injectable,
|
|
743
|
+
args: [{ providedIn: "root" }]
|
|
744
|
+
}],
|
|
745
|
+
ctorParameters: () => [{
|
|
746
|
+
type: void 0,
|
|
747
|
+
decorators: [{
|
|
748
|
+
type: Inject,
|
|
749
|
+
args: [DAFF_CART_IN_MEMORY_EXTRA_ATTRIBUTES_HOOK]
|
|
750
|
+
}]
|
|
751
|
+
}]
|
|
752
|
+
});
|
|
753
|
+
var DaffInMemoryBackendCartBillingAddressService = class DaffInMemoryBackendCartBillingAddressService {
|
|
754
|
+
constructor(extraFieldsHook) {
|
|
755
|
+
this.extraFieldsHook = extraFieldsHook;
|
|
756
|
+
this.collectionName = DAFF_CART_IN_MEMORY_CART_BILLING_ADDRESS_COLLECTION_NAME;
|
|
757
|
+
}
|
|
758
|
+
get(reqInfo) {
|
|
759
|
+
return reqInfo.utils.createResponse$(() => ({
|
|
760
|
+
body: this.getBillingAddress(reqInfo),
|
|
761
|
+
status: STATUS.OK
|
|
762
|
+
}));
|
|
763
|
+
}
|
|
764
|
+
put(reqInfo) {
|
|
765
|
+
return reqInfo.utils.createResponse$(() => ({
|
|
766
|
+
body: this.updateBillingAddress(reqInfo),
|
|
767
|
+
status: STATUS.OK
|
|
768
|
+
}));
|
|
769
|
+
}
|
|
770
|
+
getCart(reqInfo) {
|
|
771
|
+
return reqInfo.utils.findById(reqInfo.collection, reqInfo.id);
|
|
772
|
+
}
|
|
773
|
+
getBillingAddress(reqInfo) {
|
|
774
|
+
return this.getCart(reqInfo).billing_address;
|
|
775
|
+
}
|
|
776
|
+
updateBillingAddress(reqInfo) {
|
|
777
|
+
const cart = this.getCart(reqInfo);
|
|
778
|
+
cart.billing_address = reqInfo.utils.getJsonBody(reqInfo.req);
|
|
779
|
+
return {
|
|
780
|
+
...cart,
|
|
781
|
+
extra_attributes: this.extraFieldsHook(reqInfo, cart)
|
|
782
|
+
};
|
|
783
|
+
}
|
|
784
|
+
static {
|
|
785
|
+
this.ɵfac = i0.ɵɵngDeclareFactory({
|
|
786
|
+
minVersion: "12.0.0",
|
|
787
|
+
version: "22.2.4",
|
|
788
|
+
ngImport: i0,
|
|
789
|
+
type: DaffInMemoryBackendCartBillingAddressService,
|
|
790
|
+
deps: [{ token: DAFF_CART_IN_MEMORY_EXTRA_ATTRIBUTES_HOOK }],
|
|
791
|
+
target: i0.ɵɵFactoryTarget.Injectable
|
|
792
|
+
});
|
|
793
|
+
}
|
|
794
|
+
static {
|
|
795
|
+
this.ɵprov = i0.ɵɵngDeclareInjectable({
|
|
796
|
+
minVersion: "12.0.0",
|
|
797
|
+
version: "22.2.4",
|
|
798
|
+
ngImport: i0,
|
|
799
|
+
type: DaffInMemoryBackendCartBillingAddressService,
|
|
800
|
+
providedIn: "root"
|
|
801
|
+
});
|
|
802
|
+
}
|
|
803
|
+
};
|
|
804
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
805
|
+
minVersion: "12.0.0",
|
|
806
|
+
version: "22.2.4",
|
|
807
|
+
ngImport: i0,
|
|
808
|
+
type: DaffInMemoryBackendCartBillingAddressService,
|
|
809
|
+
decorators: [{
|
|
810
|
+
type: Injectable,
|
|
811
|
+
args: [{ providedIn: "root" }]
|
|
812
|
+
}],
|
|
813
|
+
ctorParameters: () => [{
|
|
814
|
+
type: void 0,
|
|
815
|
+
decorators: [{
|
|
816
|
+
type: Inject,
|
|
817
|
+
args: [DAFF_CART_IN_MEMORY_EXTRA_ATTRIBUTES_HOOK]
|
|
818
|
+
}]
|
|
819
|
+
}]
|
|
820
|
+
});
|
|
821
|
+
var DaffInMemoryBackendCartCouponService = class DaffInMemoryBackendCartCouponService {
|
|
822
|
+
constructor(extraFieldsHook) {
|
|
823
|
+
this.extraFieldsHook = extraFieldsHook;
|
|
824
|
+
this.collectionName = DAFF_CART_IN_MEMORY_CART_COUPON_COLLECTION_NAME;
|
|
825
|
+
}
|
|
826
|
+
get(reqInfo) {
|
|
827
|
+
return reqInfo.utils.createResponse$(() => ({
|
|
828
|
+
body: this.listCoupons(reqInfo),
|
|
829
|
+
status: STATUS.OK
|
|
830
|
+
}));
|
|
831
|
+
}
|
|
832
|
+
post(reqInfo) {
|
|
833
|
+
return reqInfo.utils.createResponse$(() => ({
|
|
834
|
+
body: this.applyCoupon(reqInfo),
|
|
835
|
+
status: STATUS.OK
|
|
836
|
+
}));
|
|
837
|
+
}
|
|
838
|
+
delete(reqInfo) {
|
|
839
|
+
return reqInfo.utils.createResponse$(() => {
|
|
840
|
+
let body;
|
|
841
|
+
const action = this.getAction(reqInfo);
|
|
842
|
+
if (action) body = this.removeCoupon(reqInfo, action);
|
|
843
|
+
else body = this.removeAllCoupons(reqInfo);
|
|
844
|
+
return {
|
|
845
|
+
body,
|
|
846
|
+
status: STATUS.OK
|
|
847
|
+
};
|
|
848
|
+
});
|
|
849
|
+
}
|
|
850
|
+
getAction(reqInfo) {
|
|
851
|
+
return reqInfo.url.replace(`/${reqInfo.resourceUrl}${reqInfo.id}/`, "");
|
|
852
|
+
}
|
|
853
|
+
getCart(reqInfo) {
|
|
854
|
+
return reqInfo.utils.findById(reqInfo.collection, reqInfo.id);
|
|
855
|
+
}
|
|
856
|
+
listCoupons(reqInfo) {
|
|
857
|
+
return this.getCart(reqInfo).coupons;
|
|
858
|
+
}
|
|
859
|
+
applyCoupon(reqInfo) {
|
|
860
|
+
const cart = this.getCart(reqInfo);
|
|
861
|
+
const coupon = reqInfo.utils.getJsonBody(reqInfo.req);
|
|
862
|
+
cart.coupons.push(coupon);
|
|
863
|
+
return {
|
|
864
|
+
...cart,
|
|
865
|
+
extra_attributes: this.extraFieldsHook(reqInfo, cart)
|
|
866
|
+
};
|
|
867
|
+
}
|
|
868
|
+
removeCoupon(reqInfo, couponCode) {
|
|
869
|
+
const cart = this.getCart(reqInfo);
|
|
870
|
+
cart.coupons = cart.coupons.filter(({ code }) => code !== couponCode);
|
|
871
|
+
return {
|
|
872
|
+
...cart,
|
|
873
|
+
extra_attributes: this.extraFieldsHook(reqInfo, cart)
|
|
874
|
+
};
|
|
875
|
+
}
|
|
876
|
+
removeAllCoupons(reqInfo) {
|
|
877
|
+
const cart = this.getCart(reqInfo);
|
|
878
|
+
cart.coupons = [];
|
|
879
|
+
return {
|
|
880
|
+
...cart,
|
|
881
|
+
extra_attributes: this.extraFieldsHook(reqInfo, cart)
|
|
882
|
+
};
|
|
883
|
+
}
|
|
884
|
+
static {
|
|
885
|
+
this.ɵfac = i0.ɵɵngDeclareFactory({
|
|
886
|
+
minVersion: "12.0.0",
|
|
887
|
+
version: "22.2.4",
|
|
888
|
+
ngImport: i0,
|
|
889
|
+
type: DaffInMemoryBackendCartCouponService,
|
|
890
|
+
deps: [{ token: DAFF_CART_IN_MEMORY_EXTRA_ATTRIBUTES_HOOK }],
|
|
891
|
+
target: i0.ɵɵFactoryTarget.Injectable
|
|
892
|
+
});
|
|
893
|
+
}
|
|
894
|
+
static {
|
|
895
|
+
this.ɵprov = i0.ɵɵngDeclareInjectable({
|
|
896
|
+
minVersion: "12.0.0",
|
|
897
|
+
version: "22.2.4",
|
|
898
|
+
ngImport: i0,
|
|
899
|
+
type: DaffInMemoryBackendCartCouponService,
|
|
900
|
+
providedIn: "root"
|
|
901
|
+
});
|
|
902
|
+
}
|
|
903
|
+
};
|
|
904
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
905
|
+
minVersion: "12.0.0",
|
|
906
|
+
version: "22.2.4",
|
|
907
|
+
ngImport: i0,
|
|
908
|
+
type: DaffInMemoryBackendCartCouponService,
|
|
909
|
+
decorators: [{
|
|
910
|
+
type: Injectable,
|
|
911
|
+
args: [{ providedIn: "root" }]
|
|
912
|
+
}],
|
|
913
|
+
ctorParameters: () => [{
|
|
914
|
+
type: void 0,
|
|
915
|
+
decorators: [{
|
|
916
|
+
type: Inject,
|
|
917
|
+
args: [DAFF_CART_IN_MEMORY_EXTRA_ATTRIBUTES_HOOK]
|
|
918
|
+
}]
|
|
919
|
+
}]
|
|
920
|
+
});
|
|
680
921
|
function daffCartInMemoryComputeCartItemPrices(cartItem, products) {
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
}
|
|
685
|
-
|
|
686
|
-
/**
|
|
687
|
-
* @inheritdoc
|
|
688
|
-
*/
|
|
689
|
-
class DaffInMemoryBackendCartItemsService {
|
|
690
|
-
constructor(cartItemFactory, extraFieldsHook, productBackend) {
|
|
691
|
-
this.cartItemFactory = cartItemFactory;
|
|
692
|
-
this.extraFieldsHook = extraFieldsHook;
|
|
693
|
-
this.productBackend = productBackend;
|
|
694
|
-
this.collectionName = DAFF_CART_IN_MEMORY_CART_ITEMS_COLLECTION_NAME;
|
|
695
|
-
}
|
|
696
|
-
get(reqInfo) {
|
|
697
|
-
return reqInfo.utils.createResponse$(() => {
|
|
698
|
-
let body;
|
|
699
|
-
const action = this.getAction(reqInfo);
|
|
700
|
-
if (action) {
|
|
701
|
-
body = this.getItem(reqInfo, action);
|
|
702
|
-
}
|
|
703
|
-
else {
|
|
704
|
-
body = this.listItems(reqInfo);
|
|
705
|
-
}
|
|
706
|
-
return {
|
|
707
|
-
body,
|
|
708
|
-
status: STATUS.OK,
|
|
709
|
-
};
|
|
710
|
-
});
|
|
711
|
-
}
|
|
712
|
-
put(reqInfo) {
|
|
713
|
-
return reqInfo.utils.createResponse$(() => ({
|
|
714
|
-
body: this.updateItem(reqInfo, this.getAction(reqInfo)),
|
|
715
|
-
status: STATUS.OK,
|
|
716
|
-
}));
|
|
717
|
-
}
|
|
718
|
-
post(reqInfo) {
|
|
719
|
-
return reqInfo.utils.createResponse$(() => ({
|
|
720
|
-
body: this.addItem(reqInfo),
|
|
721
|
-
status: STATUS.OK,
|
|
722
|
-
}));
|
|
723
|
-
}
|
|
724
|
-
delete(reqInfo) {
|
|
725
|
-
return reqInfo.utils.createResponse$(() => ({
|
|
726
|
-
body: this.deleteItem(reqInfo, this.getAction(reqInfo)),
|
|
727
|
-
status: STATUS.OK,
|
|
728
|
-
}));
|
|
729
|
-
}
|
|
730
|
-
/**
|
|
731
|
-
* Gets whatever follows the cart ID section of the request URL.
|
|
732
|
-
*/
|
|
733
|
-
getAction(reqInfo) {
|
|
734
|
-
return reqInfo.url.replace(`/${reqInfo.resourceUrl}${reqInfo.id}/`, '');
|
|
735
|
-
}
|
|
736
|
-
getCart(reqInfo) {
|
|
737
|
-
return reqInfo.utils.findById(reqInfo.collection, reqInfo.id);
|
|
738
|
-
}
|
|
739
|
-
transformItemInput(itemInput) {
|
|
740
|
-
return {
|
|
741
|
-
...this.cartItemFactory.fromProduct(this.productBackend.products.find((product) => product.id === itemInput.productId)),
|
|
742
|
-
...itemInput,
|
|
743
|
-
};
|
|
744
|
-
}
|
|
745
|
-
listItems(reqInfo) {
|
|
746
|
-
return this.getCart(reqInfo).items;
|
|
747
|
-
}
|
|
748
|
-
getItem(reqInfo, itemId) {
|
|
749
|
-
const cart = this.getCart(reqInfo);
|
|
750
|
-
return cart.items.find(({ id }) => itemId === id);
|
|
751
|
-
}
|
|
752
|
-
updateItem(reqInfo, itemId) {
|
|
753
|
-
const cart = this.getCart(reqInfo);
|
|
754
|
-
const cartIndex = reqInfo.collection.findIndex(c => c.id === reqInfo.id);
|
|
755
|
-
const itemChanges = reqInfo.utils.getJsonBody(reqInfo.req);
|
|
756
|
-
const itemIndex = cart.items.findIndex((item) => itemId === item.id);
|
|
757
|
-
reqInfo.collection[cartIndex] = daffCartInMemoryComputeCartTotals({
|
|
758
|
-
...cart,
|
|
759
|
-
items: cart.items.map((item, index) => index === itemIndex ? daffCartInMemoryComputeCartItemPrices({
|
|
760
|
-
...cart.items[itemIndex],
|
|
761
|
-
...itemChanges,
|
|
762
|
-
}, this.productBackend.products) : item),
|
|
763
|
-
extra_attributes: this.extraFieldsHook(reqInfo, cart),
|
|
764
|
-
}, this.productBackend.products);
|
|
765
|
-
return reqInfo.collection[cartIndex];
|
|
766
|
-
}
|
|
767
|
-
addItem(reqInfo) {
|
|
768
|
-
const cart = this.getCart(reqInfo);
|
|
769
|
-
const cartIndex = reqInfo.collection.findIndex(c => c.id === reqInfo.id);
|
|
770
|
-
const itemInput = reqInfo.utils.getJsonBody(reqInfo.req);
|
|
771
|
-
const existingCartItemIndex = cart.items.findIndex(item => item.product_id === itemInput.productId);
|
|
772
|
-
if (existingCartItemIndex > -1) {
|
|
773
|
-
const updatedCartItem = {
|
|
774
|
-
...cart.items[existingCartItemIndex],
|
|
775
|
-
qty: cart.items[existingCartItemIndex].qty + itemInput.qty,
|
|
776
|
-
};
|
|
777
|
-
reqInfo.collection[cartIndex] = daffCartInMemoryComputeCartTotals({
|
|
778
|
-
...cart,
|
|
779
|
-
items: cart.items.map((item, index) => index === existingCartItemIndex ? daffCartInMemoryComputeCartItemPrices(updatedCartItem, this.productBackend.products) : item),
|
|
780
|
-
extra_attributes: this.extraFieldsHook(reqInfo, cart),
|
|
781
|
-
}, this.productBackend.products);
|
|
782
|
-
}
|
|
783
|
-
else {
|
|
784
|
-
reqInfo.collection[cartIndex] = daffCartInMemoryComputeCartTotals({
|
|
785
|
-
...cart,
|
|
786
|
-
items: [
|
|
787
|
-
...cart.items,
|
|
788
|
-
daffCartInMemoryComputeCartItemPrices(this.transformItemInput(itemInput), this.productBackend.products),
|
|
789
|
-
],
|
|
790
|
-
extra_attributes: this.extraFieldsHook(reqInfo, cart),
|
|
791
|
-
}, this.productBackend.products);
|
|
792
|
-
}
|
|
793
|
-
return reqInfo.collection[cartIndex];
|
|
794
|
-
}
|
|
795
|
-
deleteItem(reqInfo, itemId) {
|
|
796
|
-
const cart = this.getCart(reqInfo);
|
|
797
|
-
const itemIndex = cart.items.findIndex(({ id }) => itemId === id);
|
|
798
|
-
const cartIndex = reqInfo.collection.findIndex(c => c.id === reqInfo.id);
|
|
799
|
-
reqInfo.collection[cartIndex] = daffCartInMemoryComputeCartTotals({
|
|
800
|
-
...cart,
|
|
801
|
-
items: cart.items.filter((item, index) => index !== itemIndex),
|
|
802
|
-
extra_attributes: this.extraFieldsHook(reqInfo, cart),
|
|
803
|
-
}, this.productBackend.products);
|
|
804
|
-
return reqInfo.collection[cartIndex];
|
|
805
|
-
}
|
|
806
|
-
/** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: DaffInMemoryBackendCartItemsService, deps: [{ token: i1$1.DaffCartItemFactory }, { token: DAFF_CART_IN_MEMORY_EXTRA_ATTRIBUTES_HOOK }, { token: i2$1.DaffInMemoryBackendProductService }], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
807
|
-
/** @nocollapse */ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: DaffInMemoryBackendCartItemsService, providedIn: 'root' }); }
|
|
808
|
-
}
|
|
809
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: DaffInMemoryBackendCartItemsService, decorators: [{
|
|
810
|
-
type: Injectable,
|
|
811
|
-
args: [{
|
|
812
|
-
providedIn: 'root',
|
|
813
|
-
}]
|
|
814
|
-
}], ctorParameters: () => [{ type: i1$1.DaffCartItemFactory }, { type: undefined, decorators: [{
|
|
815
|
-
type: Inject,
|
|
816
|
-
args: [DAFF_CART_IN_MEMORY_EXTRA_ATTRIBUTES_HOOK]
|
|
817
|
-
}] }, { type: i2$1.DaffInMemoryBackendProductService }] });
|
|
818
|
-
|
|
819
|
-
/**
|
|
820
|
-
* @inheritdoc
|
|
821
|
-
*/
|
|
822
|
-
class DaffInMemoryBackendCartOrderService {
|
|
823
|
-
constructor() {
|
|
824
|
-
this.collectionName = DAFF_CART_IN_MEMORY_CART_ORDER_COLLECTION_NAME;
|
|
825
|
-
}
|
|
826
|
-
post(reqInfo) {
|
|
827
|
-
return reqInfo.utils.createResponse$(() => ({
|
|
828
|
-
body: this.placeOrder(reqInfo),
|
|
829
|
-
status: STATUS.OK,
|
|
830
|
-
}));
|
|
831
|
-
}
|
|
832
|
-
placeOrder(reqInfo) {
|
|
833
|
-
return {
|
|
834
|
-
cartId: '89fdsa8sadf',
|
|
835
|
-
orderId: '8235422034',
|
|
836
|
-
};
|
|
837
|
-
}
|
|
838
|
-
/** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: DaffInMemoryBackendCartOrderService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
839
|
-
/** @nocollapse */ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: DaffInMemoryBackendCartOrderService, providedIn: 'root' }); }
|
|
840
|
-
}
|
|
841
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: DaffInMemoryBackendCartOrderService, decorators: [{
|
|
842
|
-
type: Injectable,
|
|
843
|
-
args: [{
|
|
844
|
-
providedIn: 'root',
|
|
845
|
-
}]
|
|
846
|
-
}] });
|
|
847
|
-
|
|
848
|
-
/**
|
|
849
|
-
* @inheritdoc
|
|
850
|
-
*/
|
|
851
|
-
class DaffInMemoryBackendCartPaymentService {
|
|
852
|
-
constructor(extraFieldsHook) {
|
|
853
|
-
this.extraFieldsHook = extraFieldsHook;
|
|
854
|
-
this.collectionName = DAFF_CART_IN_MEMORY_CART_PAYMENT_COLLECTION_NAME;
|
|
855
|
-
}
|
|
856
|
-
get(reqInfo) {
|
|
857
|
-
return reqInfo.utils.createResponse$(() => ({
|
|
858
|
-
body: this.getPayment(reqInfo),
|
|
859
|
-
status: STATUS.OK,
|
|
860
|
-
}));
|
|
861
|
-
}
|
|
862
|
-
put(reqInfo) {
|
|
863
|
-
return reqInfo.utils.createResponse$(() => ({
|
|
864
|
-
body: this.updatePayment(reqInfo),
|
|
865
|
-
status: STATUS.OK,
|
|
866
|
-
}));
|
|
867
|
-
}
|
|
868
|
-
delete(reqInfo) {
|
|
869
|
-
return reqInfo.utils.createResponse$(() => ({
|
|
870
|
-
body: this.removePayment(reqInfo),
|
|
871
|
-
status: STATUS.OK,
|
|
872
|
-
}));
|
|
873
|
-
}
|
|
874
|
-
getCart(reqInfo) {
|
|
875
|
-
return reqInfo.utils.findById(reqInfo.collection, reqInfo.id);
|
|
876
|
-
}
|
|
877
|
-
getPayment(reqInfo) {
|
|
878
|
-
return this.getCart(reqInfo).payment;
|
|
879
|
-
}
|
|
880
|
-
updatePayment(reqInfo) {
|
|
881
|
-
const cart = this.getCart(reqInfo);
|
|
882
|
-
const { payment, address } = reqInfo.utils.getJsonBody(reqInfo.req);
|
|
883
|
-
cart.payment = payment;
|
|
884
|
-
if (address) {
|
|
885
|
-
cart.billing_address = address;
|
|
886
|
-
}
|
|
887
|
-
return {
|
|
888
|
-
...cart,
|
|
889
|
-
extra_attributes: this.extraFieldsHook(reqInfo, cart),
|
|
890
|
-
};
|
|
891
|
-
}
|
|
892
|
-
removePayment(reqInfo) {
|
|
893
|
-
const cart = this.getCart(reqInfo);
|
|
894
|
-
cart.payment = null;
|
|
895
|
-
return {
|
|
896
|
-
...cart,
|
|
897
|
-
extra_attributes: this.extraFieldsHook(reqInfo, cart),
|
|
898
|
-
};
|
|
899
|
-
}
|
|
900
|
-
/** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: DaffInMemoryBackendCartPaymentService, deps: [{ token: DAFF_CART_IN_MEMORY_EXTRA_ATTRIBUTES_HOOK }], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
901
|
-
/** @nocollapse */ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: DaffInMemoryBackendCartPaymentService, providedIn: 'root' }); }
|
|
922
|
+
cartItem.price = products.find(({ id }) => id === cartItem.product_id)?.price || 0;
|
|
923
|
+
cartItem.row_total = daffMultiply(cartItem.price, cartItem.qty);
|
|
924
|
+
return cartItem;
|
|
902
925
|
}
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
}
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
926
|
+
var DaffInMemoryBackendCartItemsService = class DaffInMemoryBackendCartItemsService {
|
|
927
|
+
constructor(cartItemFactory, extraFieldsHook, productBackend) {
|
|
928
|
+
this.cartItemFactory = cartItemFactory;
|
|
929
|
+
this.extraFieldsHook = extraFieldsHook;
|
|
930
|
+
this.productBackend = productBackend;
|
|
931
|
+
this.collectionName = DAFF_CART_IN_MEMORY_CART_ITEMS_COLLECTION_NAME;
|
|
932
|
+
}
|
|
933
|
+
get(reqInfo) {
|
|
934
|
+
return reqInfo.utils.createResponse$(() => {
|
|
935
|
+
let body;
|
|
936
|
+
const action = this.getAction(reqInfo);
|
|
937
|
+
if (action) body = this.getItem(reqInfo, action);
|
|
938
|
+
else body = this.listItems(reqInfo);
|
|
939
|
+
return {
|
|
940
|
+
body,
|
|
941
|
+
status: STATUS.OK
|
|
942
|
+
};
|
|
943
|
+
});
|
|
944
|
+
}
|
|
945
|
+
put(reqInfo) {
|
|
946
|
+
return reqInfo.utils.createResponse$(() => ({
|
|
947
|
+
body: this.updateItem(reqInfo, this.getAction(reqInfo)),
|
|
948
|
+
status: STATUS.OK
|
|
949
|
+
}));
|
|
950
|
+
}
|
|
951
|
+
post(reqInfo) {
|
|
952
|
+
return reqInfo.utils.createResponse$(() => ({
|
|
953
|
+
body: this.addItem(reqInfo),
|
|
954
|
+
status: STATUS.OK
|
|
955
|
+
}));
|
|
956
|
+
}
|
|
957
|
+
delete(reqInfo) {
|
|
958
|
+
return reqInfo.utils.createResponse$(() => ({
|
|
959
|
+
body: this.deleteItem(reqInfo, this.getAction(reqInfo)),
|
|
960
|
+
status: STATUS.OK
|
|
961
|
+
}));
|
|
962
|
+
}
|
|
963
|
+
getAction(reqInfo) {
|
|
964
|
+
return reqInfo.url.replace(`/${reqInfo.resourceUrl}${reqInfo.id}/`, "");
|
|
965
|
+
}
|
|
966
|
+
getCart(reqInfo) {
|
|
967
|
+
return reqInfo.utils.findById(reqInfo.collection, reqInfo.id);
|
|
968
|
+
}
|
|
969
|
+
transformItemInput(itemInput) {
|
|
970
|
+
return {
|
|
971
|
+
...this.cartItemFactory.fromProduct(this.productBackend.products.find((product) => product.id === itemInput.productId)),
|
|
972
|
+
...itemInput
|
|
973
|
+
};
|
|
974
|
+
}
|
|
975
|
+
listItems(reqInfo) {
|
|
976
|
+
return this.getCart(reqInfo).items;
|
|
977
|
+
}
|
|
978
|
+
getItem(reqInfo, itemId) {
|
|
979
|
+
return this.getCart(reqInfo).items.find(({ id }) => itemId === id);
|
|
980
|
+
}
|
|
981
|
+
updateItem(reqInfo, itemId) {
|
|
982
|
+
const cart = this.getCart(reqInfo);
|
|
983
|
+
const cartIndex = reqInfo.collection.findIndex((c) => c.id === reqInfo.id);
|
|
984
|
+
const itemChanges = reqInfo.utils.getJsonBody(reqInfo.req);
|
|
985
|
+
const itemIndex = cart.items.findIndex((item) => itemId === item.id);
|
|
986
|
+
reqInfo.collection[cartIndex] = daffCartInMemoryComputeCartTotals({
|
|
987
|
+
...cart,
|
|
988
|
+
items: cart.items.map((item, index) => index === itemIndex ? daffCartInMemoryComputeCartItemPrices({
|
|
989
|
+
...cart.items[itemIndex],
|
|
990
|
+
...itemChanges
|
|
991
|
+
}, this.productBackend.products) : item),
|
|
992
|
+
extra_attributes: this.extraFieldsHook(reqInfo, cart)
|
|
993
|
+
}, this.productBackend.products);
|
|
994
|
+
return reqInfo.collection[cartIndex];
|
|
995
|
+
}
|
|
996
|
+
addItem(reqInfo) {
|
|
997
|
+
const cart = this.getCart(reqInfo);
|
|
998
|
+
const cartIndex = reqInfo.collection.findIndex((c) => c.id === reqInfo.id);
|
|
999
|
+
const itemInput = reqInfo.utils.getJsonBody(reqInfo.req);
|
|
1000
|
+
const existingCartItemIndex = cart.items.findIndex((item) => item.product_id === itemInput.productId);
|
|
1001
|
+
if (existingCartItemIndex > -1) {
|
|
1002
|
+
const updatedCartItem = {
|
|
1003
|
+
...cart.items[existingCartItemIndex],
|
|
1004
|
+
qty: cart.items[existingCartItemIndex].qty + itemInput.qty
|
|
1005
|
+
};
|
|
1006
|
+
reqInfo.collection[cartIndex] = daffCartInMemoryComputeCartTotals({
|
|
1007
|
+
...cart,
|
|
1008
|
+
items: cart.items.map((item, index) => index === existingCartItemIndex ? daffCartInMemoryComputeCartItemPrices(updatedCartItem, this.productBackend.products) : item),
|
|
1009
|
+
extra_attributes: this.extraFieldsHook(reqInfo, cart)
|
|
1010
|
+
}, this.productBackend.products);
|
|
1011
|
+
} else reqInfo.collection[cartIndex] = daffCartInMemoryComputeCartTotals({
|
|
1012
|
+
...cart,
|
|
1013
|
+
items: [...cart.items, daffCartInMemoryComputeCartItemPrices(this.transformItemInput(itemInput), this.productBackend.products)],
|
|
1014
|
+
extra_attributes: this.extraFieldsHook(reqInfo, cart)
|
|
1015
|
+
}, this.productBackend.products);
|
|
1016
|
+
return reqInfo.collection[cartIndex];
|
|
1017
|
+
}
|
|
1018
|
+
deleteItem(reqInfo, itemId) {
|
|
1019
|
+
const cart = this.getCart(reqInfo);
|
|
1020
|
+
const itemIndex = cart.items.findIndex(({ id }) => itemId === id);
|
|
1021
|
+
const cartIndex = reqInfo.collection.findIndex((c) => c.id === reqInfo.id);
|
|
1022
|
+
reqInfo.collection[cartIndex] = daffCartInMemoryComputeCartTotals({
|
|
1023
|
+
...cart,
|
|
1024
|
+
items: cart.items.filter((item, index) => index !== itemIndex),
|
|
1025
|
+
extra_attributes: this.extraFieldsHook(reqInfo, cart)
|
|
1026
|
+
}, this.productBackend.products);
|
|
1027
|
+
return reqInfo.collection[cartIndex];
|
|
1028
|
+
}
|
|
1029
|
+
static {
|
|
1030
|
+
this.ɵfac = i0.ɵɵngDeclareFactory({
|
|
1031
|
+
minVersion: "12.0.0",
|
|
1032
|
+
version: "22.2.4",
|
|
1033
|
+
ngImport: i0,
|
|
1034
|
+
type: DaffInMemoryBackendCartItemsService,
|
|
1035
|
+
deps: [
|
|
1036
|
+
{ token: i1.DaffCartItemFactory },
|
|
1037
|
+
{ token: DAFF_CART_IN_MEMORY_EXTRA_ATTRIBUTES_HOOK },
|
|
1038
|
+
{ token: i2.DaffInMemoryBackendProductService }
|
|
1039
|
+
],
|
|
1040
|
+
target: i0.ɵɵFactoryTarget.Injectable
|
|
1041
|
+
});
|
|
1042
|
+
}
|
|
1043
|
+
static {
|
|
1044
|
+
this.ɵprov = i0.ɵɵngDeclareInjectable({
|
|
1045
|
+
minVersion: "12.0.0",
|
|
1046
|
+
version: "22.2.4",
|
|
1047
|
+
ngImport: i0,
|
|
1048
|
+
type: DaffInMemoryBackendCartItemsService,
|
|
1049
|
+
providedIn: "root"
|
|
1050
|
+
});
|
|
1051
|
+
}
|
|
1052
|
+
};
|
|
1053
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
1054
|
+
minVersion: "12.0.0",
|
|
1055
|
+
version: "22.2.4",
|
|
1056
|
+
ngImport: i0,
|
|
1057
|
+
type: DaffInMemoryBackendCartItemsService,
|
|
1058
|
+
decorators: [{
|
|
1059
|
+
type: Injectable,
|
|
1060
|
+
args: [{ providedIn: "root" }]
|
|
1061
|
+
}],
|
|
1062
|
+
ctorParameters: () => [
|
|
1063
|
+
{ type: i1.DaffCartItemFactory },
|
|
1064
|
+
{
|
|
1065
|
+
type: void 0,
|
|
1066
|
+
decorators: [{
|
|
1067
|
+
type: Inject,
|
|
1068
|
+
args: [DAFF_CART_IN_MEMORY_EXTRA_ATTRIBUTES_HOOK]
|
|
1069
|
+
}]
|
|
1070
|
+
},
|
|
1071
|
+
{ type: i2.DaffInMemoryBackendProductService }
|
|
1072
|
+
]
|
|
1073
|
+
});
|
|
1074
|
+
var DaffInMemoryBackendCartOrderService = class DaffInMemoryBackendCartOrderService {
|
|
1075
|
+
constructor() {
|
|
1076
|
+
this.collectionName = DAFF_CART_IN_MEMORY_CART_ORDER_COLLECTION_NAME;
|
|
1077
|
+
}
|
|
1078
|
+
post(reqInfo) {
|
|
1079
|
+
return reqInfo.utils.createResponse$(() => ({
|
|
1080
|
+
body: this.placeOrder(reqInfo),
|
|
1081
|
+
status: STATUS.OK
|
|
1082
|
+
}));
|
|
1083
|
+
}
|
|
1084
|
+
placeOrder(reqInfo) {
|
|
1085
|
+
return {
|
|
1086
|
+
cartId: "89fdsa8sadf",
|
|
1087
|
+
orderId: "8235422034"
|
|
1088
|
+
};
|
|
1089
|
+
}
|
|
1090
|
+
static {
|
|
1091
|
+
this.ɵfac = i0.ɵɵngDeclareFactory({
|
|
1092
|
+
minVersion: "12.0.0",
|
|
1093
|
+
version: "22.2.4",
|
|
1094
|
+
ngImport: i0,
|
|
1095
|
+
type: DaffInMemoryBackendCartOrderService,
|
|
1096
|
+
deps: [],
|
|
1097
|
+
target: i0.ɵɵFactoryTarget.Injectable
|
|
1098
|
+
});
|
|
1099
|
+
}
|
|
1100
|
+
static {
|
|
1101
|
+
this.ɵprov = i0.ɵɵngDeclareInjectable({
|
|
1102
|
+
minVersion: "12.0.0",
|
|
1103
|
+
version: "22.2.4",
|
|
1104
|
+
ngImport: i0,
|
|
1105
|
+
type: DaffInMemoryBackendCartOrderService,
|
|
1106
|
+
providedIn: "root"
|
|
1107
|
+
});
|
|
1108
|
+
}
|
|
1109
|
+
};
|
|
1110
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
1111
|
+
minVersion: "12.0.0",
|
|
1112
|
+
version: "22.2.4",
|
|
1113
|
+
ngImport: i0,
|
|
1114
|
+
type: DaffInMemoryBackendCartOrderService,
|
|
1115
|
+
decorators: [{
|
|
1116
|
+
type: Injectable,
|
|
1117
|
+
args: [{ providedIn: "root" }]
|
|
1118
|
+
}]
|
|
1119
|
+
});
|
|
1120
|
+
var DaffInMemoryBackendCartPaymentService = class DaffInMemoryBackendCartPaymentService {
|
|
1121
|
+
constructor(extraFieldsHook) {
|
|
1122
|
+
this.extraFieldsHook = extraFieldsHook;
|
|
1123
|
+
this.collectionName = DAFF_CART_IN_MEMORY_CART_PAYMENT_COLLECTION_NAME;
|
|
1124
|
+
}
|
|
1125
|
+
get(reqInfo) {
|
|
1126
|
+
return reqInfo.utils.createResponse$(() => ({
|
|
1127
|
+
body: this.getPayment(reqInfo),
|
|
1128
|
+
status: STATUS.OK
|
|
1129
|
+
}));
|
|
1130
|
+
}
|
|
1131
|
+
put(reqInfo) {
|
|
1132
|
+
return reqInfo.utils.createResponse$(() => ({
|
|
1133
|
+
body: this.updatePayment(reqInfo),
|
|
1134
|
+
status: STATUS.OK
|
|
1135
|
+
}));
|
|
1136
|
+
}
|
|
1137
|
+
delete(reqInfo) {
|
|
1138
|
+
return reqInfo.utils.createResponse$(() => ({
|
|
1139
|
+
body: this.removePayment(reqInfo),
|
|
1140
|
+
status: STATUS.OK
|
|
1141
|
+
}));
|
|
1142
|
+
}
|
|
1143
|
+
getCart(reqInfo) {
|
|
1144
|
+
return reqInfo.utils.findById(reqInfo.collection, reqInfo.id);
|
|
1145
|
+
}
|
|
1146
|
+
getPayment(reqInfo) {
|
|
1147
|
+
return this.getCart(reqInfo).payment;
|
|
1148
|
+
}
|
|
1149
|
+
updatePayment(reqInfo) {
|
|
1150
|
+
const cart = this.getCart(reqInfo);
|
|
1151
|
+
const { payment, address } = reqInfo.utils.getJsonBody(reqInfo.req);
|
|
1152
|
+
cart.payment = payment;
|
|
1153
|
+
if (address) cart.billing_address = address;
|
|
1154
|
+
return {
|
|
1155
|
+
...cart,
|
|
1156
|
+
extra_attributes: this.extraFieldsHook(reqInfo, cart)
|
|
1157
|
+
};
|
|
1158
|
+
}
|
|
1159
|
+
removePayment(reqInfo) {
|
|
1160
|
+
const cart = this.getCart(reqInfo);
|
|
1161
|
+
cart.payment = null;
|
|
1162
|
+
return {
|
|
1163
|
+
...cart,
|
|
1164
|
+
extra_attributes: this.extraFieldsHook(reqInfo, cart)
|
|
1165
|
+
};
|
|
1166
|
+
}
|
|
1167
|
+
static {
|
|
1168
|
+
this.ɵfac = i0.ɵɵngDeclareFactory({
|
|
1169
|
+
minVersion: "12.0.0",
|
|
1170
|
+
version: "22.2.4",
|
|
1171
|
+
ngImport: i0,
|
|
1172
|
+
type: DaffInMemoryBackendCartPaymentService,
|
|
1173
|
+
deps: [{ token: DAFF_CART_IN_MEMORY_EXTRA_ATTRIBUTES_HOOK }],
|
|
1174
|
+
target: i0.ɵɵFactoryTarget.Injectable
|
|
1175
|
+
});
|
|
1176
|
+
}
|
|
1177
|
+
static {
|
|
1178
|
+
this.ɵprov = i0.ɵɵngDeclareInjectable({
|
|
1179
|
+
minVersion: "12.0.0",
|
|
1180
|
+
version: "22.2.4",
|
|
1181
|
+
ngImport: i0,
|
|
1182
|
+
type: DaffInMemoryBackendCartPaymentService,
|
|
1183
|
+
providedIn: "root"
|
|
1184
|
+
});
|
|
1185
|
+
}
|
|
1186
|
+
};
|
|
1187
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
1188
|
+
minVersion: "12.0.0",
|
|
1189
|
+
version: "22.2.4",
|
|
1190
|
+
ngImport: i0,
|
|
1191
|
+
type: DaffInMemoryBackendCartPaymentService,
|
|
1192
|
+
decorators: [{
|
|
1193
|
+
type: Injectable,
|
|
1194
|
+
args: [{ providedIn: "root" }]
|
|
1195
|
+
}],
|
|
1196
|
+
ctorParameters: () => [{
|
|
1197
|
+
type: void 0,
|
|
1198
|
+
decorators: [{
|
|
1199
|
+
type: Inject,
|
|
1200
|
+
args: [DAFF_CART_IN_MEMORY_EXTRA_ATTRIBUTES_HOOK]
|
|
1201
|
+
}]
|
|
1202
|
+
}]
|
|
1203
|
+
});
|
|
1204
|
+
var DaffInMemoryBackendCartPaymentMethodsService = class DaffInMemoryBackendCartPaymentMethodsService {
|
|
1205
|
+
constructor() {
|
|
1206
|
+
this.collectionName = DAFF_CART_IN_MEMORY_CART_PAYMENT_METHODS_COLLECTION_NAME;
|
|
1207
|
+
}
|
|
1208
|
+
get(reqInfo) {
|
|
1209
|
+
return reqInfo.utils.createResponse$(() => ({
|
|
1210
|
+
body: this.listPaymentMethods(reqInfo),
|
|
1211
|
+
status: STATUS.OK
|
|
1212
|
+
}));
|
|
1213
|
+
}
|
|
1214
|
+
getCart(reqInfo) {
|
|
1215
|
+
return reqInfo.utils.findById(reqInfo.collection, reqInfo.id);
|
|
1216
|
+
}
|
|
1217
|
+
listPaymentMethods(reqInfo) {
|
|
1218
|
+
return this.getCart(reqInfo).available_payment_methods;
|
|
1219
|
+
}
|
|
1220
|
+
static {
|
|
1221
|
+
this.ɵfac = i0.ɵɵngDeclareFactory({
|
|
1222
|
+
minVersion: "12.0.0",
|
|
1223
|
+
version: "22.2.4",
|
|
1224
|
+
ngImport: i0,
|
|
1225
|
+
type: DaffInMemoryBackendCartPaymentMethodsService,
|
|
1226
|
+
deps: [],
|
|
1227
|
+
target: i0.ɵɵFactoryTarget.Injectable
|
|
1228
|
+
});
|
|
1229
|
+
}
|
|
1230
|
+
static {
|
|
1231
|
+
this.ɵprov = i0.ɵɵngDeclareInjectable({
|
|
1232
|
+
minVersion: "12.0.0",
|
|
1233
|
+
version: "22.2.4",
|
|
1234
|
+
ngImport: i0,
|
|
1235
|
+
type: DaffInMemoryBackendCartPaymentMethodsService,
|
|
1236
|
+
providedIn: "root"
|
|
1237
|
+
});
|
|
1238
|
+
}
|
|
1239
|
+
};
|
|
1240
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
1241
|
+
minVersion: "12.0.0",
|
|
1242
|
+
version: "22.2.4",
|
|
1243
|
+
ngImport: i0,
|
|
1244
|
+
type: DaffInMemoryBackendCartPaymentMethodsService,
|
|
1245
|
+
decorators: [{
|
|
1246
|
+
type: Injectable,
|
|
1247
|
+
args: [{ providedIn: "root" }]
|
|
1248
|
+
}]
|
|
1249
|
+
});
|
|
1250
|
+
var DaffInMemoryBackendCartShippingAddressService = class DaffInMemoryBackendCartShippingAddressService {
|
|
1251
|
+
constructor(extraFieldsHook) {
|
|
1252
|
+
this.extraFieldsHook = extraFieldsHook;
|
|
1253
|
+
this.collectionName = DAFF_CART_IN_MEMORY_CART_SHIPPING_ADDRESS_COLLECTION_NAME;
|
|
1254
|
+
}
|
|
1255
|
+
get(reqInfo) {
|
|
1256
|
+
return reqInfo.utils.createResponse$(() => ({
|
|
1257
|
+
body: this.getShippingAddress(reqInfo),
|
|
1258
|
+
status: STATUS.OK
|
|
1259
|
+
}));
|
|
1260
|
+
}
|
|
1261
|
+
put(reqInfo) {
|
|
1262
|
+
return reqInfo.utils.createResponse$(() => ({
|
|
1263
|
+
body: this.updateShippingAddress(reqInfo),
|
|
1264
|
+
status: STATUS.OK
|
|
1265
|
+
}));
|
|
1266
|
+
}
|
|
1267
|
+
getCart(reqInfo) {
|
|
1268
|
+
return reqInfo.utils.findById(reqInfo.collection, reqInfo.id);
|
|
1269
|
+
}
|
|
1270
|
+
getShippingAddress(reqInfo) {
|
|
1271
|
+
return this.getCart(reqInfo).shipping_address;
|
|
1272
|
+
}
|
|
1273
|
+
updateShippingAddress(reqInfo) {
|
|
1274
|
+
const cart = this.getCart(reqInfo);
|
|
1275
|
+
cart.shipping_address = reqInfo.utils.getJsonBody(reqInfo.req);
|
|
1276
|
+
return {
|
|
1277
|
+
...cart,
|
|
1278
|
+
extra_attributes: this.extraFieldsHook(reqInfo, cart)
|
|
1279
|
+
};
|
|
1280
|
+
}
|
|
1281
|
+
static {
|
|
1282
|
+
this.ɵfac = i0.ɵɵngDeclareFactory({
|
|
1283
|
+
minVersion: "12.0.0",
|
|
1284
|
+
version: "22.2.4",
|
|
1285
|
+
ngImport: i0,
|
|
1286
|
+
type: DaffInMemoryBackendCartShippingAddressService,
|
|
1287
|
+
deps: [{ token: DAFF_CART_IN_MEMORY_EXTRA_ATTRIBUTES_HOOK }],
|
|
1288
|
+
target: i0.ɵɵFactoryTarget.Injectable
|
|
1289
|
+
});
|
|
1290
|
+
}
|
|
1291
|
+
static {
|
|
1292
|
+
this.ɵprov = i0.ɵɵngDeclareInjectable({
|
|
1293
|
+
minVersion: "12.0.0",
|
|
1294
|
+
version: "22.2.4",
|
|
1295
|
+
ngImport: i0,
|
|
1296
|
+
type: DaffInMemoryBackendCartShippingAddressService,
|
|
1297
|
+
providedIn: "root"
|
|
1298
|
+
});
|
|
1299
|
+
}
|
|
1300
|
+
};
|
|
1301
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
1302
|
+
minVersion: "12.0.0",
|
|
1303
|
+
version: "22.2.4",
|
|
1304
|
+
ngImport: i0,
|
|
1305
|
+
type: DaffInMemoryBackendCartShippingAddressService,
|
|
1306
|
+
decorators: [{
|
|
1307
|
+
type: Injectable,
|
|
1308
|
+
args: [{ providedIn: "root" }]
|
|
1309
|
+
}],
|
|
1310
|
+
ctorParameters: () => [{
|
|
1311
|
+
type: void 0,
|
|
1312
|
+
decorators: [{
|
|
1313
|
+
type: Inject,
|
|
1314
|
+
args: [DAFF_CART_IN_MEMORY_EXTRA_ATTRIBUTES_HOOK]
|
|
1315
|
+
}]
|
|
1316
|
+
}]
|
|
1317
|
+
});
|
|
1318
|
+
var DaffInMemoryBackendCartShippingInformationService = class DaffInMemoryBackendCartShippingInformationService {
|
|
1319
|
+
constructor(extraFieldsHook, productBackend) {
|
|
1320
|
+
this.extraFieldsHook = extraFieldsHook;
|
|
1321
|
+
this.productBackend = productBackend;
|
|
1322
|
+
this.collectionName = DAFF_CART_IN_MEMORY_CART_SHIPPING_COLLECTION_NAME;
|
|
1323
|
+
}
|
|
1324
|
+
get(reqInfo) {
|
|
1325
|
+
return reqInfo.utils.createResponse$(() => ({
|
|
1326
|
+
body: this.getShippingInformation(reqInfo),
|
|
1327
|
+
status: STATUS.OK
|
|
1328
|
+
}));
|
|
1329
|
+
}
|
|
1330
|
+
put(reqInfo) {
|
|
1331
|
+
return reqInfo.utils.createResponse$(() => ({
|
|
1332
|
+
body: this.updateShippingInformation(reqInfo),
|
|
1333
|
+
status: STATUS.OK
|
|
1334
|
+
}));
|
|
1335
|
+
}
|
|
1336
|
+
delete(reqInfo) {
|
|
1337
|
+
return reqInfo.utils.createResponse$(() => ({
|
|
1338
|
+
body: this.removeShippingInformation(reqInfo),
|
|
1339
|
+
status: STATUS.OK
|
|
1340
|
+
}));
|
|
1341
|
+
}
|
|
1342
|
+
getCart(reqInfo) {
|
|
1343
|
+
return reqInfo.utils.findById(reqInfo.collection, reqInfo.id);
|
|
1344
|
+
}
|
|
1345
|
+
getShippingInformation(reqInfo) {
|
|
1346
|
+
return this.getCart(reqInfo).shipping_information;
|
|
1347
|
+
}
|
|
1348
|
+
updateShippingInformation(reqInfo) {
|
|
1349
|
+
const cart = this.getCart(reqInfo);
|
|
1350
|
+
cart.shipping_information = reqInfo.utils.getJsonBody(reqInfo.req);
|
|
1351
|
+
return {
|
|
1352
|
+
...daffCartInMemoryComputeCartTotals(cart, this.productBackend.products),
|
|
1353
|
+
extra_attributes: this.extraFieldsHook(reqInfo, cart)
|
|
1354
|
+
};
|
|
1355
|
+
}
|
|
1356
|
+
removeShippingInformation(reqInfo) {
|
|
1357
|
+
const cart = this.getCart(reqInfo);
|
|
1358
|
+
cart.shipping_information = null;
|
|
1359
|
+
return {
|
|
1360
|
+
...daffCartInMemoryComputeCartTotals(cart, this.productBackend.products),
|
|
1361
|
+
extra_attributes: this.extraFieldsHook(reqInfo, cart)
|
|
1362
|
+
};
|
|
1363
|
+
}
|
|
1364
|
+
static {
|
|
1365
|
+
this.ɵfac = i0.ɵɵngDeclareFactory({
|
|
1366
|
+
minVersion: "12.0.0",
|
|
1367
|
+
version: "22.2.4",
|
|
1368
|
+
ngImport: i0,
|
|
1369
|
+
type: DaffInMemoryBackendCartShippingInformationService,
|
|
1370
|
+
deps: [{ token: DAFF_CART_IN_MEMORY_EXTRA_ATTRIBUTES_HOOK }, { token: i2.DaffInMemoryBackendProductService }],
|
|
1371
|
+
target: i0.ɵɵFactoryTarget.Injectable
|
|
1372
|
+
});
|
|
1373
|
+
}
|
|
1374
|
+
static {
|
|
1375
|
+
this.ɵprov = i0.ɵɵngDeclareInjectable({
|
|
1376
|
+
minVersion: "12.0.0",
|
|
1377
|
+
version: "22.2.4",
|
|
1378
|
+
ngImport: i0,
|
|
1379
|
+
type: DaffInMemoryBackendCartShippingInformationService,
|
|
1380
|
+
providedIn: "root"
|
|
1381
|
+
});
|
|
1382
|
+
}
|
|
1383
|
+
};
|
|
1384
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
1385
|
+
minVersion: "12.0.0",
|
|
1386
|
+
version: "22.2.4",
|
|
1387
|
+
ngImport: i0,
|
|
1388
|
+
type: DaffInMemoryBackendCartShippingInformationService,
|
|
1389
|
+
decorators: [{
|
|
1390
|
+
type: Injectable,
|
|
1391
|
+
args: [{ providedIn: "root" }]
|
|
1392
|
+
}],
|
|
1393
|
+
ctorParameters: () => [{
|
|
1394
|
+
type: void 0,
|
|
1395
|
+
decorators: [{
|
|
1396
|
+
type: Inject,
|
|
1397
|
+
args: [DAFF_CART_IN_MEMORY_EXTRA_ATTRIBUTES_HOOK]
|
|
1398
|
+
}]
|
|
1399
|
+
}, { type: i2.DaffInMemoryBackendProductService }]
|
|
1400
|
+
});
|
|
1401
|
+
var DaffInMemoryBackendCartShippingMethodsService = class DaffInMemoryBackendCartShippingMethodsService {
|
|
1402
|
+
constructor(shippingMethodFactory) {
|
|
1403
|
+
this.shippingMethodFactory = shippingMethodFactory;
|
|
1404
|
+
this.collectionName = DAFF_CART_IN_MEMORY_CART_SHIPPING_METHODS_COLLECTION_NAME;
|
|
1405
|
+
}
|
|
1406
|
+
get(reqInfo) {
|
|
1407
|
+
return reqInfo.utils.createResponse$(() => ({
|
|
1408
|
+
body: this.listShippingMethods(reqInfo),
|
|
1409
|
+
status: STATUS.OK
|
|
1410
|
+
}));
|
|
1411
|
+
}
|
|
1412
|
+
getCart(reqInfo) {
|
|
1413
|
+
return reqInfo.utils.findById(reqInfo.collection, reqInfo.id);
|
|
1414
|
+
}
|
|
1415
|
+
listShippingMethods(reqInfo) {
|
|
1416
|
+
const cart = this.getCart(reqInfo);
|
|
1417
|
+
if (cart.shipping_address) {
|
|
1418
|
+
if (cart.available_shipping_methods?.length === 0) cart.available_shipping_methods = this.shippingMethodFactory.createMany(3);
|
|
1419
|
+
} else cart.available_shipping_methods = [];
|
|
1420
|
+
return cart.available_shipping_methods;
|
|
1421
|
+
}
|
|
1422
|
+
static {
|
|
1423
|
+
this.ɵfac = i0.ɵɵngDeclareFactory({
|
|
1424
|
+
minVersion: "12.0.0",
|
|
1425
|
+
version: "22.2.4",
|
|
1426
|
+
ngImport: i0,
|
|
1427
|
+
type: DaffInMemoryBackendCartShippingMethodsService,
|
|
1428
|
+
deps: [{ token: i1.DaffCartShippingRateFactory }],
|
|
1429
|
+
target: i0.ɵɵFactoryTarget.Injectable
|
|
1430
|
+
});
|
|
1431
|
+
}
|
|
1432
|
+
static {
|
|
1433
|
+
this.ɵprov = i0.ɵɵngDeclareInjectable({
|
|
1434
|
+
minVersion: "12.0.0",
|
|
1435
|
+
version: "22.2.4",
|
|
1436
|
+
ngImport: i0,
|
|
1437
|
+
type: DaffInMemoryBackendCartShippingMethodsService,
|
|
1438
|
+
providedIn: "root"
|
|
1439
|
+
});
|
|
1440
|
+
}
|
|
1441
|
+
};
|
|
1442
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
1443
|
+
minVersion: "12.0.0",
|
|
1444
|
+
version: "22.2.4",
|
|
1445
|
+
ngImport: i0,
|
|
1446
|
+
type: DaffInMemoryBackendCartShippingMethodsService,
|
|
1447
|
+
decorators: [{
|
|
1448
|
+
type: Injectable,
|
|
1449
|
+
args: [{ providedIn: "root" }]
|
|
1450
|
+
}],
|
|
1451
|
+
ctorParameters: () => [{ type: i1.DaffCartShippingRateFactory }]
|
|
1452
|
+
});
|
|
1096
1453
|
const COLLECTION_NAMES = [
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1454
|
+
"cart",
|
|
1455
|
+
"cart-items",
|
|
1456
|
+
"cart-order",
|
|
1457
|
+
"cart-coupon",
|
|
1458
|
+
"cart-address",
|
|
1459
|
+
"cart-shipping-address",
|
|
1460
|
+
"cart-billing-address",
|
|
1461
|
+
"cart-payment-methods",
|
|
1462
|
+
"cart-shipping-methods",
|
|
1463
|
+
"cart-payment",
|
|
1464
|
+
"cart-shipping-information"
|
|
1108
1465
|
];
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
}
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
}
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1466
|
+
var DaffInMemoryBackendCartRootService = class DaffInMemoryBackendCartRootService extends DaffInMemoryBackendDelegate {
|
|
1467
|
+
constructor(cartService, cartItemsService, cartOrderService, cartCouponService, cartAddressService, cartShippingAddressService, cartBillingAddressService, cartPaymentMethodsService, cartShippingMethodsService, cartPaymentService, cartShippingInformationService, _config) {
|
|
1468
|
+
super([
|
|
1469
|
+
cartService,
|
|
1470
|
+
cartItemsService,
|
|
1471
|
+
cartOrderService,
|
|
1472
|
+
cartCouponService,
|
|
1473
|
+
cartAddressService,
|
|
1474
|
+
cartShippingAddressService,
|
|
1475
|
+
cartBillingAddressService,
|
|
1476
|
+
cartPaymentMethodsService,
|
|
1477
|
+
cartShippingMethodsService,
|
|
1478
|
+
cartPaymentService,
|
|
1479
|
+
cartShippingInformationService
|
|
1480
|
+
], _config);
|
|
1481
|
+
this._config = _config;
|
|
1482
|
+
this.carts = [];
|
|
1483
|
+
}
|
|
1484
|
+
delegateRequest(reqInfo, method) {
|
|
1485
|
+
return super.delegateRequest({
|
|
1486
|
+
...reqInfo,
|
|
1487
|
+
collection: this.carts
|
|
1488
|
+
}, method);
|
|
1489
|
+
}
|
|
1490
|
+
canHandle(collectionName) {
|
|
1491
|
+
return COLLECTION_NAMES.includes(collectionName);
|
|
1492
|
+
}
|
|
1493
|
+
createDb(reqInfo) {
|
|
1494
|
+
if (reqInfo) {
|
|
1495
|
+
const seedData = reqInfo.utils.getJsonBody(reqInfo.req).carts;
|
|
1496
|
+
if (seedData) this.carts = seedData;
|
|
1497
|
+
}
|
|
1498
|
+
return of({ cart: this.carts });
|
|
1499
|
+
}
|
|
1500
|
+
static {
|
|
1501
|
+
this.ɵfac = i0.ɵɵngDeclareFactory({
|
|
1502
|
+
minVersion: "12.0.0",
|
|
1503
|
+
version: "22.2.4",
|
|
1504
|
+
ngImport: i0,
|
|
1505
|
+
type: DaffInMemoryBackendCartRootService,
|
|
1506
|
+
deps: [
|
|
1507
|
+
{ token: DaffInMemoryBackendCartService },
|
|
1508
|
+
{ token: DaffInMemoryBackendCartItemsService },
|
|
1509
|
+
{ token: DaffInMemoryBackendCartOrderService },
|
|
1510
|
+
{ token: DaffInMemoryBackendCartCouponService },
|
|
1511
|
+
{ token: DaffInMemoryBackendCartAddressService },
|
|
1512
|
+
{ token: DaffInMemoryBackendCartShippingAddressService },
|
|
1513
|
+
{ token: DaffInMemoryBackendCartBillingAddressService },
|
|
1514
|
+
{ token: DaffInMemoryBackendCartPaymentMethodsService },
|
|
1515
|
+
{ token: DaffInMemoryBackendCartShippingMethodsService },
|
|
1516
|
+
{ token: DaffInMemoryBackendCartPaymentService },
|
|
1517
|
+
{ token: DaffInMemoryBackendCartShippingInformationService },
|
|
1518
|
+
{ token: DAFF_IN_MEMORY_DRIVER_CONFIG }
|
|
1519
|
+
],
|
|
1520
|
+
target: i0.ɵɵFactoryTarget.Injectable
|
|
1521
|
+
});
|
|
1522
|
+
}
|
|
1523
|
+
static {
|
|
1524
|
+
this.ɵprov = i0.ɵɵngDeclareInjectable({
|
|
1525
|
+
minVersion: "12.0.0",
|
|
1526
|
+
version: "22.2.4",
|
|
1527
|
+
ngImport: i0,
|
|
1528
|
+
type: DaffInMemoryBackendCartRootService,
|
|
1529
|
+
providedIn: "root"
|
|
1530
|
+
});
|
|
1531
|
+
}
|
|
1532
|
+
};
|
|
1533
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
1534
|
+
minVersion: "12.0.0",
|
|
1535
|
+
version: "22.2.4",
|
|
1536
|
+
ngImport: i0,
|
|
1537
|
+
type: DaffInMemoryBackendCartRootService,
|
|
1538
|
+
decorators: [{
|
|
1539
|
+
type: Injectable,
|
|
1540
|
+
args: [{ providedIn: "root" }]
|
|
1541
|
+
}],
|
|
1542
|
+
ctorParameters: () => [
|
|
1543
|
+
{ type: DaffInMemoryBackendCartService },
|
|
1544
|
+
{ type: DaffInMemoryBackendCartItemsService },
|
|
1545
|
+
{ type: DaffInMemoryBackendCartOrderService },
|
|
1546
|
+
{ type: DaffInMemoryBackendCartCouponService },
|
|
1547
|
+
{ type: DaffInMemoryBackendCartAddressService },
|
|
1548
|
+
{ type: DaffInMemoryBackendCartShippingAddressService },
|
|
1549
|
+
{ type: DaffInMemoryBackendCartBillingAddressService },
|
|
1550
|
+
{ type: DaffInMemoryBackendCartPaymentMethodsService },
|
|
1551
|
+
{ type: DaffInMemoryBackendCartShippingMethodsService },
|
|
1552
|
+
{ type: DaffInMemoryBackendCartPaymentService },
|
|
1553
|
+
{ type: DaffInMemoryBackendCartShippingInformationService },
|
|
1554
|
+
{
|
|
1555
|
+
type: void 0,
|
|
1556
|
+
decorators: [{
|
|
1557
|
+
type: Inject,
|
|
1558
|
+
args: [DAFF_IN_MEMORY_DRIVER_CONFIG]
|
|
1559
|
+
}]
|
|
1560
|
+
}
|
|
1561
|
+
]
|
|
1562
|
+
});
|
|
1563
|
+
const provideDaffCartInMemoryDriver = () => makeEnvironmentProviders([
|
|
1564
|
+
provideDaffCartDriver(DaffInMemoryCartService),
|
|
1565
|
+
provideDaffCartAddressDriver(DaffInMemoryCartAddressService),
|
|
1566
|
+
provideDaffCartBillingAddressDriver(DaffInMemoryCartBillingAddressService),
|
|
1567
|
+
provideDaffCartItemDriver(DaffInMemoryCartItemService),
|
|
1568
|
+
provideDaffCartPaymentDriver(DaffInMemoryCartPaymentService),
|
|
1569
|
+
provideDaffCartPaymentMethodsDriver(DaffInMemoryCartPaymentMethodsService),
|
|
1570
|
+
provideDaffCartShippingAddressDriver(DaffInMemoryCartShippingAddressService),
|
|
1571
|
+
provideDaffCartShippingInformationDriver(DaffInMemoryCartShippingInformationService),
|
|
1572
|
+
provideDaffCartShippingMethodsDriver(DaffInMemoryCartShippingMethodsService),
|
|
1573
|
+
provideDaffCartOrderDriver(DaffInMemoryCartOrderService),
|
|
1574
|
+
provideDaffCartCouponDriver(DaffInMemoryCartCouponService),
|
|
1575
|
+
provideDaffInMemoryBackends(DaffInMemoryBackendCartRootService)
|
|
1576
|
+
]);
|
|
1577
|
+
var DaffCartInMemoryDriverModule = class DaffCartInMemoryDriverModule {
|
|
1578
|
+
static forRoot() {
|
|
1579
|
+
return {
|
|
1580
|
+
ngModule: DaffCartInMemoryDriverModule,
|
|
1581
|
+
providers: [provideDaffCartInMemoryDriver()]
|
|
1582
|
+
};
|
|
1583
|
+
}
|
|
1584
|
+
static {
|
|
1585
|
+
this.ɵfac = i0.ɵɵngDeclareFactory({
|
|
1586
|
+
minVersion: "12.0.0",
|
|
1587
|
+
version: "22.2.4",
|
|
1588
|
+
ngImport: i0,
|
|
1589
|
+
type: DaffCartInMemoryDriverModule,
|
|
1590
|
+
deps: [],
|
|
1591
|
+
target: i0.ɵɵFactoryTarget.NgModule
|
|
1592
|
+
});
|
|
1593
|
+
}
|
|
1594
|
+
static {
|
|
1595
|
+
this.ɵmod = i0.ɵɵngDeclareNgModule({
|
|
1596
|
+
minVersion: "14.0.0",
|
|
1597
|
+
version: "22.2.4",
|
|
1598
|
+
ngImport: i0,
|
|
1599
|
+
type: DaffCartInMemoryDriverModule,
|
|
1600
|
+
imports: [CommonModule]
|
|
1601
|
+
});
|
|
1602
|
+
}
|
|
1603
|
+
static {
|
|
1604
|
+
this.ɵinj = i0.ɵɵngDeclareInjector({
|
|
1605
|
+
minVersion: "12.0.0",
|
|
1606
|
+
version: "22.2.4",
|
|
1607
|
+
ngImport: i0,
|
|
1608
|
+
type: DaffCartInMemoryDriverModule,
|
|
1609
|
+
imports: [CommonModule]
|
|
1610
|
+
});
|
|
1611
|
+
}
|
|
1612
|
+
};
|
|
1613
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
1614
|
+
minVersion: "12.0.0",
|
|
1615
|
+
version: "22.2.4",
|
|
1616
|
+
ngImport: i0,
|
|
1617
|
+
type: DaffCartInMemoryDriverModule,
|
|
1618
|
+
decorators: [{
|
|
1619
|
+
type: NgModule,
|
|
1620
|
+
args: [{ imports: [CommonModule] }]
|
|
1621
|
+
}]
|
|
1622
|
+
});
|
|
1623
|
+
export { DAFF_CART_IN_MEMORY_CART_ADDRESS_COLLECTION_NAME, DAFF_CART_IN_MEMORY_CART_BILLING_ADDRESS_COLLECTION_NAME, DAFF_CART_IN_MEMORY_CART_COLLECTION_NAME, DAFF_CART_IN_MEMORY_CART_COUPON_COLLECTION_NAME, DAFF_CART_IN_MEMORY_CART_ITEMS_COLLECTION_NAME, DAFF_CART_IN_MEMORY_CART_ORDER_COLLECTION_NAME, DAFF_CART_IN_MEMORY_CART_PAYMENT_COLLECTION_NAME, DAFF_CART_IN_MEMORY_CART_PAYMENT_METHODS_COLLECTION_NAME, DAFF_CART_IN_MEMORY_CART_SHIPPING_ADDRESS_COLLECTION_NAME, DAFF_CART_IN_MEMORY_CART_SHIPPING_COLLECTION_NAME, DAFF_CART_IN_MEMORY_CART_SHIPPING_METHODS_COLLECTION_NAME, DAFF_CART_IN_MEMORY_EXTRA_ATTRIBUTES_HOOK, DaffCartInMemoryDriverModule, DaffInMemoryBackendCartAddressService, DaffInMemoryBackendCartBillingAddressService, DaffInMemoryBackendCartCouponService, DaffInMemoryBackendCartItemsService, DaffInMemoryBackendCartOrderService, DaffInMemoryBackendCartPaymentMethodsService, DaffInMemoryBackendCartPaymentService, DaffInMemoryBackendCartRootService, DaffInMemoryBackendCartService, DaffInMemoryBackendCartShippingAddressService, DaffInMemoryBackendCartShippingInformationService, DaffInMemoryBackendCartShippingMethodsService, DaffInMemoryCartBillingAddressService, DaffInMemoryCartCouponService, DaffInMemoryCartItemService, DaffInMemoryCartOrderService, DaffInMemoryCartPaymentMethodsService, DaffInMemoryCartPaymentService, DaffInMemoryCartService, DaffInMemoryCartShippingAddressService, DaffInMemoryCartShippingInformationService, DaffInMemoryCartShippingMethodsService, provideDaffCartInMemoryDriver };
|
|
1203
1624
|
|
|
1204
|
-
|
|
1205
|
-
//# sourceMappingURL=daffodil-cart-driver-in-memory.mjs.map
|
|
1625
|
+
//# sourceMappingURL=daffodil-cart-driver-in-memory.mjs.map
|