ng-easycommerce 0.0.570 → 0.0.572

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 (32) hide show
  1. package/README.md +7 -0
  2. package/assets/bancardCatastro.html +1 -1
  3. package/assets/ec-i18n/ct.json +2 -1
  4. package/assets/ec-i18n/en.json +2 -1
  5. package/assets/ec-i18n/es.json +2 -1
  6. package/assets/ec-i18n/fr.json +2 -1
  7. package/assets/ec-i18n/gl.json +2 -1
  8. package/assets/ec-i18n/pr.json +2 -1
  9. package/bundles/ng-easycommerce.umd.js +113 -3
  10. package/bundles/ng-easycommerce.umd.js.map +1 -1
  11. package/bundles/ng-easycommerce.umd.min.js +1 -1
  12. package/bundles/ng-easycommerce.umd.min.js.map +1 -1
  13. package/esm2015/lib/ec-component/build-your-ec/build-your-ec.component.js +2 -2
  14. package/esm2015/lib/ec-component/cart-ec/cart-ec.component.js +9 -2
  15. package/esm2015/lib/ec-component/header-ec/header-ec.component.js +7 -1
  16. package/esm2015/lib/services/cart.service.js +66 -2
  17. package/esm2015/lib/services/products/product-detail.service.js +29 -1
  18. package/esm5/lib/ec-component/build-your-ec/build-your-ec.component.js +2 -2
  19. package/esm5/lib/ec-component/cart-ec/cart-ec.component.js +9 -2
  20. package/esm5/lib/ec-component/header-ec/header-ec.component.js +8 -1
  21. package/esm5/lib/services/cart.service.js +70 -2
  22. package/esm5/lib/services/products/product-detail.service.js +29 -1
  23. package/fesm2015/ng-easycommerce.js +108 -3
  24. package/fesm2015/ng-easycommerce.js.map +1 -1
  25. package/fesm5/ng-easycommerce.js +113 -3
  26. package/fesm5/ng-easycommerce.js.map +1 -1
  27. package/lib/ec-component/cart-ec/cart-ec.component.d.ts +2 -2
  28. package/lib/ec-component/header-ec/header-ec.component.d.ts +3 -0
  29. package/lib/services/cart.service.d.ts +19 -0
  30. package/lib/services/products/product-detail.service.d.ts +9 -3
  31. package/ng-easycommerce.metadata.json +1 -1
  32. package/package.json +1 -1
