simpo-component-library 1.4.15 → 1.4.17

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.
Files changed (30) hide show
  1. package/esm2022/lib/ecommerce/json/user-cart.json +1 -14
  2. package/esm2022/lib/ecommerce/sections/authenticate-user/authenticate-user.component.mjs +13 -10
  3. package/esm2022/lib/ecommerce/sections/cart/cart.component.mjs +2 -2
  4. package/esm2022/lib/ecommerce/sections/featured-products/featured-products.component.mjs +3 -3
  5. package/esm2022/lib/ecommerce/sections/product-desc/product-desc.component.mjs +10 -4
  6. package/esm2022/lib/ecommerce/sections/whislist/whislist.component.mjs +3 -3
  7. package/esm2022/lib/ecommerce/styles/OrderedItems.modal.mjs +3 -8
  8. package/esm2022/lib/ecommerce/styles/cart.modal.mjs +2 -1
  9. package/esm2022/lib/ecommerce/styles/user.modal.mjs +11 -0
  10. package/esm2022/lib/services/cart.service.mjs +86 -69
  11. package/esm2022/lib/services/storage.service.mjs +80 -0
  12. package/fesm2022/simpo-component-library.mjs +188 -100
  13. package/fesm2022/simpo-component-library.mjs.map +1 -1
  14. package/lib/directive/background-directive.d.ts +1 -1
  15. package/lib/directive/button-directive.directive.d.ts +1 -1
  16. package/lib/directive/color.directive.d.ts +1 -1
  17. package/lib/ecommerce/sections/authenticate-user/authenticate-user.component.d.ts +4 -2
  18. package/lib/ecommerce/sections/featured-products/featured-products.component.d.ts +1 -1
  19. package/lib/ecommerce/styles/OrderedItems.modal.d.ts +10 -14
  20. package/lib/ecommerce/styles/cart.modal.d.ts +3 -18
  21. package/lib/ecommerce/styles/user.modal.d.ts +38 -0
  22. package/lib/sections/pricing-section/pricing-section.component.d.ts +1 -1
  23. package/lib/services/cart.service.d.ts +9 -9
  24. package/lib/services/storage.service.d.ts +28 -0
  25. package/package.json +1 -1
  26. package/simpo-component-library-1.4.17.tgz +0 -0
  27. package/simpo-component-library-1.4.12.tgz +0 -0
  28. package/simpo-component-library-1.4.13.tgz +0 -0
  29. package/simpo-component-library-1.4.14.tgz +0 -0
  30. package/simpo-component-library-1.4.15.tgz +0 -0
@@ -18,6 +18,7 @@ import * as i2$3 from '@angular/material/snack-bar';
18
18
  import * as i2$4 from 'ngx-skeleton-loader';
19
19
  import { NgxSkeletonLoaderModule } from 'ngx-skeleton-loader';
20
20
  import * as mapboxgl from 'mapbox-gl';
21
+ import { v1 } from 'uuid';
21
22
  import * as i8 from 'ngx-image-zoom';
22
23
  import { NgxImageZoomModule } from 'ngx-image-zoom';
23
24
  import * as i8$1 from '@angular/material/slider';
@@ -2985,18 +2986,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.1.4", ngImpor
2985
2986
  }] } });
2986
2987
 
2987
2988
  var orderedItems$1 = [
2988
- {
2989
- itemId: "1ef50089-2cf0-6bdf-8ea9-b51e0a912f33",
2990
- businessId: "21",
2991
- itemName: "Anime T-Shirt",
2992
- brandName: "Excee",
2993
- imgUrl: "https://dev-beeos.s3.amazonaws.com/library-media/291611c1707983189501product-details-2.jpg.jpg",
2994
- price: 120,
2995
- itemTax: 10,
2996
- quantity: 2,
2997
- discountedPrice: 20,
2998
- taxAfterDiscount: 10
2999
- }
3000
2989
  ];
3001
2990
  var cartType$1 = "CART";
