ng-easycommerce 0.0.653 → 0.0.655-beta.1

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/README.md +6 -0
  2. package/bundles/ng-easycommerce.umd.js +96 -30
  3. package/bundles/ng-easycommerce.umd.js.map +1 -1
  4. package/bundles/ng-easycommerce.umd.min.js +1 -1
  5. package/bundles/ng-easycommerce.umd.min.js.map +1 -1
  6. package/esm2015/lib/core.consts.js +6 -1
  7. package/esm2015/lib/ec-component/cart-ec/cart-ec.component.js +5 -4
  8. package/esm2015/lib/ec-component/checkout-ec/dataform-ec/dataform-ec.component.js +10 -4
  9. package/esm2015/lib/ec-component/product-detail-ec/product-detail-ec.component.js +27 -2
  10. package/esm2015/lib/ec-component/product-ec/product-ec.component.js +1 -2
  11. package/esm2015/lib/ec-component/sidebar-ec/sidebar-ec.component.js +5 -4
  12. package/esm2015/lib/ec-component/widgets-ec/paypal-express-ec/paypal-express-ec.component.js +1 -3
  13. package/esm2015/lib/services/cart.service.js +27 -12
  14. package/esm5/lib/core.consts.js +6 -1
  15. package/esm5/lib/ec-component/cart-ec/cart-ec.component.js +5 -4
  16. package/esm5/lib/ec-component/checkout-ec/dataform-ec/dataform-ec.component.js +10 -4
  17. package/esm5/lib/ec-component/product-detail-ec/product-detail-ec.component.js +45 -2
  18. package/esm5/lib/ec-component/product-ec/product-ec.component.js +1 -2
  19. package/esm5/lib/ec-component/sidebar-ec/sidebar-ec.component.js +5 -4
  20. package/esm5/lib/ec-component/widgets-ec/paypal-express-ec/paypal-express-ec.component.js +1 -3
  21. package/esm5/lib/services/cart.service.js +27 -12
  22. package/fesm2015/ng-easycommerce.js +73 -25
  23. package/fesm2015/ng-easycommerce.js.map +1 -1
  24. package/fesm5/ng-easycommerce.js +97 -31
  25. package/fesm5/ng-easycommerce.js.map +1 -1
  26. package/lib/core.consts.d.ts +5 -0
  27. package/lib/ec-component/product-detail-ec/product-detail-ec.component.d.ts +2 -0
  28. package/lib/services/cart.service.d.ts +2 -2
  29. package/ng-easycommerce.metadata.json +1 -1
  30. package/package.json +1 -1
@@ -7,7 +7,7 @@ import { InfiniteScrollModule } from 'ngx-infinite-scroll';
7
7
  import { ToastrService, ToastrModule } from 'ngx-toastr';
8
8
  import { ReplaySubject, of, BehaviorSubject, forkJoin, combineLatest, Observable, throwError } from 'rxjs';
9
9
  import 'rxjs/add/operator/map';
10
- import { take, map, catchError, filter, mapTo, finalize, skipWhile, concatMap } from 'rxjs/operators';
10
+ import { take, map, catchError, filter, mapTo, finalize, startWith, skipWhile, concatMap } from 'rxjs/operators';
11
11
  import 'rxjs/add/operator/catch';
12
12
  import 'rxjs/add/observable/of';
13
13
  import * as moment from 'moment';
