simpo-component-library 2.0.1 → 2.0.2
Sign up to get free protection for your applications and to get access to all the features.
- package/esm2022/lib/ecommerce/sections/cart/cart.component.mjs +46 -2
- package/esm2022/lib/ecommerce/sections/featured-products/featured-products.component.mjs +78 -56
- package/esm2022/lib/sections/navbar-section/navbar-section.component.mjs +2 -2
- package/esm2022/lib/services/cart.service.mjs +65 -4
- package/esm2022/lib/services/rest.service.mjs +3 -3
- package/esm2022/lib/services/storage.service.mjs +43 -1
- package/fesm2022/simpo-component-library.mjs +230 -62
- package/fesm2022/simpo-component-library.mjs.map +1 -1
- package/lib/directive/background-directive.d.ts +1 -1
- package/lib/directive/button-directive.directive.d.ts +1 -1
- package/lib/directive/color.directive.d.ts +1 -1
- package/lib/ecommerce/sections/cart/cart.component.d.ts +1 -0
- package/lib/sections/pricing-section/pricing-section.component.d.ts +1 -1
- package/lib/services/cart.service.d.ts +7 -2
- package/lib/services/storage.service.d.ts +1 -0
- package/package.json +1 -1
- package/simpo-component-library-2.0.2.tgz +0 -0
- package/simpo-component-library-2.0.1.tgz +0 -0
@@ -3349,8 +3349,8 @@ class RestService {
|
|
3349
3349
|
constructor(http, eventService) {
|
3350
3350
|
this.http = http;
|
3351
3351
|
this.eventService = eventService;
|
3352
|
-
this.BASE_URL = "https://api.simpo.ai/";
|
3353
|
-
this.ECOMMERCE_URL = "https://
|
3352
|
+
this.BASE_URL = "https://dev-api.simpo.ai/";
|
3353
|
+
this.ECOMMERCE_URL = "https://dev-ecommerce.simpo.ai/";
|
3354
3354
|
this.environmentTypeSubscriber = null;
|
3355
3355
|
this.environmentTypeSubscriber = this.eventService.environmentType.subscribe((response) => {
|
3356
3356
|
if (response == "DEV") {
|
@@ -3755,6 +3755,48 @@ class StorageServiceService {
|
|
3755
3755
|
const transaction = this.database.transaction(this.cartCollectionName, "readwrite");
|
3756
3756
|
return await transaction.objectStore(this.cartCollectionName).getAll();
|
3757
3757
|
}
|
3758
|
+
async getCartProduct() {
|
3759
|
+
try {
|
3760
|
+
const cartResponse = await this.getUserCart();
|
3761
|
+
return new Promise((resolve, reject) => {
|
3762
|
+
cartResponse.onsuccess = async (cartData) => {
|
3763
|
+
const indexDBProduct = cartData.target.result;
|
3764
|
+
const userDetails = this.getUser();
|
3765
|
+
if (userDetails?.userId) {
|
3766
|
+
try {
|
3767
|
+
const response = await this.restService.getUserItems(userDetails?.userId, "CART").toPromise();
|
3768
|
+
localStorage.setItem('cartId', response.data?.[0]?.cartId);
|
3769
|
+
const serverDBProduct = response?.data?.[0]?.orderedItems ?? [];
|
3770
|
+
for (let localProduct of indexDBProduct) {
|
3771
|
+
let productFound = false;
|
3772
|
+
for (let serverProduct of serverDBProduct) {
|
3773
|
+
if (serverProduct.varientId === localProduct.varientId) {
|
3774
|
+
serverProduct.quantity += localProduct.quantity;
|
3775
|
+
productFound = true;
|
3776
|
+
}
|
3777
|
+
}
|
3778
|
+
if (!productFound) {
|
3779
|
+
serverDBProduct.push(localProduct);
|
3780
|
+
}
|
3781
|
+
}
|
3782
|
+
resolve(serverDBProduct);
|
3783
|
+
}
|
3784
|
+
catch (error) {
|
3785
|
+
console.error("Error in API call:", error);
|
3786
|
+
reject(error);
|
3787
|
+
}
|
3788
|
+
}
|
3789
|
+
else {
|
3790
|
+
resolve(indexDBProduct);
|
3791
|
+
}
|
3792
|
+
};
|
3793
|
+
});
|
3794
|
+
}
|
3795
|
+
catch (error) {
|
3796
|
+
console.error("Error retrieving cart:", error);
|
3797
|
+
throw error;
|
3798
|
+
}
|
3799
|
+
}
|
3758
3800
|
addProductToCart(product) {
|
3759
3801
|
const transaction = this.database.transaction(this.cartCollectionName, "readwrite");
|
3760
3802
|
const response = transaction.objectStore(this.cartCollectionName).get(product.varientId);
|
@@ -4546,9 +4588,10 @@ class OrderedItems {
|
|
4546
4588
|
}
|
4547
4589
|
|
4548
4590
|
class CartService {
|
4549
|
-
constructor(storageService, restService) {
|
4591
|
+
constructor(storageService, restService, messageService) {
|
4550
4592
|
this.storageService = storageService;
|
4551
4593
|
this.restService = restService;
|
4594
|
+
this.messageService = messageService;
|
4552
4595
|
}
|
4553
4596
|
addItemFromCartPage(product, userCart) {
|
4554
4597
|
if (product.quantity) {
|
@@ -4624,6 +4667,65 @@ class CartService {
|
|
4624
4667
|
clearCartItems() {
|
4625
4668
|
this.storageService.clearUserCart();
|
4626
4669
|
}
|
4670
|
+
addItemToLocalCart(product, type) {
|
4671
|
+
if (this.isItemOutOfStock(product)) {
|
4672
|
+
this.messageService.add({ severity: 'warn', summary: 'Cart', detail: 'Item is not available as of now. We will notify you once available' });
|
4673
|
+
return;
|
4674
|
+
}
|
4675
|
+
if (!product?.quantity)
|
4676
|
+
product.quantity = 0;
|
4677
|
+
if (type == 'ADD') {
|
4678
|
+
product.quantity += 1;
|
4679
|
+
}
|
4680
|
+
else {
|
4681
|
+
product.quantity -= 1;
|
4682
|
+
}
|
4683
|
+
this.storageService.getUserCart().then((cartResponse) => {
|
4684
|
+
cartResponse.onsuccess = (cartData) => {
|
4685
|
+
const userCart = cartData.target.result ?? [];
|
4686
|
+
let orderedItem = new OrderedItems();
|
4687
|
+
if (product?.itemVariant?.length) {
|
4688
|
+
const itemVarient = this.getItemVarient(product, product.varientId);
|
4689
|
+
if (itemVarient) {
|
4690
|
+
itemVarient.quantity = product.quantity;
|
4691
|
+
orderedItem = this.objectMapper(product, itemVarient.variantId);
|
4692
|
+
}
|
4693
|
+
}
|
4694
|
+
else {
|
4695
|
+
orderedItem = this.objectMapper(product);
|
4696
|
+
}
|
4697
|
+
let productFound = false;
|
4698
|
+
for (let localProduct of userCart) {
|
4699
|
+
if (localProduct.varientId === product.varientId) {
|
4700
|
+
localProduct.quantity = type === 'ADD' ? localProduct.quantity + 1 : localProduct.quantity - 1;
|
4701
|
+
if (localProduct.quantity == 0) {
|
4702
|
+
this.removeItemFromCart(localProduct);
|
4703
|
+
}
|
4704
|
+
else {
|
4705
|
+
this.storageService.addProductToCart(localProduct);
|
4706
|
+
}
|
4707
|
+
productFound = true;
|
4708
|
+
break;
|
4709
|
+
}
|
4710
|
+
}
|
4711
|
+
if (!productFound) {
|
4712
|
+
orderedItem.quantity = type === 'ADD' ? 1 : -1;
|
4713
|
+
this.storageService.addProductToCart(orderedItem);
|
4714
|
+
}
|
4715
|
+
};
|
4716
|
+
});
|
4717
|
+
}
|
4718
|
+
isItemOutOfStock(product) {
|
4719
|
+
return product.itemInventory?.openingStock == 0;
|
4720
|
+
}
|
4721
|
+
getItemVarient(product, varientId) {
|
4722
|
+
let selectedVarient = null;
|
4723
|
+
product?.itemVariant?.forEach((varient) => {
|
4724
|
+
if (varient.variantId == varientId)
|
4725
|
+
selectedVarient = varient;
|
4726
|
+
});
|
4727
|
+
return selectedVarient;
|
4728
|
+
}
|
4627
4729
|
storeDataToServer() {
|
4628
4730
|
// const userCart = UserCart as never as Cart;
|
4629
4731
|
// const userWishlist = UserFavourites as never as Cart;
|
@@ -4636,7 +4738,7 @@ class CartService {
|
|
4636
4738
|
// this.restService.addItemToDB(UserFavourites)
|
4637
4739
|
// ]);
|
4638
4740
|
}
|
4639
|
-
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 }); }
|
4741
|
+
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 }); }
|
4640
4742
|
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "18.1.4", ngImport: i0, type: CartService, providedIn: 'root' }); }
|
4641
4743
|
}
|
4642
4744
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.1.4", ngImport: i0, type: CartService, decorators: [{
|
@@ -4644,7 +4746,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.1.4", ngImpor
|
|
4644
4746
|
args: [{
|
4645
4747
|
providedIn: 'root',
|
4646
4748
|
}]
|
4647
|
-
}], ctorParameters: () => [{ type: StorageServiceService }, { type: RestService }] });
|
4749
|
+
}], ctorParameters: () => [{ type: StorageServiceService }, { type: RestService }, { type: i5$1.MessageService }] });
|
4648
4750
|
|
4649
4751
|
class CartComponent extends BaseSection {
|
4650
4752
|
constructor(_eventService, cartService, router, restService, matDialog, storageService, messageService, bottomSheet, matDialogData, dialogRef) {
|
@@ -4668,6 +4770,7 @@ class CartComponent extends BaseSection {
|
|
4668
4770
|
this.enteredCouponCode = "";
|
4669
4771
|
this.couponList = [];
|
4670
4772
|
this.cartInfo = {
|
4773
|
+
cartId: localStorage.getItem("cartId"),
|
4671
4774
|
orderedItems: null,
|
4672
4775
|
businessId: localStorage.getItem("bId") ?? localStorage.getItem("businessId"),
|
4673
4776
|
billdetails: {
|
@@ -4699,7 +4802,7 @@ class CartComponent extends BaseSection {
|
|
4699
4802
|
// this.getIndexDBData();
|
4700
4803
|
}
|
4701
4804
|
});
|
4702
|
-
this.
|
4805
|
+
this.updateUserCartV2();
|
4703
4806
|
// if (this.storageService.getUser()) {
|
4704
4807
|
// this.updateUserCart();
|
4705
4808
|
// } else {
|
@@ -4795,6 +4898,49 @@ class CartComponent extends BaseSection {
|
|
4795
4898
|
}
|
4796
4899
|
});
|
4797
4900
|
}
|
4901
|
+
updateUserCartV2() {
|
4902
|
+
this.storageService.getCartProduct().then((products) => {
|
4903
|
+
const deliveryOption = JSON.parse(localStorage.getItem("deliveryOptions") ?? "{}");
|
4904
|
+
this.cartInfo.orderedItems = products;
|
4905
|
+
if (!this.cartInfo?.cartId && !(localStorage.getItem("cartId") == "undefined" || localStorage.getItem("cartId") == "null")) {
|
4906
|
+
this.cartInfo['cartId'] = localStorage.getItem("cartId");
|
4907
|
+
}
|
4908
|
+
this.userDetails = this.storageService.getUser();
|
4909
|
+
if (this.userDetails) {
|
4910
|
+
this.getCouponList();
|
4911
|
+
this.cartInfo.userDetails = {
|
4912
|
+
"userId": this.userDetails?.userId,
|
4913
|
+
"userName": this.userDetails?.contact.name,
|
4914
|
+
"mobile": this.userDetails?.contact.mobile,
|
4915
|
+
"email": this.userDetails?.contact.email,
|
4916
|
+
};
|
4917
|
+
if (!(localStorage.getItem("couponId") == "undefined" || localStorage.getItem("couponId") == "null"))
|
4918
|
+
this.cartInfo.billdetails.couponId = localStorage.getItem("couponId");
|
4919
|
+
if (!(localStorage.getItem("couponCode") == "undefined" || localStorage.getItem("couponCode") == "null"))
|
4920
|
+
this.cartInfo.billdetails.couponCode = localStorage.getItem("couponCode");
|
4921
|
+
const restResponse = this.restService.addItemToDB(this.cartInfo).toPromise();
|
4922
|
+
restResponse.then((cartResponse) => {
|
4923
|
+
this.cartInfo = cartResponse.data;
|
4924
|
+
this.storageService.clearUserCart();
|
4925
|
+
});
|
4926
|
+
}
|
4927
|
+
else {
|
4928
|
+
this.cartInfo.billdetails.totalGrossValue = 0;
|
4929
|
+
this.cartInfo.billdetails.totalTax = 0;
|
4930
|
+
this.cartInfo.billdetails.deliveryCharges = 0;
|
4931
|
+
this.cartInfo.billdetails.totalNetValue = 0;
|
4932
|
+
this.cartInfo.totalAmount = 0;
|
4933
|
+
products.forEach((item) => {
|
4934
|
+
this.cartInfo.billdetails.totalGrossValue += (item.discountedPrice * (item.quantity ?? 1));
|
4935
|
+
this.cartInfo.billdetails.totalTax += (item.quantity * (item.itemTax ?? 0));
|
4936
|
+
});
|
4937
|
+
this.cartInfo.billdetails.deliveryCharges = (deliveryOption?.minOrderAmount > this.cartInfo.billdetails.totalGrossValue) ? 0 : (deliveryOption?.deliveryCharges ?? 0);
|
4938
|
+
this.cartInfo.billdetails.totalNetValue = this.cartInfo.billdetails.totalGrossValue - this.cartInfo.billdetails.deliveryCharges;
|
4939
|
+
this.cartInfo.totalAmount = this.cartInfo.billdetails.totalNetValue + this.getTaxAmount();
|
4940
|
+
+this.cartInfo.billdetails.deliveryCharges;
|
4941
|
+
}
|
4942
|
+
});
|
4943
|
+
}
|
4798
4944
|
// updateUserCart2() {
|
4799
4945
|
// const deliveryOption = JSON.parse(localStorage.getItem("deliveryOptions") ?? "{}");
|
4800
4946
|
// this.userDetails = this.storageService.getUser() as User;
|
@@ -5306,7 +5452,7 @@ class NavbarSectionComponent {
|
|
5306
5452
|
this.showEditors = false;
|
5307
5453
|
this.showSearchBar = false;
|
5308
5454
|
this.getScreenSize();
|
5309
|
-
this.storageService.updateAllData();
|
5455
|
+
// this.storageService.updateAllData();
|
5310
5456
|
}
|
5311
5457
|
searchProducts() {
|
5312
5458
|
this.router.navigate(['/list'], { queryParams: { searchTxt: this.searchText } });
|
@@ -7632,29 +7778,50 @@ class FeaturedProductsComponent extends BaseSection {
|
|
7632
7778
|
this.apiLoading = true;
|
7633
7779
|
this.restService.getFeaturedProduct(this.content?.collectionId).subscribe((response) => {
|
7634
7780
|
this.responseData = response;
|
7635
|
-
this.storageService.getUserCart().then((cartResponse) => {
|
7636
|
-
|
7637
|
-
|
7638
|
-
|
7639
|
-
|
7640
|
-
|
7641
|
-
|
7642
|
-
|
7643
|
-
|
7644
|
-
|
7645
|
-
|
7646
|
-
|
7647
|
-
|
7648
|
-
|
7649
|
-
|
7650
|
-
|
7781
|
+
// this.storageService.getUserCart().then((cartResponse) => {
|
7782
|
+
// cartResponse.onsuccess = (cartData: any) => {
|
7783
|
+
// this.apiLoading = false;
|
7784
|
+
// this.USER_CART = cartData.target.result as unknown as OrderedItems[];
|
7785
|
+
// this.responseData?.forEach((product: Product) => {
|
7786
|
+
// this.USER_CART?.forEach((item: OrderedItems) => {
|
7787
|
+
// if (item.itemId == product.itemId) {
|
7788
|
+
// if (product?.itemVariant?.length > 0) {
|
7789
|
+
// const itemVarient: ItemVariant = product?.itemVariant?.[0];
|
7790
|
+
// if (itemVarient.variantId == item.varientId) {
|
7791
|
+
// product.itemImages = itemVarient.variantImages ?? [];
|
7792
|
+
// product.price = itemVarient.itemVariantPrice;
|
7793
|
+
// product.quantity = item.quantity;
|
7794
|
+
// }
|
7795
|
+
// } else {
|
7796
|
+
// product.quantity = item.quantity;
|
7797
|
+
// }
|
7798
|
+
// }
|
7799
|
+
// })
|
7800
|
+
// })
|
7801
|
+
// }
|
7802
|
+
// },(err) => {
|
7803
|
+
// this.apiLoading = false;
|
7804
|
+
// })
|
7805
|
+
this.storageService.getCartProduct().then((products) => {
|
7806
|
+
this.apiLoading = false;
|
7807
|
+
this.responseData?.forEach((product) => {
|
7808
|
+
products?.forEach((item) => {
|
7809
|
+
if (item.itemId == product.itemId) {
|
7810
|
+
if (product?.itemVariant?.length > 0) {
|
7811
|
+
const itemVarient = product?.itemVariant?.[0];
|
7812
|
+
if (itemVarient.variantId == item.varientId) {
|
7813
|
+
product.itemImages = itemVarient.variantImages ?? [];
|
7814
|
+
product.price = itemVarient.itemVariantPrice;
|
7651
7815
|
product.quantity = item.quantity;
|
7652
7816
|
}
|
7653
7817
|
}
|
7654
|
-
|
7818
|
+
else {
|
7819
|
+
product.quantity = item.quantity;
|
7820
|
+
}
|
7821
|
+
}
|
7655
7822
|
});
|
7656
|
-
};
|
7657
|
-
}
|
7823
|
+
});
|
7824
|
+
}).catch(err => {
|
7658
7825
|
this.apiLoading = false;
|
7659
7826
|
});
|
7660
7827
|
this.storageService.getUserWhishlist().then((wishlistResponse) => {
|
@@ -7682,43 +7849,44 @@ class FeaturedProductsComponent extends BaseSection {
|
|
7682
7849
|
});
|
7683
7850
|
}
|
7684
7851
|
addItemToCart(product, type) {
|
7685
|
-
|
7686
|
-
this.messageService.add({ severity: 'warn', summary: 'Cart', detail: 'Item is not available as of now. We will notify you once available' });
|
7687
|
-
return;
|
7688
|
-
}
|
7689
|
-
if (!product?.quantity)
|
7690
|
-
product.quantity = 0;
|
7691
|
-
if (type == 'ADD') {
|
7692
|
-
product.quantity += 1;
|
7693
|
-
}
|
7694
|
-
else {
|
7695
|
-
product.quantity -= 1;
|
7696
|
-
}
|
7697
|
-
if (product?.itemVariant?.length) {
|
7698
|
-
const itemVarient = this.getItemVarient(product, product.varientId);
|
7699
|
-
if (itemVarient) {
|
7700
|
-
itemVarient.quantity = product.quantity;
|
7701
|
-
this.cartService.addItemToCart(product, itemVarient.variantId);
|
7702
|
-
}
|
7703
|
-
}
|
7704
|
-
else {
|
7705
|
-
this.cartService.addItemToCart(product);
|
7706
|
-
}
|
7707
|
-
if (product.quantity) {
|
7708
|
-
let isPresent = false;
|
7709
|
-
this.USER_CART?.forEach((item) => {
|
7710
|
-
if (item.varientId == product.varientId) {
|
7711
|
-
item.quantity = product.quantity;
|
7712
|
-
isPresent = true;
|
7713
|
-
}
|
7714
|
-
});
|
7715
|
-
if (!isPresent)
|
7716
|
-
this.USER_CART?.push(new OrderedItems(product, product.varientId));
|
7717
|
-
}
|
7718
|
-
else {
|
7719
|
-
this.USER_CART = this.USER_CART?.filter((item) => item.varientId != product.varientId) ?? [];
|
7720
|
-
}
|
7852
|
+
this.cartService.addItemToLocalCart(product, type);
|
7721
7853
|
}
|
7854
|
+
// addItemToCart(product: Product, type: 'ADD' | 'SUBSTRACT') {
|
7855
|
+
// if (this.isItemOutOfStock(product)) {
|
7856
|
+
// this.messageService.add({ severity: 'warn', summary: 'Cart', detail: 'Item is not available as of now. We will notify you once available' });
|
7857
|
+
// return;
|
7858
|
+
// }
|
7859
|
+
// if (!product?.quantity)
|
7860
|
+
// product.quantity = 0;
|
7861
|
+
// if (type == 'ADD') {
|
7862
|
+
// product.quantity += 1;
|
7863
|
+
// }
|
7864
|
+
// else {
|
7865
|
+
// product.quantity -= 1;
|
7866
|
+
// }
|
7867
|
+
// if (product?.itemVariant?.length) {
|
7868
|
+
// const itemVarient: ItemVariant | null = this.getItemVarient(product, product.varientId);
|
7869
|
+
// if (itemVarient) {
|
7870
|
+
// itemVarient.quantity = product.quantity;
|
7871
|
+
// this.cartService.addItemToCart(product, itemVarient.variantId);
|
7872
|
+
// }
|
7873
|
+
// } else {
|
7874
|
+
// this.cartService.addItemToCart(product);
|
7875
|
+
// }
|
7876
|
+
// if (product.quantity) {
|
7877
|
+
// let isPresent: boolean = false;
|
7878
|
+
// this.USER_CART?.forEach((item: OrderedItems) => {
|
7879
|
+
// if (item.varientId == product.varientId) {
|
7880
|
+
// item.quantity = product.quantity;
|
7881
|
+
// isPresent = true;
|
7882
|
+
// }
|
7883
|
+
// })
|
7884
|
+
// if (!isPresent)
|
7885
|
+
// this.USER_CART?.push(new OrderedItems(product, product.varientId));
|
7886
|
+
// } else {
|
7887
|
+
// this.USER_CART = this.USER_CART?.filter((item: OrderedItems) => item.varientId != product.varientId) ?? [];
|
7888
|
+
// }
|
7889
|
+
// }
|
7722
7890
|
toggleItemToFav(event, product, type) {
|
7723
7891
|
if (type == 'ADD') {
|
7724
7892
|
product.whislist = true;
|