simpo-component-library 2.0.17 → 2.0.19

Sign up to get free protection for your applications and to get access to all the features.
@@ -3603,11 +3603,12 @@ var cartType;
3603
3603
  })(cartType || (cartType = {}));
3604
3604
 
3605
3605
  class StorageServiceService {
3606
- constructor(eventService, cookieService, restService, router) {
3606
+ constructor(eventService, cookieService, restService, router, messageService) {
3607
3607
  this.eventService = eventService;
3608
3608
  this.cookieService = cookieService;
3609
3609
  this.restService = restService;
3610
3610
  this.router = router;
3611
+ this.messageService = messageService;
3611
3612
  this.totalCartItems = 0;
3612
3613
  this.databaseName = "USER";
3613
3614
  this.databaseVersion = 1;
@@ -3696,11 +3697,6 @@ class StorageServiceService {
3696
3697
  if (this.router.url.includes('cart'))
3697
3698
  return;
3698
3699
  const userDetails = this.getUser();
3699
- this.getCartProduct(userDetails?.userId).then((products) => {
3700
- console.log("Merged products:", products);
3701
- }).catch((error) => {
3702
- console.error("Error:", error);
3703
- });
3704
3700
  if (!!userDetails) {
3705
3701
  this.eventService.showLoadingScreen.emit(true);
3706
3702
  const request = forkJoin([
@@ -3760,15 +3756,17 @@ class StorageServiceService {
3760
3756
  const transaction = this.database.transaction(this.cartCollectionName, "readwrite");
3761
3757
  return await transaction.objectStore(this.cartCollectionName).getAll();
3762
3758
  }
3763
- async getCartProduct(userId) {
3759
+ async getCartProduct() {
3764
3760
  try {
3765
3761
  const cartResponse = await this.getUserCart();
3766
3762
  return new Promise((resolve, reject) => {
3767
3763
  cartResponse.onsuccess = async (cartData) => {
3768
3764
  const indexDBProduct = cartData.target.result;
3769
- if (userId) {
3765
+ const userDetails = this.getUser();
3766
+ if (userDetails?.userId) {
3770
3767
  try {
3771
- const response = await this.restService.getUserItems(userId, "CART").toPromise();
3768
+ const response = await this.restService.getUserItems(userDetails?.userId, "CART").toPromise();
3769
+ localStorage.setItem('cartId', response.data?.[0]?.cartId);
3772
3770
  const serverDBProduct = response?.data?.[0]?.orderedItems ?? [];
3773
3771
  for (let localProduct of indexDBProduct) {
3774
3772
  let productFound = false;
@@ -3881,7 +3879,7 @@ class StorageServiceService {
3881
3879
  storePaymentFor(paymentFor) {
3882
3880
  this.cookieService.set("paymentFor", paymentFor, 7);
3883
3881
  }
3884
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.1.4", ngImport: i0, type: StorageServiceService, deps: [{ token: EventsService }, { token: i2$2.CookieService }, { token: RestService }, { token: i2$3.Router }], target: i0.ɵɵFactoryTarget.Injectable }); }
3882
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.1.4", ngImport: i0, type: StorageServiceService, deps: [{ token: EventsService }, { token: i2$2.CookieService }, { token: RestService }, { token: i2$3.Router }, { token: i5$1.MessageService }], target: i0.ɵɵFactoryTarget.Injectable }); }
3885
3883
  static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "18.1.4", ngImport: i0, type: StorageServiceService, providedIn: 'root' }); }
3886
3884
  }
3887
3885
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.1.4", ngImport: i0, type: StorageServiceService, decorators: [{
@@ -3889,7 +3887,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.1.4", ngImpor
3889
3887
  args: [{
3890
3888
  providedIn: 'root'
3891
3889
  }]
3892
- }], ctorParameters: () => [{ type: EventsService }, { type: i2$2.CookieService }, { type: RestService }, { type: i2$3.Router }] });
3890
+ }], ctorParameters: () => [{ type: EventsService }, { type: i2$2.CookieService }, { type: RestService }, { type: i2$3.Router }, { type: i5$1.MessageService }] });
3893
3891
 
3894
3892
  class UserBasicInfoComponent {
3895
3893
  constructor(restService, router, dialogRef, storageService, messageService) {
@@ -4591,9 +4589,10 @@ class OrderedItems {
4591
4589
  }
4592
4590
 
4593
4591
  class CartService {
4594
- constructor(storageService, restService) {
4592
+ constructor(storageService, restService, messageService) {
4595
4593
  this.storageService = storageService;
4596
4594
  this.restService = restService;
4595
+ this.messageService = messageService;
4597
4596
  }
4598
4597
  addItemFromCartPage(product, userCart) {
4599
4598
  if (product.quantity) {
@@ -4669,6 +4668,65 @@ class CartService {
4669
4668
  clearCartItems() {
4670
4669
  this.storageService.clearUserCart();
4671
4670
  }
4671
+ addItemToLocalCart(product, type) {
4672
+ if (this.isItemOutOfStock(product)) {
4673
+ this.messageService.add({ severity: 'warn', summary: 'Cart', detail: 'Item is not available as of now. We will notify you once available' });
4674
+ return;
4675
+ }
4676
+ if (!product?.quantity)
4677
+ product.quantity = 0;
4678
+ if (type == 'ADD') {
4679
+ product.quantity += 1;
4680
+ }
4681
+ else {
4682
+ product.quantity -= 1;
4683
+ }
4684
+ this.storageService.getUserCart().then((cartResponse) => {
4685
+ cartResponse.onsuccess = (cartData) => {
4686
+ const userCart = cartData.target.result ?? [];
4687
+ let orderedItem = new OrderedItems();
4688
+ if (product?.itemVariant?.length) {
4689
+ const itemVarient = this.getItemVarient(product, product.varientId);
4690
+ if (itemVarient) {
4691
+ itemVarient.quantity = product.quantity;
4692
+ orderedItem = this.objectMapper(product, itemVarient.variantId);
4693
+ }
4694
+ }
4695
+ else {
4696
+ orderedItem = this.objectMapper(product);
4697
+ }
4698
+ let productFound = false;
4699
+ for (let localProduct of userCart) {
4700
+ if (localProduct.varientId === product.varientId) {
4701
+ localProduct.quantity = type === 'ADD' ? localProduct.quantity + 1 : localProduct.quantity - 1;
4702
+ if (localProduct.quantity == 0) {
4703
+ this.removeItemFromCart(localProduct);
4704
+ }
4705
+ else {
4706
+ this.storageService.addProductToCart(localProduct);
4707
+ }
4708
+ productFound = true;
4709
+ break;
4710
+ }
4711
+ }
4712
+ if (!productFound) {
4713
+ orderedItem.quantity = type === 'ADD' ? 1 : -1;
4714
+ this.storageService.addProductToCart(orderedItem);
4715
+ }
4716
+ };
4717
+ });
4718
+ }
4719
+ isItemOutOfStock(product) {
4720
+ return product.itemInventory?.openingStock == 0;
4721
+ }
4722
+ getItemVarient(product, varientId) {
4723
+ let selectedVarient = null;
4724
+ product?.itemVariant?.forEach((varient) => {
4725
+ if (varient.variantId == varientId)
4726
+ selectedVarient = varient;
4727
+ });
4728
+ return selectedVarient;
4729
+ }
4672
4730
  storeDataToServer() {
4673
4731
  // const userCart = UserCart as never as Cart;
4674
4732
  // const userWishlist = UserFavourites as never as Cart;
@@ -4681,7 +4739,7 @@ class CartService {
4681
4739
  // this.restService.addItemToDB(UserFavourites)
4682
4740
  // ]);
4683
4741
  }
4684
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.1.4", ngImport: i0, type: CartService, deps: [{ token: StorageServiceService }, { token: RestService }], target: i0.ɵɵFactoryTarget.Injectable }); }
4742
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.1.4", ngImport: i0, type: CartService, deps: [{ token: StorageServiceService }, { token: RestService }, { token: i5$1.MessageService }], target: i0.ɵɵFactoryTarget.Injectable }); }
4685
4743
  static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "18.1.4", ngImport: i0, type: CartService, providedIn: 'root' }); }
4686
4744
  }
4687
4745
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.1.4", ngImport: i0, type: CartService, decorators: [{
@@ -4689,7 +4747,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.1.4", ngImpor
4689
4747
  args: [{
4690
4748
  providedIn: 'root',
4691
4749
  }]
4692
- }], ctorParameters: () => [{ type: StorageServiceService }, { type: RestService }] });
4750
+ }], ctorParameters: () => [{ type: StorageServiceService }, { type: RestService }, { type: i5$1.MessageService }] });
4693
4751
 
4694
4752
  class CartComponent extends BaseSection {
4695
4753
  constructor(_eventService, cartService, router, restService, matDialog, storageService, messageService, bottomSheet, matDialogData, dialogRef) {
@@ -4713,6 +4771,7 @@ class CartComponent extends BaseSection {
4713
4771
  this.enteredCouponCode = "";
4714
4772
  this.couponList = [];
4715
4773
  this.cartInfo = {
4774
+ cartId: localStorage.getItem("cartId"),
4716
4775
  orderedItems: null,
4717
4776
  businessId: localStorage.getItem("bId") ?? localStorage.getItem("businessId"),
4718
4777
  billdetails: {
@@ -4744,7 +4803,7 @@ class CartComponent extends BaseSection {
4744
4803
  // this.getIndexDBData();
4745
4804
  }
4746
4805
  });
4747
- this.getIndexDBData();
4806
+ this.updateUserCartV2();
4748
4807
  // if (this.storageService.getUser()) {
4749
4808
  // this.updateUserCart();
4750
4809
  // } else {
@@ -4840,6 +4899,49 @@ class CartComponent extends BaseSection {
4840
4899
  }
4841
4900
  });
4842
4901
  }
4902
+ updateUserCartV2() {
4903
+ this.storageService.getCartProduct().then((products) => {
4904
+ const deliveryOption = JSON.parse(localStorage.getItem("deliveryOptions") ?? "{}");
4905
+ this.cartInfo.orderedItems = products;
4906
+ if (!this.cartInfo?.cartId && !(localStorage.getItem("cartId") == "undefined" || localStorage.getItem("cartId") == "null")) {
4907
+ this.cartInfo['cartId'] = localStorage.getItem("cartId");
4908
+ }
4909
+ this.userDetails = this.storageService.getUser();
4910
+ if (this.userDetails) {
4911
+ this.getCouponList();
4912
+ this.cartInfo.userDetails = {
4913
+ "userId": this.userDetails?.userId,
4914
+ "userName": this.userDetails?.contact.name,
4915
+ "mobile": this.userDetails?.contact.mobile,
4916
+ "email": this.userDetails?.contact.email,
4917
+ };
4918
+ if (!(localStorage.getItem("couponId") == "undefined" || localStorage.getItem("couponId") == "null"))
4919
+ this.cartInfo.billdetails.couponId = localStorage.getItem("couponId");
4920
+ if (!(localStorage.getItem("couponCode") == "undefined" || localStorage.getItem("couponCode") == "null"))
4921
+ this.cartInfo.billdetails.couponCode = localStorage.getItem("couponCode");
4922
+ const restResponse = this.restService.addItemToDB(this.cartInfo).toPromise();
4923
+ restResponse.then((cartResponse) => {
4924
+ this.cartInfo = cartResponse.data;
4925
+ this.storageService.clearUserCart();
4926
+ });
4927
+ }
4928
+ else {
4929
+ this.cartInfo.billdetails.totalGrossValue = 0;
4930
+ this.cartInfo.billdetails.totalTax = 0;
4931
+ this.cartInfo.billdetails.deliveryCharges = 0;
4932
+ this.cartInfo.billdetails.totalNetValue = 0;
4933
+ this.cartInfo.totalAmount = 0;
4934
+ products.forEach((item) => {
4935
+ this.cartInfo.billdetails.totalGrossValue += (item.discountedPrice * (item.quantity ?? 1));
4936
+ this.cartInfo.billdetails.totalTax += (item.quantity * (item.itemTax ?? 0));
4937
+ });
4938
+ this.cartInfo.billdetails.deliveryCharges = (deliveryOption?.minOrderAmount > this.cartInfo.billdetails.totalGrossValue) ? 0 : (deliveryOption?.deliveryCharges ?? 0);
4939
+ this.cartInfo.billdetails.totalNetValue = this.cartInfo.billdetails.totalGrossValue - this.cartInfo.billdetails.deliveryCharges;
4940
+ this.cartInfo.totalAmount = this.cartInfo.billdetails.totalNetValue + this.getTaxAmount();
4941
+ +this.cartInfo.billdetails.deliveryCharges;
4942
+ }
4943
+ });
4944
+ }
4843
4945
  // updateUserCart2() {
4844
4946
  // const deliveryOption = JSON.parse(localStorage.getItem("deliveryOptions") ?? "{}");
4845
4947
  // this.userDetails = this.storageService.getUser() as User;
@@ -5351,7 +5453,7 @@ class NavbarSectionComponent {
5351
5453
  this.showEditors = false;
5352
5454
  this.showSearchBar = false;
5353
5455
  this.getScreenSize();
5354
- this.storageService.updateAllData();
5456
+ // this.storageService.updateAllData();
5355
5457
  }
5356
5458
  searchProducts() {
5357
5459
  this.router.navigate(['/list'], { queryParams: { searchTxt: this.searchText } });
@@ -7677,29 +7779,50 @@ class FeaturedProductsComponent extends BaseSection {
7677
7779
  this.apiLoading = true;
7678
7780
  this.restService.getFeaturedProduct(this.content?.collectionId).subscribe((response) => {
7679
7781
  this.responseData = response;
7680
- this.storageService.getUserCart().then((cartResponse) => {
7681
- cartResponse.onsuccess = (cartData) => {
7682
- this.apiLoading = false;
7683
- this.USER_CART = cartData.target.result;
7684
- this.responseData?.forEach((product) => {
7685
- this.USER_CART?.forEach((item) => {
7686
- if (item.itemId == product.itemId) {
7687
- if (product?.itemVariant?.length > 0) {
7688
- const itemVarient = product?.itemVariant?.[0];
7689
- if (itemVarient.variantId == item.varientId) {
7690
- product.itemImages = itemVarient.variantImages ?? [];
7691
- product.price = itemVarient.itemVariantPrice;
7692
- product.quantity = item.quantity;
7693
- }
7694
- }
7695
- else {
7782
+ // this.storageService.getUserCart().then((cartResponse) => {
7783
+ // cartResponse.onsuccess = (cartData: any) => {
7784
+ // this.apiLoading = false;
7785
+ // this.USER_CART = cartData.target.result as unknown as OrderedItems[];
7786
+ // this.responseData?.forEach((product: Product) => {
7787
+ // this.USER_CART?.forEach((item: OrderedItems) => {
7788
+ // if (item.itemId == product.itemId) {
7789
+ // if (product?.itemVariant?.length > 0) {
7790
+ // const itemVarient: ItemVariant = product?.itemVariant?.[0];
7791
+ // if (itemVarient.variantId == item.varientId) {
7792
+ // product.itemImages = itemVarient.variantImages ?? [];
7793
+ // product.price = itemVarient.itemVariantPrice;
7794
+ // product.quantity = item.quantity;
7795
+ // }
7796
+ // } else {
7797
+ // product.quantity = item.quantity;
7798
+ // }
7799
+ // }
7800
+ // })
7801
+ // })
7802
+ // }
7803
+ // },(err) => {
7804
+ // this.apiLoading = false;
7805
+ // })
7806
+ this.storageService.getCartProduct().then((products) => {
7807
+ this.apiLoading = false;
7808
+ this.responseData?.forEach((product) => {
7809
+ products?.forEach((item) => {
7810
+ if (item.itemId == product.itemId) {
7811
+ if (product?.itemVariant?.length > 0) {
7812
+ const itemVarient = product?.itemVariant?.[0];
7813
+ if (itemVarient.variantId == item.varientId) {
7814
+ product.itemImages = itemVarient.variantImages ?? [];
7815
+ product.price = itemVarient.itemVariantPrice;
7696
7816
  product.quantity = item.quantity;
7697
7817
  }
7698
7818
  }
7699
- });
7819
+ else {
7820
+ product.quantity = item.quantity;
7821
+ }
7822
+ }
7700
7823
  });
7701
- };
7702
- }, (err) => {
7824
+ });
7825
+ }).catch(err => {
7703
7826
  this.apiLoading = false;
7704
7827
  });
7705
7828
  this.storageService.getUserWhishlist().then((wishlistResponse) => {
@@ -7727,43 +7850,44 @@ class FeaturedProductsComponent extends BaseSection {
7727
7850
  });
7728
7851
  }
7729
7852
  addItemToCart(product, type) {
7730
- if (this.isItemOutOfStock(product)) {
7731
- this.messageService.add({ severity: 'warn', summary: 'Cart', detail: 'Item is not available as of now. We will notify you once available' });
7732
- return;
7733
- }
7734
- if (!product?.quantity)
7735
- product.quantity = 0;
7736
- if (type == 'ADD') {
7737
- product.quantity += 1;
7738
- }
7739
- else {
7740
- product.quantity -= 1;
7741
- }
7742
- if (product?.itemVariant?.length) {
7743
- const itemVarient = this.getItemVarient(product, product.varientId);
7744
- if (itemVarient) {
7745
- itemVarient.quantity = product.quantity;
7746
- this.cartService.addItemToCart(product, itemVarient.variantId);
7747
- }
7748
- }
7749
- else {
7750
- this.cartService.addItemToCart(product);
7751
- }
7752
- if (product.quantity) {
7753
- let isPresent = false;
7754
- this.USER_CART?.forEach((item) => {
7755
- if (item.varientId == product.varientId) {
7756
- item.quantity = product.quantity;
7757
- isPresent = true;
7758
- }
7759
- });
7760
- if (!isPresent)
7761
- this.USER_CART?.push(new OrderedItems(product, product.varientId));
7762
- }
7763
- else {
7764
- this.USER_CART = this.USER_CART?.filter((item) => item.varientId != product.varientId) ?? [];
7765
- }
7853
+ this.cartService.addItemToLocalCart(product, type);
7766
7854
  }
7855
+ // addItemToCart(product: Product, type: 'ADD' | 'SUBSTRACT') {
7856
+ // if (this.isItemOutOfStock(product)) {
7857
+ // this.messageService.add({ severity: 'warn', summary: 'Cart', detail: 'Item is not available as of now. We will notify you once available' });
7858
+ // return;
7859
+ // }
7860
+ // if (!product?.quantity)
7861
+ // product.quantity = 0;
7862
+ // if (type == 'ADD') {
7863
+ // product.quantity += 1;
7864
+ // }
7865
+ // else {
7866
+ // product.quantity -= 1;
7867
+ // }
7868
+ // if (product?.itemVariant?.length) {
7869
+ // const itemVarient: ItemVariant | null = this.getItemVarient(product, product.varientId);
7870
+ // if (itemVarient) {
7871
+ // itemVarient.quantity = product.quantity;
7872
+ // this.cartService.addItemToCart(product, itemVarient.variantId);
7873
+ // }
7874
+ // } else {
7875
+ // this.cartService.addItemToCart(product);
7876
+ // }
7877
+ // if (product.quantity) {
7878
+ // let isPresent: boolean = false;
7879
+ // this.USER_CART?.forEach((item: OrderedItems) => {
7880
+ // if (item.varientId == product.varientId) {
7881
+ // item.quantity = product.quantity;
7882
+ // isPresent = true;
7883
+ // }
7884
+ // })
7885
+ // if (!isPresent)
7886
+ // this.USER_CART?.push(new OrderedItems(product, product.varientId));
7887
+ // } else {
7888
+ // this.USER_CART = this.USER_CART?.filter((item: OrderedItems) => item.varientId != product.varientId) ?? [];
7889
+ // }
7890
+ // }
7767
7891
  toggleItemToFav(event, product, type) {
7768
7892
  if (type == 'ADD') {
7769
7893
  product.whislist = true;