simpo-component-library 1.4.49 → 1.4.51

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.
@@ -3227,6 +3227,7 @@ class StorageServiceService {
3227
3227
  this.eventService = eventService;
3228
3228
  this.cookieService = cookieService;
3229
3229
  this.restService = restService;
3230
+ this.totalCartItems = 0;
3230
3231
  this.databaseName = "USER";
3231
3232
  this.databaseVersion = 1;
3232
3233
  this.cartCollectionName = "USER_CART";
@@ -3237,6 +3238,9 @@ class StorageServiceService {
3237
3238
  this.userCollectionRef = null;
3238
3239
  this.createDataBase();
3239
3240
  }
3241
+ get getTotalCartItems() {
3242
+ return this.totalCartItems;
3243
+ }
3240
3244
  async createDataBase() {
3241
3245
  const request = await window.indexedDB.open(this.databaseName, 1);
3242
3246
  this.eventService.showLoadingScreen.emit(true);
@@ -3314,10 +3318,12 @@ class StorageServiceService {
3314
3318
  return await transaction.objectStore(this.cartCollectionName).getAll();
3315
3319
  }
3316
3320
  addProductToCart(product) {
3321
+ this.totalCartItems += 1;
3317
3322
  const transaction = this.database.transaction(this.cartCollectionName, "readwrite");
3318
3323
  return transaction.objectStore(this.cartCollectionName).put(product);
3319
3324
  }
3320
3325
  removeProductFromCart(productId) {
3326
+ this.totalCartItems -= 1;
3321
3327
  const transaction = this.database.transaction(this.cartCollectionName, "readwrite");
3322
3328
  return transaction.objectStore(this.cartCollectionName).delete(productId);
3323
3329
  }
@@ -3596,7 +3602,7 @@ class NavbarSectionComponent {
3596
3602
  }, 100);
3597
3603
  }
3598
3604
  get getCartItemsCount() {
3599
- return 0;
3605
+ return this.storageService.getTotalCartItems;
3600
3606
  }
