simpo-component-library 2.0.18 → 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;
@@ -3878,7 +3879,7 @@ class StorageServiceService {
3878
3879
  storePaymentFor(paymentFor) {
3879
3880
  this.cookieService.set("paymentFor", paymentFor, 7);
3880
3881
  }
3881
- 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 }); }
3882
3883
  static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "18.1.4", ngImport: i0, type: StorageServiceService, providedIn: 'root' }); }
3883
3884
  }
3884
3885
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.1.4", ngImport: i0, type: StorageServiceService, decorators: [{
@@ -3886,7 +3887,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.1.4", ngImpor
3886
3887
  args: [{
3887
3888
  providedIn: 'root'
3888
3889
  }]
3889
- }], 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 }] });
3890
3891
 
3891
3892
  class UserBasicInfoComponent {
3892
3893
  constructor(restService, router, dialogRef, storageService, messageService) {
@@ -4588,9 +4589,10 @@ class OrderedItems {
4588
4589
  }
4589
4590
 
4590
4591
  class CartService {
4591
- constructor(storageService, restService) {
4592
+ constructor(storageService, restService, messageService) {
4592
4593
  this.storageService = storageService;
4593
4594
  this.restService = restService;
4595
+ this.messageService = messageService;
4594
4596
  }
4595
4597
  addItemFromCartPage(product, userCart) {
4596
4598
  if (product.quantity) {
@@ -4666,6 +4668,65 @@ class CartService {
4666
4668
  clearCartItems() {
4667
4669
  this.storageService.clearUserCart();
4668
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
+ }
4669
4730
  storeDataToServer() {
4670
4731
  // const userCart = UserCart as never as Cart;
4671
4732
  // const userWishlist = UserFavourites as never as Cart;
@@ -4678,7 +4739,7 @@ class CartService {
4678
4739
  // this.restService.addItemToDB(UserFavourites)
4679
4740
  // ]);
4680
4741
  }
4681
- 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 }); }
4682
4743
  static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "18.1.4", ngImport: i0, type: CartService, providedIn: 'root' }); }
4683
4744
  }
4684
4745
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.1.4", ngImport: i0, type: CartService, decorators: [{
@@ -4686,7 +4747,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.1.4", ngImpor
4686
4747
  args: [{
4687
4748
  providedIn: 'root',
4688
4749
  }]
4689
- }], ctorParameters: () => [{ type: StorageServiceService }, { type: RestService }] });
4750
+ }], ctorParameters: () => [{ type: StorageServiceService }, { type: RestService }, { type: i5$1.MessageService }] });
4690
4751
 
4691
4752
  class CartComponent extends BaseSection {
4692
4753
  constructor(_eventService, cartService, router, restService, matDialog, storageService, messageService, bottomSheet, matDialogData, dialogRef) {
@@ -4839,7 +4900,7 @@ class CartComponent extends BaseSection {
4839
4900
  });
4840
4901
  }
4841
4902
  updateUserCartV2() {
4842
- this.storageService.getUserCart().then((products) => {
4903
+ this.storageService.getCartProduct().then((products) => {
4843
4904
  const deliveryOption = JSON.parse(localStorage.getItem("deliveryOptions") ?? "{}");
4844
4905
  this.cartInfo.orderedItems = products;
4845
4906
  if (!this.cartInfo?.cartId && !(localStorage.getItem("cartId") == "undefined" || localStorage.getItem("cartId") == "null")) {
@@ -4861,6 +4922,7 @@ class CartComponent extends BaseSection {
4861
4922
  const restResponse = this.restService.addItemToDB(this.cartInfo).toPromise();
4862
4923
  restResponse.then((cartResponse) => {
4863
4924
  this.cartInfo = cartResponse.data;
4925
+ this.storageService.clearUserCart();
4864
4926
  });
4865
4927
  }
4866
4928
  else {
@@ -5391,7 +5453,7 @@ class NavbarSectionComponent {
5391
5453
  this.showEditors = false;
5392
5454
  this.showSearchBar = false;
5393
5455
  this.getScreenSize();
5394
- this.storageService.updateAllData();
5456
+ // this.storageService.updateAllData();
5395
5457
  }
5396
5458
  searchProducts() {
5397
5459
  this.router.navigate(['/list'], { queryParams: { searchTxt: this.searchText } });
@@ -7717,29 +7779,50 @@ class FeaturedProductsComponent extends BaseSection {
7717
7779
  this.apiLoading = true;
7718
7780
  this.restService.getFeaturedProduct(this.content?.collectionId).subscribe((response) => {
7719
7781
  this.responseData = response;
7720
- this.storageService.getUserCart().then((cartResponse) => {
7721
- cartResponse.onsuccess = (cartData) => {
7722
- this.apiLoading = false;
7723
- this.USER_CART = cartData.target.result;
7724
- this.responseData?.forEach((product) => {
7725
- this.USER_CART?.forEach((item) => {
7726
- if (item.itemId == product.itemId) {
7727
- if (product?.itemVariant?.length > 0) {
7728
- const itemVarient = product?.itemVariant?.[0];
7729
- if (itemVarient.variantId == item.varientId) {
7730
- product.itemImages = itemVarient.variantImages ?? [];
7731
- product.price = itemVarient.itemVariantPrice;
7732
- product.quantity = item.quantity;
7733
- }
7734
- }
7735
- 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;
7736
7816
  product.quantity = item.quantity;
7737
7817
  }
7738
7818
  }
7739
- });
7819
+ else {
7820
+ product.quantity = item.quantity;
7821
+ }
7822
+ }
7740
7823
  });
7741
- };
7742
- }, (err) => {
7824
+ });
7825
+ }).catch(err => {
7743
7826
  this.apiLoading = false;
7744
7827
  });
7745
7828
  this.storageService.getUserWhishlist().then((wishlistResponse) => {
@@ -7767,43 +7850,44 @@ class FeaturedProductsComponent extends BaseSection {
7767
7850
  });
7768
7851
  }
7769
7852
  addItemToCart(product, type) {
7770
- if (this.isItemOutOfStock(product)) {
7771
- this.messageService.add({ severity: 'warn', summary: 'Cart', detail: 'Item is not available as of now. We will notify you once available' });
7772
- return;
7773
- }
7774
- if (!product?.quantity)
7775
- product.quantity = 0;
7776
- if (type == 'ADD') {
7777
- product.quantity += 1;
7778
- }
7779
- else {
7780
- product.quantity -= 1;
7781
- }
7782
- if (product?.itemVariant?.length) {
7783
- const itemVarient = this.getItemVarient(product, product.varientId);
7784
- if (itemVarient) {
7785
- itemVarient.quantity = product.quantity;
7786
- this.cartService.addItemToCart(product, itemVarient.variantId);
7787
- }
7788
- }
7789
- else {
7790
- this.cartService.addItemToCart(product);
7791
- }
7792
- if (product.quantity) {
7793
- let isPresent = false;
7794
- this.USER_CART?.forEach((item) => {
7795
- if (item.varientId == product.varientId) {
7796
- item.quantity = product.quantity;
7797
- isPresent = true;
7798
- }
7799
- });
7800
- if (!isPresent)
7801
- this.USER_CART?.push(new OrderedItems(product, product.varientId));
7802
- }
7803
- else {
7804
- this.USER_CART = this.USER_CART?.filter((item) => item.varientId != product.varientId) ?? [];
7805
- }
7853
+ this.cartService.addItemToLocalCart(product, type);
7806
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
+ // }
7807
7891
  toggleItemToFav(event, product, type) {
7808
7892
  if (type == 'ADD') {
7809
7893
  product.whislist = true;