3002
2991
  var billdetails$1 = {
@@ -3233,12 +3222,91 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.1.4", ngImpor
3233
3222
  ], template: "<section style=\"padding: 20px\" class=\"position-relative\">\r\n <div class=\"d-flex flex-wrap justify-content-between\">\r\n <div class=\"form-control-group-3\">\r\n <div class=\"label\">First Name</div>\r\n <input type=\"text\" placeholder=\"Enter first name\" [(ngModel)]=\"firstName\">\r\n </div>\r\n <div class=\"form-control-group-3\">\r\n <div class=\"label\">Middle Name</div>\r\n <input type=\"text\" placeholder=\"Enter middle name\" [(ngModel)]=\"middleName\">\r\n </div>\r\n <div class=\"form-control-group-3\">\r\n <div class=\"label\">Last Name</div>\r\n <input type=\"text\" placeholder=\"Enter last name\" [(ngModel)]=\"lastName\">\r\n </div>\r\n <div class=\"form-control-group-full\">\r\n <div class=\"form-control-group\">\r\n <div class=\"label\">Email</div>\r\n <input type=\"text\" placeholder=\"Enter email\" [(ngModel)]=\"email\">\r\n </div>\r\n </div> \r\n <div class=\"form-control-group\">\r\n <div class=\"label\">Select Gender</div>\r\n <div class=\"d-flex align-items-center\">\r\n <img src=\"https://img.icons8.com/?size=100&id=108296&format=png&color=000000\" alt=\"\" (click)=\"gender = 'MALE'\" [ngClass]=\"{'active': gender == 'MALE' }\">\r\n <img src=\"https://img.icons8.com/?size=100&id=108295&format=png&color=000000\" alt=\"\" (click)=\"gender = 'FEMALE'\" [ngClass]=\"{'active': gender == 'FEMALE'}\">\r\n </div>\r\n </div>\r\n </div>\r\n <div class=\"action-btn\">\r\n <span class=\"skip-btn\" (click)=\"close()\">Skip</span>\r\n <button (click)=\"saveProfile()\">Save Profile</button>\r\n </div>\r\n</section>", styles: [".form-control-group,.form-control-group-3,.form-control-group-full{width:48%}:is(.form-control-group,.form-control-group-3,.form-control-group-full)>input{width:100%;padding:10px;border-radius:3px;border:1.5px solid lightgray}.form-control-group-3{width:32%!important}.form-control-group-full{width:100%}.form-control-group{margin:15px 0}.form-control-group img{height:50px;width:50px;object-fit:cover;margin:0 5px;border:2px solid transparent;cursor:pointer;border-radius:50%}.form-control-group .active{border:2px solid #0267C1}.action-btn{position:absolute;bottom:-35px;right:10px;display:flex;align-items:center;gap:20px}.action-btn .skip-btn{color:#0267c1;cursor:pointer}.action-btn button{width:100px!important;border:none;background-color:#0267c1;color:#fff;cursor:pointer;border-radius:3px;padding:8px 0;font-size:14px!important;font-weight:500!important}\n"] }]
3234
3223
  }], ctorParameters: () => [{ type: RestService }, { type: i2$2.Router }, { type: i3.MatDialogRef }] });
3235
3224
 
