@infrab4a/connect-angular 4.13.2 → 4.13.3-beta.2

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