@@ -469,6 +469,11 @@ let Constants = class Constants {
469
469
  * @example ['AR','ES','GB']
470
470
  */
471
471
  this.countries = [];
472
+ /**
473
+ * @description contiene un arreglo de string cuyo contenido son los codigos de los paises a excluir.
474
+ * @example ['GB']
475
+ */
476
+ this.excludedCountries = [];
472
477
  /**
473
478
  *
474
479
  * @param countries debe contener los codigos de los paises que se quiere mostrar
@@ -4032,12 +4037,22 @@ let CartService = class CartService {
4032
4037
  this.updateLocalCart();
4033
4038
  this.requestInProcess.next(false);
4034
4039
  };
4035
- this.updateCartItemQuantity = (variant_id, quantity) => {
4036
- let newQuantity = this.items.find(item => item.variant_id == variant_id).quantity = quantity;
4040
+ this.updateCartItemQuantity = (variant_id, quantity, comments) => {
4041
+ const normalizedComments = comments !== undefined ? ((comments !== null && comments !== void 0 ? comments : '')).trim() : undefined;
4042
+ const newItems = this.items.map(it => {
4043
+ if (it.variant_id !== variant_id)
4044
+ return it;
4045
+ const updated = Object.assign(Object.assign({}, it), { quantity: Number(quantity) });
4046
+ if (normalizedComments !== undefined) {
4047
+ updated.comments = normalizedComments;
4048
+ }
4049
+ return updated;
4050
+ });
4051
+ this.items = newItems;
4037
4052
  this.cartItemsSubject.next(this.items);
4038
4053
  this.requestInProcess.next(false);
4039
4054
  this.updateLocalCart();
4040
- this.toastrService.show('product-updated', { quantity: newQuantity });
4055
+ this.toastrService.show('product-updated', { quantity });
4041
4056
  };
4042
4057
  this.appendToCart = (cart) => {
4043
4058
  this.updateCartObj(cart);
@@ -4058,9 +4073,9 @@ let CartService = class CartService {
4058
4073
  // this.googleAnalytics.removeFromCart(product);
4059
4074
  this.analyticsService.callEvent('remove_from_cart', Object.assign(Object.assign({}, product), { currency: this.consts.currency.code }));
4060
4075
  };
4061
- this.addIfAllreadyExists = (product, variant_id, quantityAdd = 1) => this.items.find((item, index) => {
4076
+ this.addIfAllreadyExists = (product, variant_id, quantityAdd = 1, comments) => this.items.find((item, index) => {
4062
4077
  if (item.product.id == product.id && item.variant_id == variant_id) {
4063
- this.updateItemQuantity(item, this.findItem(product.id).quantity + quantityAdd);
4078
+ this.updateItemQuantity(item, this.findItem(product.id).quantity + quantityAdd, comments);
4064
4079
  return true;
4065
4080
  }
4066
4081
  return false;
@@ -4112,7 +4127,7 @@ let CartService = class CartService {
4112
4127
  return;
4113
4128
  }
4114
4129
  this.requestInProcess.next(true);
4115
- let added = this.addIfAllreadyExists(product, variant_id, quantity);
4130
+ let added = this.addIfAllreadyExists(product, variant_id, quantity, comments);
4116
4131
  if (!added) {
4117
4132
  const payload = {
4118
4133
  productCode: product.id,
@@ -4152,13 +4167,13 @@ let CartService = class CartService {
4152
4167
  !added && this.connection.post(this.addItemApi(), { productCode: product.id, quantity: quantity, variantCode: variant_id, id: id || '', order_item_id: order_item_id || '', lot_quantity: lot_quantity || '', unit_price: unit_price || '', unit_total: unit_total || '', ajustement_total: ajustement_total || '', total_lot: total_lot || '', lot_status: lot_status || '', date_request: date_request || '', notes: notes || '', shipping_address_id: shipping_address_id || '', shipping_address_name: shipping_address_name || '', action: action || 'newlot' })
4153
4168
  .subscribe(res => this.appendToCart(res), err => this.handleError(err));
4154
4169
  };
4155
- this.addToCartPromise = (product, quantity, variant_id) => __awaiter$5(this, void 0, void 0, function* () {
4170
+ this.addToCartPromise = (product, quantity, variant_id, comments) => __awaiter$5(this, void 0, void 0, function* () {
4156
4171
  if (!this.authService.isAbleToBuy()) {
4157
4172
  this.toastrService.show('must-select-customer');
4158
4173
  return;
4159
4174
  }
4160
4175
  this.requestInProcess.next(true);
4161
- let added = this.addIfAllreadyExists(product, variant_id, quantity);
4176
+ let added = this.addIfAllreadyExists(product, variant_id, quantity, comments);
4162
4177
  if (!added) {
4163
4178
  let result = yield (this.connection.post(this.addItemApi(), { productCode: product.id, quantity: quantity, variantCode: variant_id }).toPromise());
4164
4179
  if (!result || result.error)
@@ -4200,13 +4215,18 @@ let CartService = class CartService {
4200
4215
  items = items.filter(itemParam => !this.items.find(item => itemParam.variantCode == item.variant_id));
4201
4216
  return [...items, ...paramsMerge];
4202
4217
  };
4203
- this.updateItemQuantity = (item, quantity) => {
4218
+ this.updateItemQuantity = (item, quantity, comments) => {
4204
4219
  if (this.validateQuantity(item, quantity) && (this.validatePriceAndCredits(item, quantity))) {
4205
4220
  this.requestInProcess.next(true);
4221
+ const payload = { quantity: Number(quantity) };
4222
+ if (comments !== undefined) {
4223
+ const cleaned = ((comments !== null && comments !== void 0 ? comments : '')).trim();
4224
+ payload.comments = cleaned;
4225
+ }
4206
4226
  this.connection
4207
- .put(this.updateItemQuantityApi(this.findItemByIdVariant(item.variant_id)), { 'quantity': Number(quantity) })
4227
+ .put(this.updateItemQuantityApi(this.findItemByIdVariant(item.variant_id)), payload)
4208
4228
  .pipe(finalize(() => this.requestInProcess.next(false)))
4209
- .subscribe(res => this.updateCartObj(res) && this.updateCartItemQuantity(item.variant_id, Number(quantity)), err => this.handleError(err));
4229
+ .subscribe(res => this.updateCartObj(res) && this.updateCartItemQuantity(item.variant_id, Number(quantity), comments), err => this.handleError(err));
4210
4230
  }
4211
4231
  };
4212
4232
  this.validateQuantity = (item, quantity) => {
@@ -6385,7 +6405,7 @@ let CartEcComponent = class CartEcComponent extends ComponentHelper {
6385
6405
  this.ecOnInit();
6386
6406
  }
6387
6407
  actualizarCantidad(item, cantidad, stock, id) {
6388
- var _a;
6408
+ var _a, _b, _c;
6389
6409
  if (this.cartLoading) {
6390
6410
  return;
6391
6411
  }
@@ -6405,10 +6425,11 @@ let CartEcComponent = class CartEcComponent extends ComponentHelper {
6405
6425
  newQuantity = Math.round(newQuantity / step) * step;
6406
6426
  }
6407
6427
  }
6428
+ const keepSameComment = (_c = (_b = item) === null || _b === void 0 ? void 0 : _b.comments, (_c !== null && _c !== void 0 ? _c : undefined));
6408
6429
  if (id) {
6409
6430
  this.isDisabled = true; // Actualiza la propiedad vinculada a `[disabled]`
6410
6431
  if (newQuantity > 0 && newQuantity <= stock) {
6411
- this.cartService.updateItemQuantity(item, newQuantity);
6432
+ this.cartService.updateItemQuantity(item, newQuantity, keepSameComment);
6412
6433
  }
6413
6434
  else {
6414
6435
  this.toastrService.show('out-of-stock-actually');
@@ -6419,7 +6440,7 @@ let CartEcComponent = class CartEcComponent extends ComponentHelper {
6419
6440
  }
6420
6441
  else {
6421
6442
  if (newQuantity > 0 && newQuantity <= stock) {
6422
- this.cartService.updateItemQuantity(item, newQuantity);
6443
+ this.cartService.updateItemQuantity(item, newQuantity, keepSameComment);
6423
6444
  }
6424
6445
  else {
6425
6446
  this.toastrService.show('out-of-stock-actually');
@@ -6885,18 +6906,24 @@ let DataFormEcComponent = class DataFormEcComponent extends ComponentHelper {
6885
6906
  * @returns un arreglo de countries.
6886
6907
  */
6887
6908
  this.filterCountryByCode = (countries) => {
6909
+ // 1. Si hay países EXCLUIDOS, quítalos siempre
6910
+ let filtered = countries;
6911
+ if (this.consts.excludedCountries && this.consts.excludedCountries.length > 0) {
6912
+ filtered = filtered.filter(elem => !this.consts.excludedCountries.includes(elem.code));
6913
+ }
6914
+ // 2. Si hay países INCLUIDOS, aplica el filtro de inclusión
6888
6915
  if (this.consts.getCountries().length > 0) {
6889
- let countriesFiltered = countries.filter(elem => this.consts.getCountries().includes(elem.code));
6916
+ let countriesFiltered = filtered.filter(elem => this.consts.getCountries().includes(elem.code));
6890
6917
  if (countriesFiltered.length > 0) {
6891
6918
  return countriesFiltered;
6892
6919
  }
6893
6920
  else {
6894
6921
  console.error('El/los codigo/s ingresado/s no coinciden con los provistos desde el backend');
6895
- return countries;
6922
+ return filtered;
6896
6923
  }
6897
6924
  }
6898
6925
  else {
6899
- return countries;
6926
+ return filtered;
6900
6927
  }
6901
6928
  };
6902
6929
  this.showFormFacturacion = () => {
@@ -9311,7 +9338,8 @@ let ProductDetailEcComponent = class ProductDetailEcComponent extends ComponentH
9311
9338
  this.enableFieldNotesInArticleFile = false;
9312
9339
  this.addToCart = () => {
9313
9340
  var _a;
9314
- this.quantity > 0 && this.productService.addToCart(this.quantity, undefined, ((_a = this.comments) === null || _a === void 0 ? void 0 : _a.trim()) || null);
9341
+ const note = ((_a = this.comments) === null || _a === void 0 ? void 0 : _a.trim()) || null;
9342
+ this.quantity > 0 && this.productService.addToCart(this.quantity, undefined, note);
9315
9343
  };
9316
9344
  this.addAllProductosToCart = () => {
9317
9345
  var _a, _b;
@@ -9430,6 +9458,28 @@ let ProductDetailEcComponent = class ProductDetailEcComponent extends ComponentH
9430
9458
  }
9431
9459
  ngOnInit() {
9432
9460
  this.ecOnInit();
9461
+ // Prellenar comentarios cuando:
9462
+ // - cargue el producto
9463
+ // - cambie la variante seleccionada (asociatedData$)
9464
+ // - cambien los ítems del carrito
9465
+ this.prefillSub = combineLatest([
9466
+ this.productService.product$.pipe(filter((p) => !!p && !!p.id)),
9467
+ this.productService.asociatedData$.pipe(startWith(null)),
9468
+ this.cartService.cartItems.pipe(startWith([])),
9469
+ ]).subscribe(([product, data, items]) => {
9470
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
9471
+ const variantId = (_h = (_d = (_b = (_a = data) === null || _a === void 0 ? void 0 : _a.variantCode, (_b !== null && _b !== void 0 ? _b : (_c = data) === null || _c === void 0 ? void 0 : _c.variant_id)), (_d !== null && _d !== void 0 ? _d : (_g = (_f = (_e = product) === null || _e === void 0 ? void 0 : _e.variants) === null || _f === void 0 ? void 0 : _f[0]) === null || _g === void 0 ? void 0 : _g.code)), (_h !== null && _h !== void 0 ? _h : null));
9472
+ const match = (_j = items) === null || _j === void 0 ? void 0 : _j.find(it => {
9473
+ var _a, _b, _c, _d;
9474
+ return ((_b = (_a = it) === null || _a === void 0 ? void 0 : _a.product) === null || _b === void 0 ? void 0 : _b.id) === ((_c = product) === null || _c === void 0 ? void 0 : _c.id) &&
9475
+ (variantId ? ((_d = it) === null || _d === void 0 ? void 0 : _d.variant_id) === variantId : true);
9476
+ });
9477
+ this.comments = (_l = (_k = match) === null || _k === void 0 ? void 0 : _k.comments, (_l !== null && _l !== void 0 ? _l : ''));
9478
+ });
9479
+ }
9480
+ ngOnDestroy() {
9481
+ var _a;
9482
+ (_a = this.prefillSub) === null || _a === void 0 ? void 0 : _a.unsubscribe();
9433
9483
  }
9434
9484
  scroll() {
9435
9485
  let el = this.contact.nativeElement;
@@ -9560,7 +9610,6 @@ let ProductEcComponent = class ProductEcComponent extends ComponentHelper {
9560
9610
  ngOnChanges() {
9561
9611
  }
9562
9612
  selectItem(product) {
9563
- console.log('entro');
9564
9613
  this.analyticsService.callEvent('select_item', product);
9565
9614
  }
9566
9615
  };
@@ -12892,12 +12941,10 @@ let PaypalExpressEcComponent = class PaypalExpressEcComponent extends ComponentH
12892
12941
  this.loading = false;
12893
12942
  }
12894
12943
  else {
12895
- /* console.log('Entro al else'); */
12896
12944
  this.renderPayPal();
12897
12945
  }
12898
12946
  }
12899
12947
  catch (error) {
12900
- /* console.log('Entro al catch'); */
12901
12948
  this.renderPayPal();
12902
12949
  }
12903
12950
  }, 1000);
