simpo-component-library 1.8.9992 → 1.8.9993

Sign up to get free protection for your applications and to get access to all the features.
@@ -3706,7 +3706,10 @@ class StorageServiceService {
3706
3706
  userCartResponse.onsuccess = (userCartIndexDB) => {
3707
3707
  userCart.orderedItems = [...(userCartIndexDB.target.result ?? []), ...(userCart?.orderedItems ?? [])];
3708
3708
  this.addAllProductsToCart(userCart.orderedItems);
3709
- this.restService.addItemToDB(userCart);
3709
+ this.restService.addItemToDB(userCart).subscribe((res) => {
3710
+ if (res?.data?.cartId && !localStorage.getItem('cartId'))
3711
+ localStorage.setItem('cartId', res.data.cartId);
3712
+ });
3710
3713
  };
3711
3714
  });
3712
3715
  const userWishlist = cartResponse?.[1].data;
@@ -4581,7 +4584,6 @@ class CartComponent extends BaseSection {
4581
4584
  this.couponDialogRef = null;
4582
4585
  }
4583
4586
  ngOnInit() {
4584
- const deliveryOption = JSON.parse(localStorage.getItem("deliveryOptions") ?? "{}");
4585
4587
  this._eventService.showLoadingScreen.subscribe((response) => {
4586
4588
  this.isLoading = response;
4587
4589
  if (!this.isLoading) {
@@ -4589,84 +4591,7 @@ class CartComponent extends BaseSection {
4589
4591
  }
4590
4592
  });
4591
4593
  if (this.storageService.getUser()) {
4592
- this.userDetails = this.storageService.getUser();
4593
- this.cartInfo.userDetails = {
4594
- "userId": this.userDetails?.userId,
4595
- "userName": this.userDetails?.contact.name,
4596
- "mobile": this.userDetails?.contact.mobile,
4597
- "email": this.userDetails?.contact.email,
4598
- };
4599
- this.restService.getUserItems(this.userDetails.userId, "CART").subscribe((response) => {
4600
- const tempUserCart = response?.data?.[0]?.orderedItems ?? [];
4601
- localStorage.setItem('cartId', response.data?.[0]?.cartId);
4602
- this.cartInfo["cartId"] = response.data?.[0]?.cartId;
4603
- this.getCouponList();
4604
- if (response.data?.[0]?.orderedItems?.length > 0) {
4605
- this.storageService.addAllProductsToCart(tempUserCart).oncomplete = () => {
4606
- this.storageService.getUserCart().then((cartResponse) => {
4607
- cartResponse.onsuccess = (cartData) => {
4608
- if (!(localStorage.getItem("couponId") == "undefined" || localStorage.getItem("couponId") == "null"))
4609
- this.cartInfo.billdetails.couponId = localStorage.getItem("couponId");
4610
- if (!(localStorage.getItem("couponCode") == "undefined" || localStorage.getItem("couponCode") == "null"))
4611
- this.cartInfo.billdetails.couponCode = localStorage.getItem("couponCode");
4612
- const restResponse = this.restService.addItemToDB(this.cartInfo).toPromise();
4613
- restResponse.then((response) => {
4614
- this.cartInfo.billdetails.totalGrossValue = 0;
4615
- this.cartInfo.billdetails.totalTax = 0;
4616
- this.cartInfo.billdetails.deliveryCharges = 0;
4617
- this.cartInfo.billdetails.totalNetValue = 0;
4618
- this.cartInfo.totalAmount = 0;
4619
- this.USER_CART_ITEMS = cartData.target.result;
4620
- this.USER_CART_ITEMS.forEach((item) => {
4621
- this.cartInfo.billdetails.totalGrossValue += (item.discountedPrice * (item.quantity ?? 1));
4622
- this.cartInfo.billdetails.totalTax += (item.quantity * (item.itemTax ?? 0));
4623
- });
4624
- this.cartInfo.billdetails.deliveryCharges = (deliveryOption?.minOrderAmount > this.cartInfo.billdetails.totalGrossValue) ? 0 : (deliveryOption?.deliveryCharges ?? 0);
4625
- this.cartInfo.billdetails.totalNetValue = this.cartInfo.billdetails.totalGrossValue;
4626
- this.cartInfo.orderedItems = this.USER_CART_ITEMS;
4627
- this.cartInfo.billdetails.discountAmount = response?.data?.billdetails?.discountAmount ?? 0;
4628
- this.cartInfo.billdetails.totalTaxAfterDiscount = response?.data?.billdetails?.totalTaxAfterDiscount ?? 0;
4629
- this.cartInfo.totalAmount = this.cartInfo.billdetails.totalNetValue + this.getTaxAmount() + this.cartInfo.billdetails.deliveryCharges;
4630
- this.responseData = this.cartInfo;
4631
- console.log(this.responseData);
4632
- });
4633
- };
4634
- cartResponse.onerror = (cartData) => {
4635
- this.messageService.add({ severity: 'error', summary: 'Error', detail: 'Failed to update cart details' });
4636
- };
4637
- });
4638
- };
4639
- }
4640
- else {
4641
- this.storageService.getUserCart().then((cartResponse) => {
4642
- cartResponse.onsuccess = (cartData) => {
4643
- this.USER_CART_ITEMS = cartData.target.result;
4644
- this.cartInfo.billdetails.totalGrossValue = 0;
4645
- this.cartInfo.billdetails.totalTax = 0;
4646
- this.cartInfo.billdetails.totalTaxAfterDiscount = cartData.billdetails?.totalTaxAfterDiscount ?? 0;
4647
- this.cartInfo.billdetails.deliveryCharges = 0;
4648
- this.cartInfo.billdetails.totalNetValue = 0;
4649
- this.cartInfo.totalAmount = 0;
4650
- this.USER_CART_ITEMS.forEach((item) => {
4651
- this.cartInfo.billdetails.totalGrossValue += (item.discountedPrice * (item.quantity ?? 1));
4652
- this.cartInfo.billdetails.totalTax += (item.quantity * (item.itemTax ?? 0));
4653
- });
4654
- this.cartInfo.billdetails.deliveryCharges = (deliveryOption?.minOrderAmount > this.cartInfo.billdetails.totalGrossValue) ? 0 : (deliveryOption?.deliveryCharges ?? 0);
4655
- this.cartInfo.billdetails.totalNetValue = this.cartInfo.billdetails.totalGrossValue - this.cartInfo.billdetails.deliveryCharges;
4656
- console.log(this.cartInfo.billdetails.totalNetValue, this.cartInfo.billdetails.totalTax, this.cartInfo.billdetails.deliveryCharges);
4657
- this.cartInfo.totalAmount = this.cartInfo.billdetails.totalNetValue + this.getTaxAmount();
4658
- +this.cartInfo.billdetails.deliveryCharges;
4659
- this.cartInfo.orderedItems = this.USER_CART_ITEMS;
4660
- this.responseData = this.cartInfo;
4661
- this.restService.addItemToDB(this.responseData).subscribe((response) => {
4662
- localStorage.setItem('cartId', response.data?.cartId);
4663
- this.cartInfo["cartId"] = response.data?.cartId;
4664
- this.responseData["cartId"] = this.cartInfo["cartId"];
4665
- });
4666
- };
4667
- });
4668
- }
4669
- });
4594
+ this.updateUserCart();
4670
4595
  }
4671
4596
  else {
4672
4597
  this.getIndexDBData();
@@ -4675,6 +4600,87 @@ class CartComponent extends BaseSection {
4675
4600
  console.log(this.responseData);
4676
4601
  this.styles = this.data?.styles;
4677
4602
  }
4603
+ updateUserCart() {
4604
+ const deliveryOption = JSON.parse(localStorage.getItem("deliveryOptions") ?? "{}");
4605
+ this.userDetails = this.storageService.getUser();
4606
+ this.cartInfo.userDetails = {
4607
+ "userId": this.userDetails?.userId,
4608
+ "userName": this.userDetails?.contact.name,
4609
+ "mobile": this.userDetails?.contact.mobile,
4610
+ "email": this.userDetails?.contact.email,
4611
+ };
4612
+ this.restService.getUserItems(this.userDetails.userId, "CART").subscribe((response) => {
4613
+ const tempUserCart = response?.data?.[0]?.orderedItems ?? [];
4614
+ localStorage.setItem('cartId', response.data?.[0]?.cartId);
4615
+ this.cartInfo["cartId"] = response.data?.[0]?.cartId;
4616
+ this.getCouponList();
4617
+ if (response.data?.[0]?.orderedItems?.length > 0) {
4618
+ this.storageService.addAllProductsToCart(tempUserCart).oncomplete = () => {
4619
+ this.storageService.getUserCart().then((cartResponse) => {
4620
+ cartResponse.onsuccess = (cartData) => {
4621
+ if (!(localStorage.getItem("couponId") == "undefined" || localStorage.getItem("couponId") == "null"))
4622
+ this.cartInfo.billdetails.couponId = localStorage.getItem("couponId");
4623
+ if (!(localStorage.getItem("couponCode") == "undefined" || localStorage.getItem("couponCode") == "null"))
4624
+ this.cartInfo.billdetails.couponCode = localStorage.getItem("couponCode");
4625
+ const restResponse = this.restService.addItemToDB(this.cartInfo).toPromise();
4626
+ restResponse.then((response) => {
4627
+ this.cartInfo.billdetails.totalGrossValue = 0;
4628
+ this.cartInfo.billdetails.totalTax = 0;
4629
+ this.cartInfo.billdetails.deliveryCharges = 0;
4630
+ this.cartInfo.billdetails.totalNetValue = 0;
4631
+ this.cartInfo.totalAmount = 0;
4632
+ this.USER_CART_ITEMS = cartData.target.result;
4633
+ this.USER_CART_ITEMS.forEach((item) => {
4634
+ this.cartInfo.billdetails.totalGrossValue += (item.discountedPrice * (item.quantity ?? 1));
4635
+ this.cartInfo.billdetails.totalTax += (item.quantity * (item.itemTax ?? 0));
4636
+ });
4637
+ this.cartInfo.billdetails.deliveryCharges = (deliveryOption?.minOrderAmount > this.cartInfo.billdetails.totalGrossValue) ? 0 : (deliveryOption?.deliveryCharges ?? 0);
4638
+ this.cartInfo.billdetails.totalNetValue = this.cartInfo.billdetails.totalGrossValue;
4639
+ this.cartInfo.orderedItems = this.USER_CART_ITEMS;
4640
+ this.cartInfo.billdetails.discountAmount = response?.data?.billdetails?.discountAmount ?? 0;
4641
+ this.cartInfo.billdetails.totalTaxAfterDiscount = response?.data?.billdetails?.totalTaxAfterDiscount ?? 0;
4642
+ this.cartInfo.totalAmount = this.cartInfo.billdetails.totalNetValue + this.getTaxAmount() + this.cartInfo.billdetails.deliveryCharges;
4643
+ this.responseData = this.cartInfo;
4644
+ console.log(this.responseData);
4645
+ });
4646
+ };
4647
+ cartResponse.onerror = (cartData) => {
4648
+ this.messageService.add({ severity: 'error', summary: 'Error', detail: 'Failed to update cart details' });
4649
+ };
4650
+ });
4651
+ };
4652
+ }
4653
+ else {
4654
+ this.storageService.getUserCart().then((cartResponse) => {
4655
+ cartResponse.onsuccess = (cartData) => {
4656
+ this.USER_CART_ITEMS = cartData.target.result;
4657
+ this.cartInfo.billdetails.totalGrossValue = 0;
4658
+ this.cartInfo.billdetails.totalTax = 0;
4659
+ this.cartInfo.billdetails.totalTaxAfterDiscount = cartData.billdetails?.totalTaxAfterDiscount ?? 0;
4660
+ this.cartInfo.billdetails.deliveryCharges = 0;
4661
+ this.cartInfo.billdetails.totalNetValue = 0;
4662
+ this.cartInfo.totalAmount = 0;
4663
+ this.USER_CART_ITEMS.forEach((item) => {
4664
+ this.cartInfo.billdetails.totalGrossValue += (item.discountedPrice * (item.quantity ?? 1));
4665
+ this.cartInfo.billdetails.totalTax += (item.quantity * (item.itemTax ?? 0));
4666
+ });
4667
+ this.cartInfo.billdetails.deliveryCharges = (deliveryOption?.minOrderAmount > this.cartInfo.billdetails.totalGrossValue) ? 0 : (deliveryOption?.deliveryCharges ?? 0);
4668
+ this.cartInfo.billdetails.totalNetValue = this.cartInfo.billdetails.totalGrossValue - this.cartInfo.billdetails.deliveryCharges;
4669
+ console.log(this.cartInfo.billdetails.totalNetValue, this.cartInfo.billdetails.totalTax, this.cartInfo.billdetails.deliveryCharges);
4670
+ this.cartInfo.totalAmount = this.cartInfo.billdetails.totalNetValue + this.getTaxAmount();
4671
+ +this.cartInfo.billdetails.deliveryCharges;
4672
+ this.cartInfo.orderedItems = this.USER_CART_ITEMS;
4673
+ this.responseData = this.cartInfo;
4674
+ this.restService.addItemToDB(this.responseData).subscribe((response) => {
4675
+ localStorage.setItem('cartId', response.data?.cartId);
4676
+ this.cartInfo["cartId"] = response.data?.cartId;
4677
+ this.responseData["cartId"] = this.cartInfo["cartId"];
4678
+ });
4679
+ };
4680
+ });
4681
+ }
4682
+ });
4683
+ }
4678
4684
  getCouponList() {
4679
4685
  if (!this.cartInfo.cartId && !(localStorage.getItem("cartId") == "undefined" || localStorage.getItem("cartId") == "null"))
4680
4686
  this.cartInfo.cartId = localStorage.getItem("cartId");
@@ -4755,10 +4761,8 @@ class CartComponent extends BaseSection {
4755
4761
  this.cartInfo["cartId"] = localStorage.getItem("cartId");
4756
4762
  console.log("Response : ", response);
4757
4763
  if (response && response === 'success') {
4758
- this.restService.getUserItems(this.userDetails?.userId || '', "CART").subscribe((res) => {
4759
- localStorage.setItem('cartId', response.data?.[0]?.cartId);
4760
- this.proceedToCheckout();
4761
- });
4764
+ this.updateUserCart();
4765
+ // this.proceedToCheckout();
4762
4766
  }
4763
4767
  });
4764
4768
  // if (window.innerWidth <= 475) {
@@ -9519,6 +9523,7 @@ class UserProfileComponent extends BaseSection {
9519
9523
  if (response.isConfirmed) {
9520
9524
  this.cookieService.delete("user");
9521
9525
  localStorage.removeItem("perId");
9526
+ localStorage.removeItem('cartId');
9522
9527
  this.router.navigate(['/']);
9523
9528
  }
9524
9529
  });