@infrab4a/connect-angular 5.0.0-beta.61 → 5.0.0-beta.62

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.
Files changed (56) hide show
  1. package/esm2022/angular-connect.module.mjs +1 -1
  2. package/esm2022/angular-elastic-search.module.mjs +1 -1
  3. package/esm2022/angular-firebase-auth.module.mjs +1 -1
  4. package/esm2022/angular-firestore.module.mjs +1 -1
  5. package/esm2022/angular-hasura-graphql.module.mjs +1 -1
  6. package/esm2022/angular-vertex-search.module.mjs +1 -1
  7. package/esm2022/consts/category-structure.mjs +1 -1
  8. package/esm2022/consts/default-shop.const.mjs +1 -1
  9. package/esm2022/consts/es-config.const.mjs +1 -1
  10. package/esm2022/consts/firebase-const.mjs +1 -1
  11. package/esm2022/consts/hasura-options.const.mjs +1 -1
  12. package/esm2022/consts/index.mjs +1 -1
  13. package/esm2022/consts/persistence.const.mjs +1 -1
  14. package/esm2022/consts/storage-base-url.const.mjs +1 -1
  15. package/esm2022/consts/vertex-config.const.mjs +1 -1
  16. package/esm2022/helpers/index.mjs +1 -1
  17. package/esm2022/helpers/mobile-operation-system-checker.helper.mjs +1 -1
  18. package/esm2022/index.mjs +1 -1
  19. package/esm2022/persistence/cookie-data-persistence.mjs +1 -1
  20. package/esm2022/persistence/data-persistence.mjs +1 -1
  21. package/esm2022/persistence/index.mjs +1 -1
  22. package/esm2022/services/auth.service.mjs +1 -1
  23. package/esm2022/services/cart.service.mjs +20 -11
  24. package/esm2022/services/catalog/adapters/category-structure.adapter.mjs +1 -1
  25. package/esm2022/services/catalog/adapters/index.mjs +1 -1
  26. package/esm2022/services/catalog/adapters/new-category-structure.adapter.mjs +1 -1
  27. package/esm2022/services/catalog/adapters/old-category-structure.adapter.mjs +1 -1
  28. package/esm2022/services/catalog/catalog.service.mjs +1 -1
  29. package/esm2022/services/catalog/category.service.mjs +1 -1
  30. package/esm2022/services/catalog/enums/index.mjs +1 -1
  31. package/esm2022/services/catalog/enums/product-sorts.enum.mjs +1 -1
  32. package/esm2022/services/catalog/index.mjs +1 -1
  33. package/esm2022/services/catalog/models/category-with-tree.model.mjs +1 -1
  34. package/esm2022/services/catalog/models/index.mjs +1 -1
  35. package/esm2022/services/catalog/types/index.mjs +1 -1
  36. package/esm2022/services/catalog/types/product-sort.type.mjs +1 -1
  37. package/esm2022/services/catalog/wishlist.service.mjs +1 -1
  38. package/esm2022/services/checkout-subscription.service.mjs +1 -1
  39. package/esm2022/services/checkout.service.mjs +1 -1
  40. package/esm2022/services/coupon.service.mjs +1 -1
  41. package/esm2022/services/helpers/index.mjs +1 -1
  42. package/esm2022/services/helpers/util.helper.mjs +1 -1
  43. package/esm2022/services/home-shop.service.mjs +1 -1
  44. package/esm2022/services/index.mjs +1 -1
  45. package/esm2022/services/order.service.mjs +1 -1
  46. package/esm2022/services/shipping.service.mjs +1 -1
  47. package/esm2022/services/types/index.mjs +1 -1
  48. package/esm2022/services/types/required-checkout-data.type.mjs +1 -1
  49. package/esm2022/services/types/required-checkout-subscription-data.type.mjs +1 -1
  50. package/esm2022/services/types/shipping-methods.type.mjs +1 -1
  51. package/esm2022/types/firebase-app-config.type.mjs +1 -1
  52. package/esm2022/types/index.mjs +1 -1
  53. package/fesm2022/infrab4a-connect-angular.mjs +19 -10
  54. package/fesm2022/infrab4a-connect-angular.mjs.map +1 -1
  55. package/package.json +2 -2
  56. package/services/cart.service.d.ts +1 -0
@@ -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 {
@@ -1434,8 +1437,9 @@ class CartService {
1434
1437
  pricePaid,
1435
1438
  discount: 0,
1436
1439
  categories: product.categories || product.category?.id ? [product.category?.id, ...product.categories] : [],
1440
+ category: product.category,
1437
1441
  isGift: isGift ?? null,
1438
- costPrice: product.costPrice ?? 0,
1442
+ costPrice: isGift ? 0 : product.costPrice ?? 0,
1439
1443
  type,
1440
1444
  }),
1441
1445
  };
@@ -1484,6 +1488,10 @@ class CartService {
1484
1488
  }), concatMap((checkout) => this.checkoutService.updateCheckoutLineItems(checkout)), map((checkout) => this.generateCartObject(checkout.lineItems)), tap((cart) => this.cartSubject.next(cart)));
1485
1489
  }
1486
1490
  updateUserCart(user) {
1491
+ const isSameUserId = !user?.id || this.user?.id === user?.id;
1492
+ const isSameUser = isSameUserId && !!this.user?.isSubscriber === !!user?.isSubscriber;
1493
+ if (isSameUser)
1494
+ return this.getCart();
1487
1495
  return this.checkoutService.getCheckout().pipe(concatMap((checkout) => this.checkoutService.updateCheckoutUser(Checkout.toInstance({ ...checkout.toPlain(), user }))), concatMap(async (checkout) => await this.checkoutService
1488
1496
  .updateCheckoutLineItems(Checkout.toInstance({
1489
1497
  ...checkout.toPlain(),
@@ -1491,7 +1499,7 @@ class CartService {
1491
1499
  ? await Promise.all(checkout.lineItems?.map(async (item) => (await this.buildLineItem({ checkout, item })).lineItem))
1492
1500
  : [],
1493
1501
  }))
1494
- .toPromise()), map((checkout) => this.generateCartObject(checkout.lineItems)), tap((cart) => this.cartSubject.next(cart)));
1502
+ .toPromise()), map((checkout) => this.generateCartObject(checkout.lineItems)), tap((cart) => (this.user = user)), tap((cart) => this.cartSubject.next(cart)));
1495
1503
  }
1496
1504
  clearCart() {
1497
1505
  return this.checkoutService.getCheckout().pipe(map((checkout) => {
@@ -1602,11 +1610,12 @@ class CartService {
1602
1610
  }
1603
1611
  giftToLineItems(items) {
1604
1612
  return items.map((item) => {
1605
- const { brand, categories, id, name, price, sku, slug, stock, weight, EAN } = item;
1613
+ const { brand, categories, category, id, name, price, sku, slug, stock, weight, EAN } = item;
1606
1614
  const image = item?.miniatures?.length ? item.miniatures[0] : item.images[0];
1607
1615
  return LineItem.toInstance({
1608
1616
  brand,
1609
1617
  categories,
1618
+ category,
1610
1619
  id: id.toString(),
1611
1620
  name,
1612
1621
  price,