@@ -4538,6 +4538,14 @@ var CartService = /** @class */ (function () {
4538
4538
  this.cartSubject = new BehaviorSubject(null);
4539
4539
  this.requestInProcess = new BehaviorSubject(false);
4540
4540
  this.promotionsSubject = new BehaviorSubject([]);
4541
+ this.balanceCustomerSubject = new BehaviorSubject({
4542
+ allowAnyPaymentMethod: false,
4543
+ allowExceedBalance: false,
4544
+ creditAmount: 0,
4545
+ showMax: false,
4546
+ showPrice: false,
4547
+ remainingCredits: 0,
4548
+ });
4541
4549
  this.items = [];
4542
4550
  this.count = 0;
4543
4551
  this.locale = "";
@@ -4559,6 +4567,12 @@ var CartService = /** @class */ (function () {
4559
4567
  this.cart = this.cartSubject.asObservable();
4560
4568
  this.promotions = this.promotionsSubject.asObservable();
4561
4569
  this.deleting = false;
4570
+ this.balanceCustomer$ = this.balanceCustomerSubject.asObservable();
4571
+ this.allowAnyPaymentMethod$ = this.balanceCustomer$.pipe(map(function (data) { return data.allowAnyPaymentMethod; }));
4572
+ this.allowExceedBalance$ = this.balanceCustomer$.pipe(map(function (data) { return data.allowExceedBalance; }));
4573
+ this.creditAmount$ = this.balanceCustomer$.pipe(map(function (data) { return data.creditAmount; }));
4574
+ this.showMax$ = this.balanceCustomer$.pipe(map(function (data) { return data.showMax; }));
4575
+ this.showPrice$ = this.balanceCustomer$.pipe(map(function (data) { return data.showPrice; }));
4562
4576
  this.getAddressBook = function () { return __awaiter$5(_this, void 0, void 0, function () { return __generator$5(this, function (_a) {
4563
4577
  return [2 /*return*/, this.connection.get(this.addressBookApi()).pipe(map(function (res) { var _a; return ((_a = res) === null || _a === void 0 ? void 0 : _a.length) && res.map(function (addres) { return addres && __assign$9(__assign$9({}, addres), { selected: addres.default }); }) || null; })).toPromise()];
4564
4578
  }); }); };
@@ -4668,6 +4682,7 @@ var CartService = /** @class */ (function () {
4668
4682
  this.resetCart = function (next) {
4669
4683
  _this.items = [];
4670
4684
  _this.cartSubject.next(null);
4685
+ _this.updateBalanceAttributes(null);
4671
4686
  _this.cart_token = null;
4672
4687
  _this.cartItemsSubject.next([]);
4673
4688
  _this.count = 0;
@@ -4678,6 +4693,7 @@ var CartService = /** @class */ (function () {
4678
4693
  this.updateCartObj = function (cart, emitEvent) {
4679
4694
  if (emitEvent === void 0) { emitEvent = true; }
4680
4695
  _this.cartSubject.next(cart);
4696
+ _this.updateBalanceAttributes(cart);
4681
4697
  emitEvent && _this.analyticsService.callEvent('add_to_cart', cart);
4682
4698
  _this.promotionsSubject.next(_this.orderUtils.getPromotions(cart, true));
4683
4699
  cart.couponCode
@@ -4784,7 +4800,7 @@ var CartService = /** @class */ (function () {
4784
4800
  return __spread$3(items, paramsMerge);
4785
4801
  };
4786
4802
  this.updateItemQuantity = function (item, quantity) {
4787
- if (_this.validateQuantity(item, quantity)) {
4803
+ if (_this.validateQuantity(item, quantity) && (_this.validatePriceAndCredits(item, quantity))) {
4788
4804
  _this.connection.put(_this.updateItemQuantityApi(_this.findItemByIdVariant(item.variant_id)), { 'quantity': Number(quantity) }).subscribe(function (res) { return _this.updateCartObj(res) && _this.updateCartItemQuantity(item.variant_id, Number(quantity)); }, function (err) { return _this.handleError(err); });
4789
4805
  }
4790
4806
  };
@@ -4799,6 +4815,38 @@ var CartService = /** @class */ (function () {
4799
4815
  }
4800
4816
  return true;
4801
4817
  };
4818
+ this.validatePriceAndCredits = function (item, quantity) {
4819
+ if (_this.balanceCustomerSubject.value.creditAmount === null) {
4820
+ return true;
4821
+ }
4822
+ if (_this.balanceCustomerSubject.value.remainingCredits === undefined) {
4823
+ return false;
4824
+ }
4825
+ var unitPrice = item.total / item.quantity;
4826
+ var additionalQuantity = quantity - item.quantity;
4827
+ if (additionalQuantity <= 0) {
4828
+ return true;
4829
+ }
4830
+ var additionalCost = unitPrice * additionalQuantity;
4831
+ if (additionalCost > _this.balanceCustomerSubject.value.remainingCredits) {
4832
+ _this.toastrService.show('not-enough-credits');
4833
+ return false;
4834
+ }
4835
+ return true;
4836
+ };
4837
+ this.hasSufficientCreditsForCartTotal = function () {
4838
+ if (_this.balanceCustomerSubject.value.creditAmount === null) {
4839
+ return true;
4840
+ }
4841
+ if (_this.balanceCustomerSubject.value.remainingCredits === undefined) {
4842
+ return false;
4843
+ }
4844
+ if (_this.cartSubject.value.totals.total > _this.balanceCustomerSubject.value.creditAmount) {
4845
+ _this.toastrService.show('not-enough-credits');
4846
+ return false;
4847
+ }
4848
+ return true;
4849
+ };
4802
4850
  this.calculateStockCounts = function (item, quantity) {
4803
4851
  if (item.product.stock < item.quantity + quantity) {
4804
4852
  // this.toastrService.show('out-of-stock');
@@ -4944,6 +4992,12 @@ var CartService = /** @class */ (function () {
4944
4992
  // }, 100);
4945
4993
  return item;
4946
4994
  }); };
4995
+ this.getCreditAmount = function () {
4996
+ return _this.balanceCustomerSubject.pipe(map(function (balanceCustomer) { var _a, _b; return _b = (_a = balanceCustomer) === null || _a === void 0 ? void 0 : _a.creditAmount, (_b !== null && _b !== void 0 ? _b : null); }));
4997
+ };
4998
+ this.getRemainingCredits = function () {
4999
+ return _this.balanceCustomerSubject.pipe(map(function (balanceCustomer) { var _a; return (_a = balanceCustomer) === null || _a === void 0 ? void 0 : _a.remainingCredits; }));
5000
+ };
4947
5001
  this.requestInProcess.next(true);
4948
5002
  this.items = JSON.parse(localStorage.getItem('cart')) || [];
4949
5003
  this.cart_token = localStorage.getItem('cart_token') || null;
@@ -5017,6 +5071,20 @@ var CartService = /** @class */ (function () {
5017
5071
  return subtotal - total;
5018
5072
  }));
5019
5073
  };
5074
+ CartService$1.prototype.updateBalanceAttributes = function (cartData) {
5075
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
5076
+ var balanceData = {
5077
+ allowAnyPaymentMethod: (_b = (_a = cartData) === null || _a === void 0 ? void 0 : _a.allowAnyPaymentMethod, (_b !== null && _b !== void 0 ? _b : false)),
5078
+ allowExceedBalance: (_d = (_c = cartData) === null || _c === void 0 ? void 0 : _c.allowExceedBalance, (_d !== null && _d !== void 0 ? _d : false)),
5079
+ creditAmount: (_f = (_e = cartData) === null || _e === void 0 ? void 0 : _e.creditAmount, (_f !== null && _f !== void 0 ? _f : null)),
5080
+ showMax: (_h = (_g = cartData) === null || _g === void 0 ? void 0 : _g.showMax, (_h !== null && _h !== void 0 ? _h : false)),
5081
+ showPrice: (_k = (_j = cartData) === null || _j === void 0 ? void 0 : _j.showPrice, (_k !== null && _k !== void 0 ? _k : false)),
5082
+ remainingCredits: ((_l = cartData) === null || _l === void 0 ? void 0 : _l.creditAmount) && ((_m = cartData) === null || _m === void 0 ? void 0 : _m.creditAmount) >= ((_o = cartData) === null || _o === void 0 ? void 0 : _o.totals.total)
5083
+ ? ((_p = cartData) === null || _p === void 0 ? void 0 : _p.creditAmount) - ((_q = cartData) === null || _q === void 0 ? void 0 : _q.totals.total)
5084
+ : 0,
5085
+ };
5086
+ this.balanceCustomerSubject.next(balanceData);
5087
+ };
5020
5088
  CartService$1.ctorParameters = function () { return [
5021
5089
  { type: ConnectionService },
5022
5090
  { type: ToastService },
@@ -7222,7 +7290,14 @@ var CartEcComponent = /** @class */ (function (_super) {
7222
7290
  cantidad > 0 && cantidad <= stock ? _this.cartService.updateItemQuantity(item, cantidad) : _this.toastrService.show('out-of-stock-actually');
7223
7291
  }
7224
7292
  };
7225
- _this.redirectCheckout = function () { return _this.router.navigateByUrl("/checkout"); };
7293
+ _this.redirectCheckout = function () {
7294
+ if (_this.cartService.hasSufficientCreditsForCartTotal()) {
7295
+ _this.router.navigateByUrl("/checkout");
7296
+ }
7297
+ else {
7298
+ console.warn("No se puede redirigir al checkout debido a una validación fallida.");
7299
+ }
7300
+ };
7226
7301
  _this.redirectRegister = function () { return _this.router.navigateByUrl("/auth/login"); };
7227
7302
  _this.getVariants = function (product) {
7228
7303
  var item = product.product;
@@ -9500,8 +9575,15 @@ var HeaderEcComponent = /** @class */ (function (_super) {
9500
9575
  this.paramsService.parameters.subscribe(function (res) { return _this.params = res; });
9501
9576
  var mediaQuery = window.matchMedia('(max-width: 992px)');
9502
9577
  this.mediaMenu = mediaQuery.matches;
9578
+ this.subscribeToBalance();
9503
9579
  this.ecOnInit();
9504
9580
  };
9581
+ HeaderEcComponent.prototype.subscribeToBalance = function () {
9582
+ var _this = this;
9583
+ this.balanceSubscription = this.cartService.balanceCustomer$.subscribe(function (balanceData) {
9584
+ _this.balanceAttributes = balanceData;
9585
+ });
9586
+ };
9505
9587
  HeaderEcComponent.ctorParameters = function () { return [
9506
9588
  { type: Router },
9507
9589
  { type: Constants },
@@ -9990,6 +10072,7 @@ var ProductDetailService = /** @class */ (function () {
9990
10072
  _this.optionsSubject.next(_this.getOptions());
9991
10073
  variant_code ? _this.updateVariants(variant_code) : _this.updateVariants();
9992
10074
  _this.variants.length && _this.generateAsociatedDataFromVariants();
10075
+ _this.fetchCartData();
9993
10076
  //this.analyticsService.callEvent('view_item', { ...product, currency: this.constants.currency.code })
9994
10077
  // variant_code && this.analyticsService.callEvent('view_item', { ...product, currency: this.constants.currency.code })
9995
10078
  };
@@ -10202,6 +10285,31 @@ var ProductDetailService = /** @class */ (function () {
10202
10285
  }
10203
10286
  return true;
10204
10287
  };
10288
+ this.validatePriceAndCredits = function (price) {
10289
+ if (_this.creditAmount === null) {
10290
+ console.log('No hay configuración de créditos para este usuario.');
10291
+ return true;
10292
+ }
10293
+ if (_this.remainingCredits === undefined) {
10294
+ return false;
10295
+ }
10296
+ if (price > _this.remainingCredits) {
10297
+ _this.toastrService.show('not-enough-credits');
10298
+ return false;
10299
+ }
10300
+ return true;
10301
+ };
10302
+ this.fetchCartData = function () {
10303
+ _this.cartService.getTotalAmount().subscribe(function (totalAmount) {
10304
+ _this.currentTotalAmount = totalAmount;
10305
+ });
10306
+ _this.cartService.getCreditAmount().subscribe(function (creditAmount) {
10307
+ _this.creditAmount = creditAmount;
10308
+ });
10309
+ _this.cartService.getRemainingCredits().subscribe(function (remainingCredits) {
10310
+ _this.remainingCredits = remainingCredits;
10311
+ });
10312
+ };
10205
10313
  // Cuando haya modelos de respuesta, validamos que no se intente cargar un producto incompleto
10206
10314
  this.isProductValid = function (product) { return true; };
10207
10315
  /**
@@ -10256,6 +10364,8 @@ var ProductDetailService = /** @class */ (function () {
10256
10364
  return;
10257
10365
  if (!this.validateQuantity(quantity))
10258
10366
  return;
10367
+ if (!this.validatePriceAndCredits(product_selected.price * quantity))
10368
+ return;
10259
10369
  this.cartService.addToCart(this.makeAffordableProduct(product_selected), quantity, variant.code);
10260
10370
  };
10261
10371
  ;
@@ -15962,7 +16072,7 @@ var BuildYourEcComponent = /** @class */ (function (_super) {
15962
16072
  _this.prev = function (index) {
15963
16073
  if (index === void 0) { index = -1; }
15964
16074
  _this.values.pop();
15965
- _this.attributes.pop();
16075
+ // this.attributes.pop();
15966
16076
  _this.total.pop();
15967
16077
  _this.taxonCode = 0;
15968
16078
  _this.noMoreCoincidences = false;