@infrab4a/connect-angular 4.13.4-beta.1 → 4.13.5-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.
@@ -1380,7 +1380,6 @@ class CartService {
1380
1380
  this.categoryRepository = categoryRepository;
1381
1381
  this.variantRepository = variantRepository;
1382
1382
  this.buy2WinRepository = buy2WinRepository;
1383
- this.cart = {};
1384
1383
  this.cartSubject = new Subject();
1385
1384
  this.updateLineItemInCart = (lineItem, quantity, checkout) => (isNil(checkout) ? this.checkoutService.getCheckout() : of(checkout)).pipe(concatMap((checkoutLoaded) => {
1386
1385
  const items = [];
@@ -1397,6 +1396,13 @@ class CartService {
1397
1396
  .updateCheckoutLineItems(checkoutLoaded)
1398
1397
  .pipe(map((updatedCheckout) => this.generateCartObject(updatedCheckout.lineItems)));
1399
1398
  }));
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
+ }), {}) || {};
1400
1406
  this.buildLineItem = async ({ checkout, item, quantity, }) => {
1401
1407
  const product = await this.getProductData(item.id);
1402
1408
  item.quantity = item?.quantity || checkout?.lineItems?.find((lineItem) => lineItem.id === item.id)?.quantity || 0;
@@ -1431,6 +1437,8 @@ class CartService {
1431
1437
  pricePaid,
1432
1438
  discount: 0,
1433
1439
  categories: product.categories || product.category?.id ? [product.category?.id, ...product.categories] : [],
1440
+ category: product.category,
1441
+ categoryReference: product.category?.reference,
1434
1442
  isGift: isGift ?? null,
1435
1443
  costPrice: isGift ? 0 : product.costPrice ?? 0,
1436
1444
  type,
@@ -1481,8 +1489,10 @@ class CartService {
1481
1489
  }), concatMap((checkout) => this.checkoutService.updateCheckoutLineItems(checkout)), map((checkout) => this.generateCartObject(checkout.lineItems)), tap((cart) => this.cartSubject.next(cart)));
1482
1490
  }
1483
1491
  updateUserCart(user) {
1484
- if (this.user?.id === user?.id && this.user?.isSubscriber === user?.isSubscriber)
1485
- return this.cartSubject.asObservable();
1492
+ const isSameUserId = !user?.id || this.user?.id === user?.id;
1493
+ const isSameUser = isSameUserId && !!this.user?.isSubscriber === !!user?.isSubscriber;
1494
+ if (isSameUser)
1495
+ return this.getCart();
1486
1496
  return this.checkoutService.getCheckout().pipe(concatMap((checkout) => this.checkoutService.updateCheckoutUser(Checkout.toInstance({ ...checkout.toPlain(), user }))), concatMap(async (checkout) => await this.checkoutService
1487
1497
  .updateCheckoutLineItems(Checkout.toInstance({
1488
1498
  ...checkout.toPlain(),
@@ -1490,7 +1500,7 @@ class CartService {
1490
1500
  ? await Promise.all(checkout.lineItems?.map(async (item) => (await this.buildLineItem({ checkout, item })).lineItem))
1491
1501
  : [],
1492
1502
  }))
1493
- .toPromise()), map((checkout) => this.generateCartObject(checkout.lineItems)), tap((cart) => this.cartSubject.next(cart)));
1503
+ .toPromise()), map((checkout) => this.generateCartObject(checkout.lineItems)), tap((cart) => (this.user = user)), tap((cart) => this.cartSubject.next(cart)));
1494
1504
  }
1495
1505
  clearCart() {
1496
1506
  return this.checkoutService.getCheckout().pipe(map((checkout) => {
@@ -1501,16 +1511,6 @@ class CartService {
1501
1511
  buildCartFromCheckout(checkoutData) {
1502
1512
  return this.checkoutService.getCheckout(checkoutData).pipe(map((checkout) => checkout.lineItems), concatMap((lineItems) => of(this.generateCartObject(lineItems))));
1503
1513
  }
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
- }
1514
1514
  roundPrice(productPrice) {
1515
1515
  const { price, fullPrice, subscriberPrice } = productPrice;
1516
1516
  return {