@infrab4a/connect-angular 4.13.3-beta.3 → 4.13.4-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm2020/services/cart.service.mjs +13 -9
- package/fesm2015/infrab4a-connect-angular.mjs +9 -5
- package/fesm2015/infrab4a-connect-angular.mjs.map +1 -1
- package/fesm2020/infrab4a-connect-angular.mjs +12 -8
- package/fesm2020/infrab4a-connect-angular.mjs.map +1 -1
- package/package.json +1 -1
- package/services/cart.service.d.ts +1 -0
|
@@ -1380,6 +1380,7 @@ class CartService {
|
|
|
1380
1380
|
this.categoryRepository = categoryRepository;
|
|
1381
1381
|
this.variantRepository = variantRepository;
|
|
1382
1382
|
this.buy2WinRepository = buy2WinRepository;
|
|
1383
|
+
this.cart = {};
|
|
1383
1384
|
this.cartSubject = new Subject();
|
|
1384
1385
|
this.updateLineItemInCart = (lineItem, quantity, checkout) => (isNil(checkout) ? this.checkoutService.getCheckout() : of(checkout)).pipe(concatMap((checkoutLoaded) => {
|
|
1385
1386
|
const items = [];
|
|
@@ -1396,13 +1397,6 @@ class CartService {
|
|
|
1396
1397
|
.updateCheckoutLineItems(checkoutLoaded)
|
|
1397
1398
|
.pipe(map((updatedCheckout) => this.generateCartObject(updatedCheckout.lineItems)));
|
|
1398
1399
|
}));
|
|
1399
|
-
this.generateCartObject = (items) => items?.reduce((cart, item) => ({
|
|
1400
|
-
...cart,
|
|
1401
|
-
[item.id]: LineItem.toInstance({
|
|
1402
|
-
...(cart[item.id] || item),
|
|
1403
|
-
quantity: (cart[item.id]?.quantity || 0) + (item.quantity ? item.quantity : 1),
|
|
1404
|
-
}),
|
|
1405
|
-
}), {}) || {};
|
|
1406
1400
|
this.buildLineItem = async ({ checkout, item, quantity, }) => {
|
|
1407
1401
|
const product = await this.getProductData(item.id);
|
|
1408
1402
|
item.quantity = item?.quantity || checkout?.lineItems?.find((lineItem) => lineItem.id === item.id)?.quantity || 0;
|
|
@@ -1488,7 +1482,7 @@ class CartService {
|
|
|
1488
1482
|
}
|
|
1489
1483
|
updateUserCart(user) {
|
|
1490
1484
|
if (this.user?.id === user?.id && this.user?.isSubscriber === user?.isSubscriber)
|
|
1491
|
-
return this.
|
|
1485
|
+
return this.cartSubject.asObservable();
|
|
1492
1486
|
return this.checkoutService.getCheckout().pipe(concatMap((checkout) => this.checkoutService.updateCheckoutUser(Checkout.toInstance({ ...checkout.toPlain(), user }))), concatMap(async (checkout) => await this.checkoutService
|
|
1493
1487
|
.updateCheckoutLineItems(Checkout.toInstance({
|
|
1494
1488
|
...checkout.toPlain(),
|
|
@@ -1507,6 +1501,16 @@ class CartService {
|
|
|
1507
1501
|
buildCartFromCheckout(checkoutData) {
|
|
1508
1502
|
return this.checkoutService.getCheckout(checkoutData).pipe(map((checkout) => checkout.lineItems), concatMap((lineItems) => of(this.generateCartObject(lineItems))));
|
|
1509
1503
|
}
|
|
1504
|
+
generateCartObject(items) {
|
|
1505
|
+
return (this.cart =
|
|
1506
|
+
items?.reduce((cart, item) => ({
|
|
1507
|
+
...cart,
|
|
1508
|
+
[item.id]: LineItem.toInstance({
|
|
1509
|
+
...(cart[item.id] || item),
|
|
1510
|
+
quantity: (cart[item.id]?.quantity || 0) + (item.quantity ? item.quantity : 1),
|
|
1511
|
+
}),
|
|
1512
|
+
}), {}) || {});
|
|
1513
|
+
}
|
|
1510
1514
|
roundPrice(productPrice) {
|
|
1511
1515
|
const { price, fullPrice, subscriberPrice } = productPrice;
|
|
1512
1516
|
return {
|