@@ -16316,7 +16363,7 @@ let SidebarEcComponent = class SidebarEcComponent {
16316
16363
  });
16317
16364
  }
16318
16365
  actualizarCantidad(item, cantidad, stock, id) {
16319
- var _a;
16366
+ var _a, _b, _c;
16320
16367
  if (this.cartLoading) {
16321
16368
  return;
16322
16369
  }
@@ -16336,13 +16383,14 @@ let SidebarEcComponent = class SidebarEcComponent {
16336
16383
  newQuantity = Math.round(newQuantity / step) * step;
16337
16384
  }
16338
16385
  }
16386
+ const keepSameComment = (_c = (_b = item) === null || _b === void 0 ? void 0 : _b.comments, (_c !== null && _c !== void 0 ? _c : undefined));
16339
16387
  if (id) {
16340
16388
  const elem = document.getElementById(id);
16341
16389
  if (elem) {
16342
16390
  elem.disabled = true;
16343
16391
  }
16344
16392
  if (newQuantity > 0 && newQuantity <= stock) {
16345
- this.cartService.updateItemQuantity(item, newQuantity);
16393
+ this.cartService.updateItemQuantity(item, newQuantity, keepSameComment);
16346
16394
  }
16347
16395
  else {
16348
16396
  this.toastrService.show('out-of-stock-actually');
@@ -16355,7 +16403,7 @@ let SidebarEcComponent = class SidebarEcComponent {
16355
16403
  }
16356
16404
  else {
16357
16405
  if (newQuantity > 0 && newQuantity <= stock) {
16358
- this.cartService.updateItemQuantity(item, newQuantity);
16406
+ this.cartService.updateItemQuantity(item, newQuantity, keepSameComment);
16359
16407
  }
16360
16408
  }
16361
16409
  }