3225
+ class StorageServiceService {
3226
+ constructor() {
3227
+ this.databaseName = "USER";
3228
+ this.databaseVersion = 1;
3229
+ this.cartCollectionName = "USER_CART";
3230
+ this.favouriteCollectionName = "USER_FAVOURITE";
3231
+ this.userCollectionName = "USER";
3232
+ this.cartCollectionRef = null;
3233
+ this.favouriteCollectionRef = null;
3234
+ this.userCollectionRef = null;
3235
+ this.createDataBase();
3236
+ }
3237
+ async createDataBase() {
3238
+ const request = window.indexedDB.open(this.databaseName, 1);
3239
+ request.onerror = () => { };
3240
+ request.onsuccess = async (event) => {
3241
+ this.database = await event.target.result;
3242
+ };
3243
+ request.onupgradeneeded = (event) => {
3244
+ this.database = event.target.result;
3245
+ this.cartCollectionRef = this.database.createObjectStore(this.cartCollectionName, { keyPath: "itemId" });
3246
+ this.favouriteCollectionRef = this.database.createObjectStore(this.favouriteCollectionName, { keyPath: "itemId" });
3247
+ this.userCollectionRef = this.database.createObjectStore(this.userCollectionName, { keyPath: "userId" });
3248
+ };
3249
+ }
3250
+ // CART SERVICE
3251
+ async getUserCart() {
3252
+ const request = await this.cartCollectionRef?.getAll();
3253
+ return request;
3254
+ }
3255
+ addProductToCart(product) {
3256
+ const transaction = this.database.transaction(this.cartCollectionName, "readwrite");
3257
+ return transaction.objectStore(this.cartCollectionName).put(product);
3258
+ }
3259
+ removeProductFromCart(productId) {
3260
+ const transaction = this.database.transaction(this.cartCollectionName, "readwrite");
3261
+ return transaction.objectStore(this.cartCollectionName).delete(productId);
3262
+ }
3263
+ async getProductFromCart(productId) {
3264
+ const transaction = this.database.transaction(this.cartCollectionName, "readwrite");
3265
+ return await transaction.objectStore(this.cartCollectionName).get(productId);
3266
+ }
3267
+ // WISHLIST SERVICE
3268
+ async getUserWhishlist() {
3269
+ const request = await this.cartCollectionRef?.getAll();
3270
+ return request;
3271
+ }
3272
+ addProductToWishlist(product) {
3273
+ const transaction = this.database.transaction(this.favouriteCollectionName, "readwrite");
3274
+ return transaction.objectStore(this.favouriteCollectionName).put(product);
3275
+ }
3276
+ removeProductFromWishlist(productId) {
3277
+ const transaction = this.database.transaction(this.favouriteCollectionName, "readwrite");
3278
+ return transaction.objectStore(this.favouriteCollectionName).delete(productId);
3279
+ }
3280
+ async getProductFromWishlist(productId) {
3281
+ const transaction = this.database.transaction(this.favouriteCollectionName, "readwrite");
3282
+ return await transaction.objectStore(this.favouriteCollectionName).get(productId);
3283
+ }
3284
+ // USER SERVICE
3285
+ addUser(user) {
3286
+ localStorage.setItem("user", JSON.stringify(user));
3287
+ return user;
3288
+ }
3289
+ getUser() {
3290
+ const user = localStorage.getItem("user") ?? "{}";
3291
+ return JSON.parse(user);
3292
+ }
3293
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.1.4", ngImport: i0, type: StorageServiceService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
3294
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "18.1.4", ngImport: i0, type: StorageServiceService, providedIn: 'root' }); }
3295
+ }
3296
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.1.4", ngImport: i0, type: StorageServiceService, decorators: [{
3297
+ type: Injectable,
3298
+ args: [{
3299
+ providedIn: 'root'
3300
+ }]
3301
+ }], ctorParameters: () => [] });
3302
+
3236
3303
  class AuthenticateUserComponent {
3237
- constructor(matData, restService, router, matDialog, dialogRef) {
3304
+ constructor(matData, restService, router, matDialog, storageService, dialogRef) {
3238
3305
  this.matData = matData;
3239
3306
  this.restService = restService;
3240
3307
  this.router = router;
3241
3308
  this.matDialog = matDialog;
3309
+ this.storageService = storageService;
3242
3310
  this.dialogRef = dialogRef;
3243
3311
  // @Input() index? : number;
3244
3312
  // @Input() edit? : boolean;
@@ -3274,14 +3342,16 @@ class AuthenticateUserComponent {
3274
3342
  verifyOTP() {
3275
3343
  this.restService.verifyOTP(this.mobile ?? "", this.otpString).subscribe((response) => {
3276
3344
  // localStorage.setItem("userId", response.userId);
3277
- UserInfo.user = response.data;
3278
- if (UserInfo.user?.contact?.name?.length > 0) {
3345
+ const userDetails = this.storageService.addUser(response.data);
3346
+ if (userDetails.contact?.name?.length > 0) {
3279
3347
  if (this.dialogRef)
3280
3348
  this.dialogRef.close();
3281
3349
  else
3282
3350
  this.router.navigate(['/']);
3283
3351
  }
3284
3352
  else {
3353
+ if (this.dialogRef)
3354
+ this.dialogRef.close();
3285
3355
  this.matDialog.open(UserBasicInfoComponent, {
3286
3356
  height: '50vh',
3287
3357
  width: '40vw',
@@ -3298,7 +3368,7 @@ class AuthenticateUserComponent {
3298
3368
  get isMobile() {
3299
3369
  return window.innerWidth <= 475;
3300
3370
  }
3301
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.1.4", ngImport: i0, type: AuthenticateUserComponent, deps: [{ token: MAT_DIALOG_DATA, optional: true }, { token: RestService }, { token: i2$2.Router }, { token: i3.MatDialog }, { token: i3.MatDialogRef, optional: true }], target: i0.ɵɵFactoryTarget.Component }); }
3371
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.1.4", ngImport: i0, type: AuthenticateUserComponent, deps: [{ token: MAT_DIALOG_DATA, optional: true }, { token: RestService }, { token: i2$2.Router }, { token: i3.MatDialog }, { token: StorageServiceService }, { token: i3.MatDialogRef, optional: true }], target: i0.ɵɵFactoryTarget.Component }); }
3302
3372
  static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "18.1.4", type: AuthenticateUserComponent, isStandalone: true, selector: "simpo-authenticate-user", inputs: { data: "data", responseData: "responseData" }, ngImport: i0, template: "<div [style.height.vh]=\"isMobile ? '90' : ''\">\r\n <ng-container [ngSwitch]=\"screen\">\r\n <section style=\"padding: 15px;\"\r\n class=\"d-flex flex-column align-item-center justify-content-center position-relative h-100\"\r\n *ngSwitchCase=\"'LOGIN'\"[ngClass]=\"{'fullSection': isMobile}\">\r\n <h5 class=\"text-center onlyDesktop\">Excee Fashion</h5>\r\n <h2 class=\"text-center\">Welcome</h2>\r\n <p class=\"text-center\">Log or Signup in to your account</p>\r\n <input type=\"number\" placeholder=\"Mobile Number\" [(ngModel)]=\"mobile\">\r\n <p class=\"text-center\">You will receive an SMS verification</p>\r\n\r\n <div class=\"action-btn d-flex flex-column align-item-center justify-content-center\">\r\n <button class=\"btn\" simpoButtonDirective [buttonStyle]=\"data?.action?.buttons[0]?.styles\"\r\n [color]=\"styles?.background?.accentColor\" (click)=\"generateOTP()\">Continue</button>\r\n <div class=\"alternate-opt text-center\" [style.color]=\"data?.styles.background?.accentColor\">Use email\r\n instead</div>\r\n </div>\r\n <div class=\"close-btn onlyDesktop\" (click)=\"close()\">\r\n <mat-icon>close</mat-icon>\r\n </div>\r\n </section>\r\n <section *ngSwitchCase=\"'OTP'\" style=\"padding: 15px;\"\r\n class=\"d-flex flex-column align-item-center justify-content-center position-relative h-100\" [ngClass]=\"{'fullSection': isMobile}\">\r\n <h5 class=\"text-center onlyDesktop\">Excee Fashion</h5>\r\n <h2 class=\"text-center\">Verify OTP</h2>\r\n <p class=\"text-center\">Enter the 6-digit that we have sent via the phone number +{{ countryCode }}{{ mobile\r\n }}</p>\r\n <div class=\"otpContainer\">\r\n <ng-container *ngFor=\"let _ of [].constructor(6); let idx = index\">\r\n <input type=\"number\" class=\"otp\" max=\"1\" [id]=\"'otp_'+idx\" (keyup)=\"move($event, idx)\">\r\n </ng-container>\r\n </div>\r\n\r\n <div class=\"action-btn d-flex flex-column align-item-center justify-content-center\">\r\n <button class=\"btn\" simpoButtonDirective [buttonStyle]=\"data?.action?.buttons[0]?.styles\"\r\n [color]=\"styles?.background?.accentColor\" (click)=\"verifyOTP()\">Continue</button>\r\n <div class=\"alternate-opt text-center\" [style.color]=\"data?.styles.background?.accentColor\"\r\n (click)=\"resendOTP()\">Resend code</div>\r\n </div>\r\n\r\n <div class=\"close-btn onlyDesktop\" (click)=\"close()\">\r\n <mat-icon>close</mat-icon>\r\n </div>\r\n <div class=\"back-btn\" (click)=\"goBack()\">\r\n <mat-icon>keyboard_backspace</mat-icon>\r\n </div>\r\n </section>\r\n </ng-container>\r\n</div>", styles: ["input,button{width:80%!important;margin:10px auto}input{padding:10px}.alternate-opt:hover{text-decoration:underline;cursor:pointer}.close-btn{position:absolute;top:10px;right:10px;cursor:pointer}.otpContainer{display:flex;gap:4px;margin:auto}.otpContainer .otp{border-radius:50%;padding:5px;height:50px;width:50px!important;margin:5px!important;text-align:center}input::-webkit-outer-spin-button,input::-webkit-inner-spin-button{-webkit-appearance:none;margin:0}input[type=number]{-moz-appearance:textfield}.back-btn{position:absolute;top:10px;left:10px;cursor:pointer}@media screen and (max-width: 475px){.onlyDesktop{display:none}.text-center{text-align:left!important}button,input{width:100%!important}.fullSection{justify-content:start!important}.action-btn{position:absolute;bottom:50px;width:95%}.action-btn .text-center{text-align:center!important}.otpContainer{margin-top:20px;position:relative;right:10px}}\n"], dependencies: [{ kind: "ngmodule", type: FormsModule }, { kind: "directive", type: i5.DefaultValueAccessor, selector: "input:not([type=checkbox])[formControlName],textarea[formControlName],input:not([type=checkbox])[formControl],textarea[formControl],input:not([type=checkbox])[ngModel],textarea[ngModel],[ngDefaultControl]" }, { kind: "directive", type: i5.NumberValueAccessor, selector: "input[type=number][formControlName],input[type=number][formControl],input[type=number][ngModel]" }, { kind: "directive", type: i5.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i5.NgModel, selector: "[ngModel]:not([formControlName]):not([formControl])", inputs: ["name", "disabled", "ngModel", "ngModelOptions"], outputs: ["ngModelChange"], exportAs: ["ngModel"] }, { kind: "component", type: MatIcon, selector: "mat-icon", inputs: ["color", "inline", "svgIcon", "fontSet", "fontIcon"], exportAs: ["matIcon"] }, { kind: "ngmodule", type: CommonModule }, { kind: "directive", type: i2.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { kind: "directive", type: i2.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { kind: "directive", type: i2.NgSwitch, selector: "[ngSwitch]", inputs: ["ngSwitch"] }, { kind: "directive", type: i2.NgSwitchCase, selector: "[ngSwitchCase]", inputs: ["ngSwitchCase"] }, { kind: "directive", type: ButtonDirectiveDirective, selector: "[simpoButtonDirective]", inputs: ["buttonStyle", "color", "scrollValue"] }] }); }
3303
3373
  }
3304
3374
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.1.4", ngImport: i0, type: AuthenticateUserComponent, decorators: [{
@@ -3314,7 +3384,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.1.4", ngImpor
3314
3384
  }, {
3315
3385
  type: Inject,
3316
3386
  args: [MAT_DIALOG_DATA]
3317
- }] }, { type: RestService }, { type: i2$2.Router }, { type: i3.MatDialog }, { type: i3.MatDialogRef, decorators: [{
3387
+ }] }, { type: RestService }, { type: i2$2.Router }, { type: i3.MatDialog }, { type: StorageServiceService }, { type: i3.MatDialogRef, decorators: [{
3318
3388
  type: Optional
3319
3389
  }] }], propDecorators: { data: [{
3320
3390
  type: Input
@@ -4678,7 +4748,7 @@ var UserFavourite = {
4678
4748
 
4679
4749
  class OrderedItems {
4680
4750
  constructor(json) {
4681
- this.itemId = json?.["itemId"];
4751
+ this.itemId = json?.["itemId"] ?? v1();
4682
4752
  this.businessId = json?.["businessId"];
4683
4753
  this.itemName = json?.["name"];
4684
4754
  this.brandName = json?.["brandName"];
@@ -4689,83 +4759,86 @@ class OrderedItems {
4689
4759
  this.discountedPrice = json?.["price"]?.["discountedPrice"];
4690
4760
  this.taxAfterDiscount = json?.["taxAfterDiscount"];
4691
4761
  }
4692
- set setQuantity(quantity) {
4693
- this.quantity = quantity;
4694
- }
4695
- get getQuantity() { return this.quantity; }
4696
- get getItemId() { return this.itemId; }
4697
- get getPrice() { return this.price; }
4698
4762
  }
4699
4763
 
4700
4764
  class CartService {
4701
- constructor(restService) {
4765
+ constructor(restService, storageService) {
4702
4766
  this.restService = restService;
4767
+ this.storageService = storageService;
4703
4768
  }
4704
4769
  addItemToCart(product) {
4705
- this.storeItemToJSON(UserCart, product, "CART");
4770
+ const orderedItem = this.objectMapper(product);
4771
+ let productIdx = -1;
4772
+ UserCart.orderedItems.forEach((item, idx) => productIdx = (item.itemId == product.itemId) ? idx : -1);
4773
+ if (productIdx >= 0) {
4774
+ UserCart.orderedItems[productIdx].quantity = product.quantity;
4775
+ }
4776
+ else {
4777
+ UserCart.orderedItems.push(product);
4778
+ }
4779
+ console.log(UserCart);
4780
+ this.storageService.addProductToCart(orderedItem);
4706
4781
  }
4707
4782
  addItemToFavourite(product) {
4708
- this.storeItemToJSON(UserFavourite, product, "WISHLIST");
4709
- }
4710
- removeItemToFavourite(product) {
4711
- const index = this.getItemIdxJSON(product.itemId, UserFavourite);
4712
- console.log("index: ", index);
4713
- if (index >= 0)
4714
- UserFavourite.orderedItems.splice(index, 1);
4715
- console.log(UserFavourite);
4783
+ const orderedItem = this.objectMapper(product);
4784
+ let productIdx = -1;
4785
+ UserFavourite.orderedItems.forEach((item, idx) => productIdx = (item.itemId == product.itemId) ? idx : -1);
4786
+ if (productIdx >= 0) {
4787
+ UserFavourite.orderedItems[productIdx].quantity = product.quantity;
4788
+ }
4789
+ else {
4790
+ UserFavourite.orderedItems.push(product);
4791
+ }
4792
+ this.storageService.addProductToWishlist(orderedItem);
4716
4793
  }
4717
- convertFavToCart(product) {
4718
- const index = this.getItemIdxJSON(product.getItemId, UserFavourite);
4794
+ removeItemFromFavourite(product) {
4795
+ const index = this.getItemIdxJSON(product.itemId, 'FAVOURITE');
4719
4796
  if (index >= 0) {
4720
4797
  const item = UserFavourite.orderedItems.splice(index, 1)[0];
4721
4798
  UserCart.orderedItems.push(item);
4799
+ this.storageService.removeProductFromWishlist(product.itemId);
4722
4800
  }
4723
4801
  }
4724
- convertCartToFav(product) {
4725
- const index = this.getItemIdxJSON(product.getItemId, UserCart);
4802
+ removeItemFromCart(product) {
4803
+ const index = this.getItemIdxJSON(product.itemId, 'CART');
4726
4804
  if (index >= 0) {
4727
4805
  const item = UserCart.orderedItems.splice(index, 1)[0];
4728
- UserFavourite.orderedItems.push(item);
4806
+ UserCart.orderedItems.push(item);
4807
+ this.storageService.removeProductFromCart(product.itemId);
4729
4808
  }
4730
4809
  }
4731
- storeItemToJSON(json, product, type) {
4732
- const orderProduct = this.objectMapper(product);
4733
- let productIndex = -1;
4734
- json.orderedItems.forEach((p, idx) => {
4735
- if (p.itemId == product.itemId)
4736
- productIndex = idx;
4737
- });
4738
- if (productIndex == -1)
4739
- json.orderedItems.push(orderProduct);
4740
- else {
4741
- if (product.quantity > 0) {
4742
- json.orderedItems[productIndex].quantity = orderProduct.getQuantity;
4810
+ // public convertFavToCart(product: OrderedItems) {
4811
+ // const index = this.getItemIdxJSON(product.getItemId, UserFavourites);
4812
+ // if (index >= 0) {
4813
+ // const item = UserFavourites.orderedItems.splice(index, 1)[0];
4814
+ // UserCart.orderedItems.push(item as never);
4815
+ // }
4816
+ // }
4817
+ // public convertCartToFav(product: OrderedItems) {
4818
+ // const index = this.getItemIdxJSON(product.getItemId, UserCart);
4819
+ // if (index >= 0) {
4820
+ // const item = UserCart.orderedItems.splice(index, 1)[0];
4821
+ // UserFavourites.orderedItems.push(item as never);
4822
+ // }
4823
+ // }
4824
+ storeItemToDB(product, type) {
4825
+ if (type == "CART") {
4826
+ const orderProduct = this.objectMapper(this.storageService.getProductFromCart(product.itemId));
4827
+ if (orderProduct) {
4828
+ this.storageService.addProductToCart(orderProduct);
4829
+ UserCart.orderedItems.push(orderProduct);
4743
4830
  }
4744
- else {
4745
- json.orderedItems.splice(productIndex, 1);
4831
+ }
4832
+ else {
4833
+ const orderProduct = this.objectMapper(this.storageService.getProductFromWishlist(product.itemId));
4834
+ if (orderProduct) {
4835
+ this.storageService.addProductToWishlist(orderProduct);
4836
+ UserFavourite.orderedItems.push(orderProduct);
4746
4837
  }
4747
- json.billdetails.totalNetValue = 0;
4748
- json.billdetails.totalTax = 0;
4749
- json.orderedItems.forEach((item) => json.billdetails.totalNetValue += (item.price * item.quantity));
4750
- json.orderedItems.forEach((item) => json.billdetails.totalTax += (item.itemTax));
4751
- json.totalAmount = json.billdetails.totalTax + json.billdetails.totalNetValue;
4752
4838
  }
4753
4839
  }
4754
- getItemQuantity(itemId) {
4755
- let productIndex = -1;
4756
- UserCart.orderedItems.forEach((p, idx) => {
4757
- if (p.itemId == itemId)
4758
- productIndex = idx;
4759
- });
4760
- if (productIndex == -1)
4761
- return 0;
4762
- else
4763
- return UserCart.orderedItems[productIndex].getQuantity;
4764
- }
4765
- getIsItemPresent(itemId, type) {
4766
- return type == "FAVOURITE" ? this.getItemIdxJSON(itemId, UserFavourite) >= 0 : this.getItemIdxJSON(itemId, UserCart) >= 0;
4767
- }
4768
- getItemIdxJSON(itemId, json) {
4840
+ getItemIdxJSON(itemId, type) {
4841
+ const json = type == "FAVOURITE" ? UserFavourite : UserCart;
4769
4842
  let productIndex = -1;
4770
4843
  json.orderedItems.forEach((p, idx) => {
4771
4844
  if (p.itemId == itemId)
@@ -4773,29 +4846,37 @@ class CartService {
4773
4846
  });
4774
4847
  return productIndex;
4775
4848
  }
4849
+ getItemByIdx(itemId, type) {
4850
+ const productIdx = this.getItemIdxJSON(itemId, type);
4851
+ const json = (type == "FAVOURITE") ? UserFavourite : UserCart;
4852
+ if (productIdx >= 0)
4853
+ return json.orderedItems[productIdx];
4854
+ return null;
4855
+ }
4776
4856
  objectMapper(product) {
4857
+ debugger;
4777
4858
  return new OrderedItems(product);
4778
4859
  }
4779
- storeJSONToDB() {
4780
- this.restService.addItemToDB(UserCart).subscribe((response) => { });
4781
- this.restService.addItemToDB(UserFavourite).subscribe((response) => { });
4860
+ storeDataToServer() {
4861
+ // this.restService.addItemToDB(UserCart).subscribe((response)=> {});
4862
+ // this.restService.addItemToDB(UserFavourites).subscribe((response)=> {});
4782
4863
  }
4783
4864
  storeDBToJSON() {
4784
- const userId = UserInfo.user?.userId;
4785
- if (!userId)
4786
- return;
4787
- this.restService.getUserItems(userId, "CART").subscribe((response) => {
4788
- UserCart.orderedItems = response.data.orderedItems;
4789
- UserCart.billdetails = response.data.billdetails;
4790
- UserCart.totalAmount = response.totalAmount;
4791
- });
4792
- this.restService.getUserItems(userId, "WISHLIST").subscribe((response) => {
4793
- UserFavourite.orderedItems = response.data.orderedItems;
4794
- UserFavourite.billdetails = response.data.billdetails;
4795
- UserFavourite.totalAmount = response.totalAmount;
4796
- });
4797
- }
4798
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.1.4", ngImport: i0, type: CartService, deps: [{ token: RestService }], target: i0.ɵɵFactoryTarget.Injectable }); }
4865
+ // const userId = UserDetails.user?.userId;
4866
+ // if (!userId)
4867
+ // return;
4868
+ // this.restService.getUserItems(userId, "CART").subscribe((response: any)=> {
4869
+ // UserCart.orderedItems = response.data.orderedItems;
4870
+ // UserCart.billdetails = response.data.billdetails;
4871
+ // UserCart.totalAmount = response.totalAmount;
4872
+ // })
4873
+ // this.restService.getUserItems(userId, "WISHLIST").subscribe((response: any)=> {
4874
+ // UserFavourites.orderedItems = response.data.orderedItems;
4875
+ // UserFavourites.billdetails = response.data.billdetails;
4876
+ // UserFavourites.totalAmount = response.totalAmount;
4877
+ // })
4878
+ }
4879
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.1.4", ngImport: i0, type: CartService, deps: [{ token: RestService }, { token: StorageServiceService }], target: i0.ɵɵFactoryTarget.Injectable }); }
4799
4880
  static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "18.1.4", ngImport: i0, type: CartService, providedIn: 'root' }); }
4800
4881
  }
4801
4882
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.1.4", ngImport: i0, type: CartService, decorators: [{
@@ -4803,7 +4884,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.1.4", ngImpor
4803
4884
  args: [{
4804
4885
  providedIn: 'root',
4805
4886
  }]
4806
- }], ctorParameters: () => [{ type: RestService }] });
4887
+ }], ctorParameters: () => [{ type: RestService }, { type: StorageServiceService }] });
4807
4888
 
4808
4889
  class FeaturedProductsComponent extends BaseSection {
4809
4890
  constructor(platformId, _eventService, restService, router, cartService) {
@@ -4864,14 +4945,14 @@ class FeaturedProductsComponent extends BaseSection {
4864
4945
  if (type == 'ADD')
4865
4946
  this.cartService.addItemToFavourite(product);
4866
4947
  else
4867
- this.cartService.removeItemToFavourite(product);
4948
+ this.cartService.removeItemFromFavourite(product);
4868
4949
  }
4869
4950
  proceedToProductDesc(productId) {
4870
4951
  this.router.navigate([`details`], { queryParams: { id: productId } });
4871
4952
  // this._eventService.redirectToPage.emit({redirectTo: '/details', data: {productId: productId}})
4872
4953
  }
4873
4954
  isItemFav(product) {
4874
- return this.cartService.getIsItemPresent(product.itemId, 'FAVOURITE');
4955
+ return this.cartService.getItemIdxJSON(product.itemId, 'FAVOURITE');
4875
4956
  }
4876
4957
  togglePreviewImage(product, idx) {
4877
4958
  const element = document.getElementById('preview_' + idx);
@@ -5018,7 +5099,13 @@ class ProductDescComponent extends BaseSection {
5018
5099
  this.restService.getProductDetails(productId).subscribe((response) => {
5019
5100
  this.responseData = response[0];
5020
5101
  if (this.responseData) {
5021
- this.responseData.quantity = this.cartService.getItemQuantity(this.responseData?.itemId);
5102
+ const cartItem = this.cartService.getItemByIdx(this.responseData?.itemId, "CART");
5103
+ const favItem = this.cartService.getItemByIdx(this.responseData?.itemId, "FAVOURITE");
5104
+ response.quantity = 0;
5105
+ if (cartItem)
5106
+ response.quantity = cartItem.quantity;
5107
+ if (favItem)
5108
+ response.quantity = favItem.quantity;
5022
5109
  this.currentImg = this.responseData?.itemImages[0].imgUrl;
5023
5110
  this.getProductByCategory();
5024
5111
  }
@@ -5054,10 +5141,10 @@ class ProductDescComponent extends BaseSection {
5054
5141
  this.cartService.addItemToFavourite(this.responseData);
5055
5142
  }
5056
5143
  removeToFavourite() {
5057
- this.cartService.removeItemToFavourite(this.responseData);
5144
+ this.cartService.removeItemFromFavourite(this.responseData);
5058
5145
  }
5059
5146
  get isItemAsFavorite() {
5060
- return this.cartService.getIsItemPresent(this.responseData?.itemId, "FAVOURITE");
5147
+ return false;
5061
5148
  }
5062
5149
  get getFeatureProductData() {
5063
5150
  return this.data;
@@ -5466,7 +5553,7 @@ class CartComponent extends BaseSection {
5466
5553
  this.currentTab = "BAG";
5467
5554
  }
5468
5555
  ngOnInit() {
5469
- this.cartService.storeDBToJSON();
5556
+ // this.cartService.storeDBToJSON();
5470
5557
  this.responseData = UserCart;
5471
5558
  console.log("a: ", UserCart, this.responseData);
5472
5559
  this.styles = this.data?.styles;
@@ -5612,10 +5699,10 @@ class WhislistComponent {
5612
5699
  this.styles = this.data?.styles;
5613
5700
  }
5614
5701
  moveToCart(item) {
5615
- this.cartService.convertFavToCart(item);
5702
+ // this.cartService.convertFavToCart(item);
5616
5703
  }
5617
5704
  deleteFromWhislist(item) {
5618
- this.cartService.removeItemToFavourite(item);
5705
+ // this.cartService.removeItemToFavourite(item);
5619
5706
  }
5620
5707
  addToFav(item, type) {
5621
5708
  if (type == 'ADD')
@@ -5774,6 +5861,7 @@ class Cart {
5774
5861
  this.platform = json?.["platform"];
5775
5862
  this.locationDetails = json?.["locationDetails"];
5776
5863
  this.userDetails = json?.["userDetails"];
5864
+ this.totalAmount = 0;
5777
5865
  }
5778
5866
  }
5779
5867