simpo-component-library 1.8.9991 → 1.8.9993

Sign up to get free protection for your applications and to get access to all the features.
@@ -3709,7 +3709,6 @@ class StorageServiceService {
3709
3709
  this.restService.addItemToDB(userCart).subscribe((res) => {
3710
3710
  if (res?.data?.cartId && !localStorage.getItem('cartId'))
3711
3711
  localStorage.setItem('cartId', res.data.cartId);
3712
- this.clearUserCart();
3713
3712
  });
3714
3713
  };
3715
3714
  });
@@ -3882,7 +3881,7 @@ class AuthenticationRequiredComponent {
3882
3881
  const userDetails = this.storageService.setUser(response.data);
3883
3882
  this.storageService.updateAllData();
3884
3883
  this.buttonLoading = false;
3885
- this.dialogRef.close();
3884
+ this.dialogRef.close('success');
3886
3885
  }, (error) => {
3887
3886
  this.buttonLoading = false;
3888
3887
  this.messageService.add({ severity: 'error', summary: 'Login request', detail: error?.error?.message });
@@ -3896,7 +3895,7 @@ class AuthenticationRequiredComponent {
3896
3895
  this.restService.verifyOTP(this.mobile ?? "", this.otp, deviceInfo).subscribe((response) => {
3897
3896
  const userDetails = this.storageService.setUser(response.data);
3898
3897
  this.storageService.updateAllData();
3899
- this.dialogRef.close();
3898
+ this.dialogRef.close('success');
3900
3899
  }, (error) => {
3901
3900
  this.buttonLoading = false;
3902
3901
  this.messageService.add({ severity: 'error', summary: "Login request", detail: error?.error?.message });
@@ -3943,7 +3942,7 @@ class AuthenticationRequiredComponent {
3943
3942
  this.restService.verifySignupOTP(verifySignData).subscribe((response) => {
3944
3943
  const userDetails = this.storageService.setUser(response.data);
3945
3944
  this.storageService.updateAllData();
3946
- this.dialogRef.close();
3945
+ this.dialogRef.close('success');
3947
3946
  this.buttonLoading = false;
3948
3947
  Swal.fire({
3949
3948
  icon: "success",
@@ -4585,7 +4584,6 @@ class CartComponent extends BaseSection {
4585
4584
  this.couponDialogRef = null;
4586
4585
  }
4587
4586
  ngOnInit() {
4588
- const deliveryOption = JSON.parse(localStorage.getItem("deliveryOptions") ?? "{}");
4589
4587
  this._eventService.showLoadingScreen.subscribe((response) => {
4590
4588
  this.isLoading = response;
4591
4589
  if (!this.isLoading) {
@@ -4593,84 +4591,7 @@ class CartComponent extends BaseSection {
4593
4591
  }
4594
4592
  });
4595
4593
  if (this.storageService.getUser()) {
4596
- this.userDetails = this.storageService.getUser();
4597
- this.cartInfo.userDetails = {
4598
- "userId": this.userDetails?.userId,
4599
- "userName": this.userDetails?.contact.name,
4600
- "mobile": this.userDetails?.contact.mobile,
4601
- "email": this.userDetails?.contact.email,
4602
- };
4603
- this.restService.getUserItems(this.userDetails.userId, "CART").subscribe((response) => {
4604
- const tempUserCart = response?.data?.[0]?.orderedItems ?? [];
4605
- localStorage.setItem('cartId', response.data?.[0]?.cartId);
4606
- this.cartInfo["cartId"] = response.data?.[0]?.cartId;
4607
- this.getCouponList();
4608
- if (response.data?.[0]?.orderedItems?.length > 0) {
4609
- this.storageService.addAllProductsToCart(tempUserCart).oncomplete = () => {
4610
- this.storageService.getUserCart().then((cartResponse) => {
4611
- cartResponse.onsuccess = (cartData) => {
4612
- if (!(localStorage.getItem("couponId") == "undefined" || localStorage.getItem("couponId") == "null"))
4613
- this.cartInfo.billdetails.couponId = localStorage.getItem("couponId");
4614
- if (!(localStorage.getItem("couponCode") == "undefined" || localStorage.getItem("couponCode") == "null"))
4615
- this.cartInfo.billdetails.couponCode = localStorage.getItem("couponCode");
4616
- const restResponse = this.restService.addItemToDB(this.cartInfo).toPromise();
4617
- restResponse.then((response) => {
4618
- this.cartInfo.billdetails.totalGrossValue = 0;
4619
- this.cartInfo.billdetails.totalTax = 0;
4620
- this.cartInfo.billdetails.deliveryCharges = 0;
4621
- this.cartInfo.billdetails.totalNetValue = 0;
4622
- this.cartInfo.totalAmount = 0;
4623
- this.USER_CART_ITEMS = cartData.target.result;
4624
- this.USER_CART_ITEMS.forEach((item) => {
4625
- this.cartInfo.billdetails.totalGrossValue += (item.discountedPrice * (item.quantity ?? 1));
4626
- this.cartInfo.billdetails.totalTax += (item.quantity * (item.itemTax ?? 0));
4627
- });
4628
- this.cartInfo.billdetails.deliveryCharges = (deliveryOption?.minOrderAmount > this.cartInfo.billdetails.totalGrossValue) ? 0 : (deliveryOption?.deliveryCharges ?? 0);
4629
- this.cartInfo.billdetails.totalNetValue = this.cartInfo.billdetails.totalGrossValue;
4630
- this.cartInfo.orderedItems = this.USER_CART_ITEMS;
4631
- this.cartInfo.billdetails.discountAmount = response?.data?.billdetails?.discountAmount ?? 0;
4632
- this.cartInfo.billdetails.totalTaxAfterDiscount = response?.data?.billdetails?.totalTaxAfterDiscount ?? 0;
4633
- this.cartInfo.totalAmount = this.cartInfo.billdetails.totalNetValue + this.getTaxAmount() + this.cartInfo.billdetails.deliveryCharges;
4634
- this.responseData = this.cartInfo;
4635
- console.log(this.responseData);
4636
- });
4637
- };
4638
- cartResponse.onerror = (cartData) => {
4639
- this.messageService.add({ severity: 'error', summary: 'Error', detail: 'Failed to update cart details' });
4640
- };
4641
- });
4642
- };
4643
- }
4644
- else {
4645
- this.storageService.getUserCart().then((cartResponse) => {
4646
- cartResponse.onsuccess = (cartData) => {
4647
- this.USER_CART_ITEMS = cartData.target.result;
4648
- this.cartInfo.billdetails.totalGrossValue = 0;
4649
- this.cartInfo.billdetails.totalTax = 0;
4650
- this.cartInfo.billdetails.totalTaxAfterDiscount = cartData.billdetails?.totalTaxAfterDiscount ?? 0;
4651
- this.cartInfo.billdetails.deliveryCharges = 0;
4652
- this.cartInfo.billdetails.totalNetValue = 0;
4653
- this.cartInfo.totalAmount = 0;
4654
- this.USER_CART_ITEMS.forEach((item) => {
4655
- this.cartInfo.billdetails.totalGrossValue += (item.discountedPrice * (item.quantity ?? 1));
4656
- this.cartInfo.billdetails.totalTax += (item.quantity * (item.itemTax ?? 0));
4657
- });
4658
- this.cartInfo.billdetails.deliveryCharges = (deliveryOption?.minOrderAmount > this.cartInfo.billdetails.totalGrossValue) ? 0 : (deliveryOption?.deliveryCharges ?? 0);
4659
- this.cartInfo.billdetails.totalNetValue = this.cartInfo.billdetails.totalGrossValue - this.cartInfo.billdetails.deliveryCharges;
4660
- console.log(this.cartInfo.billdetails.totalNetValue, this.cartInfo.billdetails.totalTax, this.cartInfo.billdetails.deliveryCharges);
4661
- this.cartInfo.totalAmount = this.cartInfo.billdetails.totalNetValue + this.getTaxAmount();
4662
- +this.cartInfo.billdetails.deliveryCharges;
4663
- this.cartInfo.orderedItems = this.USER_CART_ITEMS;
4664
- this.responseData = this.cartInfo;
4665
- this.restService.addItemToDB(this.responseData).subscribe((response) => {
4666
- localStorage.setItem('cartId', response.data?.cartId);
4667
- this.cartInfo["cartId"] = response.data?.cartId;
4668
- this.responseData["cartId"] = this.cartInfo["cartId"];
4669
- });
4670
- };
4671
- });
4672
- }
4673
- });
4594
+ this.updateUserCart();
4674
4595
  }
4675
4596
  else {
4676
4597
  this.getIndexDBData();
@@ -4679,6 +4600,87 @@ class CartComponent extends BaseSection {
4679
4600
  console.log(this.responseData);
4680
4601
  this.styles = this.data?.styles;
4681
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
+ }
4682
4684
  getCouponList() {
4683
4685
  if (!this.cartInfo.cartId && !(localStorage.getItem("cartId") == "undefined" || localStorage.getItem("cartId") == "null"))
4684
4686
  this.cartInfo.cartId = localStorage.getItem("cartId");
@@ -4758,8 +4760,10 @@ class CartComponent extends BaseSection {
4758
4760
  if (!(localStorage.getItem("cartId") == "undefined" || localStorage.getItem("cartId") == "null"))
4759
4761
  this.cartInfo["cartId"] = localStorage.getItem("cartId");
4760
4762
  console.log("Response : ", response);
4761
- if (response)
4762
- this.proceedToCheckout();
4763
+ if (response && response === 'success') {
4764
+ this.updateUserCart();
4765
+ // this.proceedToCheckout();
4766
+ }
4763
4767
  });
4764
4768
  // if (window.innerWidth <= 475) {
4765
4769
  // this.bottomSheet.open(AuthenticateUserComponent, {data: this.data}).afterDismissed().subscribe((response)=> {
@@ -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
  });