3601
3607
  getKeys(object) {
3602
3608
  return Object.keys(object);
@@ -4945,7 +4951,7 @@ class FeaturedProductsComponent extends BaseSection {
4945
4951
  this.storageService.getUserCart().then((cartResponse) => {
4946
4952
  cartResponse.onsuccess = (cartData) => {
4947
4953
  console.log(cartData);
4948
- this.USER_CART = cartData;
4954
+ this.USER_CART = cartData.target.result;
4949
4955
  console.log(this.USER_CART);
4950
4956
  console.log(this.responseData);
4951
4957
  this.responseData?.forEach((product) => {
@@ -4958,7 +4964,7 @@ class FeaturedProductsComponent extends BaseSection {
4958
4964
  });
4959
4965
  this.storageService.getUserWhishlist().then((wishlistResponse) => {
4960
4966
  wishlistResponse.onsuccess = (whislistData) => {
4961
- this.USER_WISHLIST = whislistData;
4967
+ this.USER_WISHLIST = whislistData.target.result;
4962
4968
  this.responseData?.forEach((product) => {
4963
4969
  this.USER_WISHLIST?.forEach((item) => {
4964
4970
  if (item.itemId == product.itemId)
@@ -5138,7 +5144,7 @@ class ProductDescComponent extends BaseSection {
5138
5144
  this.responseData.quantity = 0;
5139
5145
  this.storageService.getUserCart().then((cartResponse) => {
5140
5146
  cartResponse.onsuccess = (cartData) => {
5141
- this.USER_CART = cartData;
5147
+ this.USER_CART = cartData.target.result;
5142
5148
  this.USER_CART?.forEach((item) => {
5143
5149
  if (item.itemId == productId)
5144
5150
  this.responseData.quantity = item.quantity;
@@ -5147,7 +5153,7 @@ class ProductDescComponent extends BaseSection {
5147
5153
  });
5148
5154
  this.storageService.getUserWhishlist().then((wishlistResponse) => {
5149
5155
  wishlistResponse.onsuccess = (whislistData) => {
5150
- this.USER_WISHLIST = whislistData;
5156
+ this.USER_WISHLIST = whislistData.target.result;
5151
5157
  this.USER_WISHLIST?.forEach((item) => {
5152
5158
  if (item.itemId == productId)
5153
5159
  this.isItemAsFavorite = true;
@@ -5405,7 +5411,7 @@ class ProductListComponent extends BaseSection {
5405
5411
  this.responseData = response.data.data;
5406
5412
  this.storageService.getUserCart().then((cartResponse) => {
5407
5413
  cartResponse.onsuccess = (cartData) => {
5408
- this.USER_CART = cartData;
5414
+ this.USER_CART = cartData.target.result;
5409
5415
  this.responseData?.forEach((product) => {
5410
5416
  this.USER_CART?.forEach((item) => {
5411
5417
  if (item.itemId == product.itemId)
@@ -5416,7 +5422,7 @@ class ProductListComponent extends BaseSection {
5416
5422
  });
5417
5423
  this.storageService.getUserWhishlist().then((wishlistResponse) => {
5418
5424
  wishlistResponse.onsuccess = (whislistData) => {
5419
- this.USER_WISHLIST = whislistData;
5425
+ this.USER_WISHLIST = whislistData.target.result;
5420
5426
  this.responseData?.forEach((product) => {
5421
5427
  this.USER_WISHLIST?.forEach((item) => {
5422
5428
  if (item.itemId == product.itemId)
@@ -5660,33 +5666,24 @@ class CartComponent extends BaseSection {
5660
5666
  });
5661
5667
  if (this.storageService.getUser()) {
5662
5668
  this.userDetails = this.storageService.getUser();
5669
+ this.restService.getUserItems(this.userDetails.userId, "CART").subscribe((response) => {
5670
+ const tempUserCart = response?.data?.orderedItems ?? [];
5671
+ this.storageService.getUserCart().then((cartResponse) => {
5672
+ cartResponse.onsuccess = (cartData) => {
5673
+ this.USER_CART_ITEMS = cartData.target.result;
5674
+ this.responseData = [...tempUserCart, ...this.USER_CART_ITEMS];
5675
+ };
5676
+ });
5677
+ });
5678
+ }
5679
+ else {
5663
5680
  this.storageService.getUserCart().then((cartResponse) => {
5664
5681
  cartResponse.onsuccess = (cartData) => {
5665
- this.USER_CART_ITEMS = cartData;
5682
+ this.USER_CART_ITEMS = cartData.target.result;
5666
5683
  this.responseData = this.USER_CART_ITEMS;
5667
- if (this.userCart) {
5668
- this.userCart.orderedItems = this.USER_CART_ITEMS;
5669
- this.userCart.cartId = this.cookieService.get("cartId") ?? null;
5670
- this.restService.addItemToDB(this.userCart).subscribe((response) => { });
5671
- }
5672
5684
  };
5673
5685
  });
5674
- // console.log("user deatils", userDetails);
5675
- // UserInfo.user.addressDetailsList = userDetails.addressDetailsList as never;
5676
- // UserCart.userDetails = {...UserCart.userDetails, ...UserInfo.user.contact, userId: userDetails.userId};
5677
- // this.cartService.storeDataToServer().subscribe((response: any)=> {
5678
- // console.log("a: ", UserCart, this.responseData, response);
5679
- // if (response[0].data) {
5680
- // UserCart.billdetails = response[0].data.billdetails;
5681
- // UserCart.cartId = response[0].data.cartId;
5682
- // UserCart.orderedItems = response[0].data.orderedItems;
5683
- // }
5684
- // console.log("a: ", UserCart, this.responseData, response);
5685
- // this.responseData = this.storageService.calculateBillingDetails();
5686
- // })
5687
- }
5688
- else {
5689
- this.responseData = this.storageService.calculateBillingDetails();
5686
+ // this.responseData = this.storageService.calculateBillingDetails();
5690
5687
  console.log(this.responseData);
5691
5688
  }
5692
5689
  this.styles = this.data?.styles;