@infrab4a/connect-angular 4.13.2-beta.3 → 4.13.2-beta.5
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 +10 -15
- package/fesm2015/infrab4a-connect-angular.mjs +13 -19
- package/fesm2015/infrab4a-connect-angular.mjs.map +1 -1
- package/fesm2020/infrab4a-connect-angular.mjs +9 -14
- package/fesm2020/infrab4a-connect-angular.mjs.map +1 -1
- package/package.json +2 -2
- package/services/cart.service.d.ts +0 -1
|
@@ -1384,10 +1384,9 @@ class CartService {
|
|
|
1384
1384
|
this.updateLineItemInCart = (lineItem, quantity, checkout) => (isNil(checkout) ? this.checkoutService.getCheckout() : of(checkout)).pipe(concatMap((checkoutLoaded) => {
|
|
1385
1385
|
const items = [];
|
|
1386
1386
|
const index = checkoutLoaded.lineItems?.map((checkoutItem) => checkoutItem.id).indexOf(lineItem.id);
|
|
1387
|
-
const isGift = checkoutLoaded.lineItems?.[index]?.isGift;
|
|
1388
1387
|
if (index > -1) {
|
|
1389
1388
|
checkoutLoaded.lineItems[index].quantity += quantity;
|
|
1390
|
-
checkoutLoaded.lineItems[index].pricePaid =
|
|
1389
|
+
checkoutLoaded.lineItems[index].pricePaid = lineItem.pricePaid;
|
|
1391
1390
|
checkoutLoaded.lineItems[index].price = lineItem.price;
|
|
1392
1391
|
}
|
|
1393
1392
|
else
|
|
@@ -1410,14 +1409,12 @@ class CartService {
|
|
|
1410
1409
|
throw new Error('Desculpe! Temos apenas ' + product.stock?.quantity + ' em estoque.');
|
|
1411
1410
|
const image = item.image || item.images?.shift();
|
|
1412
1411
|
const { id, name, EAN, slug, weight, sku, type } = item;
|
|
1413
|
-
const isGift = item
|
|
1414
|
-
const pricePaid =
|
|
1415
|
-
|
|
1416
|
-
: this.
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
isSubscriber: checkout.user?.isSubscriber,
|
|
1420
|
-
});
|
|
1412
|
+
const isGift = item.isGift || null;
|
|
1413
|
+
const pricePaid = this.getProductPrice({
|
|
1414
|
+
product: LineItem.toInstance(product),
|
|
1415
|
+
shop: checkout.shop || this.defaultShop,
|
|
1416
|
+
isSubscriber: checkout.user?.isSubscriber,
|
|
1417
|
+
});
|
|
1421
1418
|
RoundProductPricesHelper.roundProductPrices(item);
|
|
1422
1419
|
RoundProductPricesHelper.roundProductPrices(product);
|
|
1423
1420
|
return {
|
|
@@ -1438,7 +1435,7 @@ class CartService {
|
|
|
1438
1435
|
discount: 0,
|
|
1439
1436
|
categories: product.categories || product.category?.id ? [product.category?.id, ...product.categories] : [],
|
|
1440
1437
|
isGift: isGift ?? null,
|
|
1441
|
-
costPrice:
|
|
1438
|
+
costPrice: product.costPrice ?? 0,
|
|
1442
1439
|
type,
|
|
1443
1440
|
}),
|
|
1444
1441
|
};
|
|
@@ -1458,7 +1455,7 @@ class CartService {
|
|
|
1458
1455
|
};
|
|
1459
1456
|
}
|
|
1460
1457
|
addItem(item, quantity = 1) {
|
|
1461
|
-
return from(this.checkoutService.getCheckout()).pipe(
|
|
1458
|
+
return from(this.checkoutService.getCheckout()).pipe(concatMap(async (checkout) => await this.buildLineItem({ checkout, item, quantity: quantity || 1 })), mergeMap(({ checkout, lineItem }) => this.updateLineItemInCart(lineItem, quantity || 1, checkout)), tap((cart) => this.cartSubject.next(cart)));
|
|
1462
1459
|
}
|
|
1463
1460
|
decreaseItem(item) {
|
|
1464
1461
|
return this.checkoutService.getCheckout().pipe(map((checkout) => {
|
|
@@ -1487,8 +1484,6 @@ class CartService {
|
|
|
1487
1484
|
}), concatMap((checkout) => this.checkoutService.updateCheckoutLineItems(checkout)), map((checkout) => this.generateCartObject(checkout.lineItems)), tap((cart) => this.cartSubject.next(cart)));
|
|
1488
1485
|
}
|
|
1489
1486
|
updateUserCart(user) {
|
|
1490
|
-
if (this.user?.id === user.id && this.user?.isSubscriber === user.isSubscriber)
|
|
1491
|
-
return this.cartSubject;
|
|
1492
1487
|
return this.checkoutService.getCheckout().pipe(concatMap((checkout) => this.checkoutService.updateCheckoutUser(Checkout.toInstance({ ...checkout.toPlain(), user }))), concatMap(async (checkout) => await this.checkoutService
|
|
1493
1488
|
.updateCheckoutLineItems(Checkout.toInstance({
|
|
1494
1489
|
...checkout.toPlain(),
|