ng-easycommerce 0.0.654 → 0.0.656-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 (34) hide show
  1. package/README.md +6 -0
  2. package/bundles/ng-easycommerce.umd.js +90 -27
  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 +2 -1
  7. package/esm2015/lib/ec-component/auth-ec/select-channel-ec/select-channel-ec.component.js +8 -1
  8. package/esm2015/lib/ec-component/cart-ec/cart-ec.component.js +5 -4
  9. package/esm2015/lib/ec-component/header-ec/header-ec.component.js +1 -1
  10. package/esm2015/lib/ec-component/product-detail-ec/product-detail-ec.component.js +27 -2
  11. package/esm2015/lib/ec-component/product-ec/product-ec.component.js +1 -2
  12. package/esm2015/lib/ec-component/sidebar-ec/sidebar-ec.component.js +5 -4
  13. package/esm2015/lib/ec-component/widgets-ec/paypal-express-ec/paypal-express-ec.component.js +1 -3
  14. package/esm2015/lib/services/cart.service.js +27 -12
  15. package/esm5/lib/core.consts.js +2 -1
  16. package/esm5/lib/ec-component/auth-ec/select-channel-ec/select-channel-ec.component.js +8 -1
  17. package/esm5/lib/ec-component/cart-ec/cart-ec.component.js +5 -4
  18. package/esm5/lib/ec-component/header-ec/header-ec.component.js +1 -1
  19. package/esm5/lib/ec-component/product-detail-ec/product-detail-ec.component.js +45 -2
  20. package/esm5/lib/ec-component/product-ec/product-ec.component.js +1 -2
  21. package/esm5/lib/ec-component/sidebar-ec/sidebar-ec.component.js +5 -4
  22. package/esm5/lib/ec-component/widgets-ec/paypal-express-ec/paypal-express-ec.component.js +1 -3
  23. package/esm5/lib/services/cart.service.js +27 -12
  24. package/fesm2015/ng-easycommerce.js +67 -22
  25. package/fesm2015/ng-easycommerce.js.map +1 -1
  26. package/fesm5/ng-easycommerce.js +91 -28
  27. package/fesm5/ng-easycommerce.js.map +1 -1
  28. package/lib/core.consts.d.ts +1 -0
  29. package/lib/ec-component/auth-ec/select-channel-ec/select-channel-ec.component.d.ts +1 -0
  30. package/lib/ec-component/header-ec/header-ec.component.d.ts +1 -1
  31. package/lib/ec-component/product-detail-ec/product-detail-ec.component.d.ts +2 -0
  32. package/lib/services/cart.service.d.ts +2 -2
  33. package/ng-easycommerce.metadata.json +1 -1
  34. 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';
@@ -188,6 +188,7 @@ let Constants = class Constants {
188
188
  this.LOCALE = 'LOCALE';
189
189
  this.CHANNEL = 'CHANNEL';
190
190
  this.searchValue = '';
191
+ this.channelSelected = '';
191
192
  this.channelConfigSubject = new ReplaySubject();
192
193
  this.channelConfig$ = this.channelConfigSubject.asObservable();
193
194
  this.channelConfigAPI = (channel) => '/shop-api/' + channel + 'channel';
@@ -4037,12 +4038,22 @@ let CartService = class CartService {
4037
4038
  this.updateLocalCart();
4038
4039
  this.requestInProcess.next(false);
4039
4040
  };
4040
- this.updateCartItemQuantity = (variant_id, quantity) => {
4041
- let newQuantity = this.items.find(item => item.variant_id == variant_id).quantity = quantity;
4041
+ this.updateCartItemQuantity = (variant_id, quantity, comments) => {
4042
+ const normalizedComments = comments !== undefined ? ((comments !== null && comments !== void 0 ? comments : '')).trim() : undefined;
4043
+ const newItems = this.items.map(it => {
4044
+ if (it.variant_id !== variant_id)
4045
+ return it;
4046
+ const updated = Object.assign(Object.assign({}, it), { quantity: Number(quantity) });
4047
+ if (normalizedComments !== undefined) {
4048
+ updated.comments = normalizedComments;
4049
+ }
4050
+ return updated;
4051
+ });
4052
+ this.items = newItems;
4042
4053
  this.cartItemsSubject.next(this.items);
4043
4054
  this.requestInProcess.next(false);
4044
4055
  this.updateLocalCart();
4045
- this.toastrService.show('product-updated', { quantity: newQuantity });
4056
+ this.toastrService.show('product-updated', { quantity });
4046
4057
  };
4047
4058
  this.appendToCart = (cart) => {
4048
4059
  this.updateCartObj(cart);
@@ -4063,9 +4074,9 @@ let CartService = class CartService {
4063
4074
  // this.googleAnalytics.removeFromCart(product);
4064
4075
  this.analyticsService.callEvent('remove_from_cart', Object.assign(Object.assign({}, product), { currency: this.consts.currency.code }));
4065
4076
  };
4066
- this.addIfAllreadyExists = (product, variant_id, quantityAdd = 1) => this.items.find((item, index) => {
4077
+ this.addIfAllreadyExists = (product, variant_id, quantityAdd = 1, comments) => this.items.find((item, index) => {
4067
4078
  if (item.product.id == product.id && item.variant_id == variant_id) {
4068
- this.updateItemQuantity(item, this.findItem(product.id).quantity + quantityAdd);
4079
+ this.updateItemQuantity(item, this.findItem(product.id).quantity + quantityAdd, comments);
4069
4080
  return true;
4070
4081
  }
4071
4082
  return false;
@@ -4117,7 +4128,7 @@ let CartService = class CartService {
4117
4128
  return;
4118
4129
  }
4119
4130
  this.requestInProcess.next(true);
4120
- let added = this.addIfAllreadyExists(product, variant_id, quantity);
4131
+ let added = this.addIfAllreadyExists(product, variant_id, quantity, comments);
4121
4132
  if (!added) {
4122
4133
  const payload = {
4123
4134
  productCode: product.id,
@@ -4157,13 +4168,13 @@ let CartService = class CartService {
4157
4168
  !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' })
4158
4169
  .subscribe(res => this.appendToCart(res), err => this.handleError(err));
4159
4170
  };
4160
- this.addToCartPromise = (product, quantity, variant_id) => __awaiter$5(this, void 0, void 0, function* () {
4171
+ this.addToCartPromise = (product, quantity, variant_id, comments) => __awaiter$5(this, void 0, void 0, function* () {
4161
4172
  if (!this.authService.isAbleToBuy()) {
4162
4173
  this.toastrService.show('must-select-customer');
4163
4174
  return;
4164
4175
  }
4165
4176
  this.requestInProcess.next(true);
4166
- let added = this.addIfAllreadyExists(product, variant_id, quantity);
4177
+ let added = this.addIfAllreadyExists(product, variant_id, quantity, comments);
4167
4178
  if (!added) {
4168
4179
  let result = yield (this.connection.post(this.addItemApi(), { productCode: product.id, quantity: quantity, variantCode: variant_id }).toPromise());
4169
4180
  if (!result || result.error)
@@ -4205,13 +4216,18 @@ let CartService = class CartService {
4205
4216
  items = items.filter(itemParam => !this.items.find(item => itemParam.variantCode == item.variant_id));
4206
4217
  return [...items, ...paramsMerge];
4207
4218
  };
4208
- this.updateItemQuantity = (item, quantity) => {
4219
+ this.updateItemQuantity = (item, quantity, comments) => {
4209
4220
  if (this.validateQuantity(item, quantity) && (this.validatePriceAndCredits(item, quantity))) {
4210
4221
  this.requestInProcess.next(true);
4222
+ const payload = { quantity: Number(quantity) };
4223
+ if (comments !== undefined) {
4224
+ const cleaned = ((comments !== null && comments !== void 0 ? comments : '')).trim();
4225
+ payload.comments = cleaned;
4226
+ }
4211
4227
  this.connection
4212
- .put(this.updateItemQuantityApi(this.findItemByIdVariant(item.variant_id)), { 'quantity': Number(quantity) })
4228
+ .put(this.updateItemQuantityApi(this.findItemByIdVariant(item.variant_id)), payload)
4213
4229
  .pipe(finalize(() => this.requestInProcess.next(false)))
4214
- .subscribe(res => this.updateCartObj(res) && this.updateCartItemQuantity(item.variant_id, Number(quantity)), err => this.handleError(err));
4230
+ .subscribe(res => this.updateCartObj(res) && this.updateCartItemQuantity(item.variant_id, Number(quantity), comments), err => this.handleError(err));
4215
4231
  }
4216
4232
  };
4217
4233
  this.validateQuantity = (item, quantity) => {
@@ -6390,7 +6406,7 @@ let CartEcComponent = class CartEcComponent extends ComponentHelper {
6390
6406
  this.ecOnInit();
6391
6407
  }
6392
6408
  actualizarCantidad(item, cantidad, stock, id) {
6393
- var _a;
6409
+ var _a, _b, _c;
6394
6410
  if (this.cartLoading) {
6395
6411
  return;
6396
6412
  }
@@ -6410,10 +6426,11 @@ let CartEcComponent = class CartEcComponent extends ComponentHelper {
6410
6426
  newQuantity = Math.round(newQuantity / step) * step;
6411
6427
  }
6412
6428
  }
6429
+ const keepSameComment = (_c = (_b = item) === null || _b === void 0 ? void 0 : _b.comments, (_c !== null && _c !== void 0 ? _c : undefined));
6413
6430
  if (id) {
6414
6431
  this.isDisabled = true; // Actualiza la propiedad vinculada a `[disabled]`
6415
6432
  if (newQuantity > 0 && newQuantity <= stock) {
6416
- this.cartService.updateItemQuantity(item, newQuantity);
6433
+ this.cartService.updateItemQuantity(item, newQuantity, keepSameComment);
6417
6434
  }
6418
6435
  else {
6419
6436
  this.toastrService.show('out-of-stock-actually');
@@ -6424,7 +6441,7 @@ let CartEcComponent = class CartEcComponent extends ComponentHelper {
6424
6441
  }
6425
6442
  else {
6426
6443
  if (newQuantity > 0 && newQuantity <= stock) {
6427
- this.cartService.updateItemQuantity(item, newQuantity);
6444
+ this.cartService.updateItemQuantity(item, newQuantity, keepSameComment);
6428
6445
  }
6429
6446
  else {
6430
6447
  this.toastrService.show('out-of-stock-actually');
@@ -9322,7 +9339,8 @@ let ProductDetailEcComponent = class ProductDetailEcComponent extends ComponentH
9322
9339
  this.enableFieldNotesInArticleFile = false;
9323
9340
  this.addToCart = () => {
9324
9341
  var _a;
9325
- this.quantity > 0 && this.productService.addToCart(this.quantity, undefined, ((_a = this.comments) === null || _a === void 0 ? void 0 : _a.trim()) || null);
9342
+ const note = ((_a = this.comments) === null || _a === void 0 ? void 0 : _a.trim()) || null;
9343
+ this.quantity > 0 && this.productService.addToCart(this.quantity, undefined, note);
9326
9344
  };
9327
9345
  this.addAllProductosToCart = () => {
9328
9346
  var _a, _b;
@@ -9441,6 +9459,28 @@ let ProductDetailEcComponent = class ProductDetailEcComponent extends ComponentH
9441
9459
  }
9442
9460
  ngOnInit() {
9443
9461
  this.ecOnInit();
9462
+ // Prellenar comentarios cuando:
9463
+ // - cargue el producto
9464
+ // - cambie la variante seleccionada (asociatedData$)
9465
+ // - cambien los ítems del carrito
9466
+ this.prefillSub = combineLatest([
9467
+ this.productService.product$.pipe(filter((p) => !!p && !!p.id)),
9468
+ this.productService.asociatedData$.pipe(startWith(null)),
9469
+ this.cartService.cartItems.pipe(startWith([])),
9470
+ ]).subscribe(([product, data, items]) => {
9471
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
9472
+ 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));
9473
+ const match = (_j = items) === null || _j === void 0 ? void 0 : _j.find(it => {
9474
+ var _a, _b, _c, _d;
9475
+ 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) &&
9476
+ (variantId ? ((_d = it) === null || _d === void 0 ? void 0 : _d.variant_id) === variantId : true);
9477
+ });
9478
+ this.comments = (_l = (_k = match) === null || _k === void 0 ? void 0 : _k.comments, (_l !== null && _l !== void 0 ? _l : ''));
9479
+ });
9480
+ }
9481
+ ngOnDestroy() {
9482
+ var _a;
9483
+ (_a = this.prefillSub) === null || _a === void 0 ? void 0 : _a.unsubscribe();
9444
9484
  }
9445
9485
  scroll() {
9446
9486
  let el = this.contact.nativeElement;
@@ -9571,7 +9611,6 @@ let ProductEcComponent = class ProductEcComponent extends ComponentHelper {
9571
9611
  ngOnChanges() {
9572
9612
  }
9573
9613
  selectItem(product) {
9574
- console.log('entro');
9575
9614
  this.analyticsService.callEvent('select_item', product);
9576
9615
  }
9577
9616
  };
@@ -12903,12 +12942,10 @@ let PaypalExpressEcComponent = class PaypalExpressEcComponent extends ComponentH
12903
12942
  this.loading = false;
12904
12943
  }
12905
12944
  else {
12906
- /* console.log('Entro al else'); */
12907
12945
  this.renderPayPal();
12908
12946
  }
12909
12947
  }
12910
12948
  catch (error) {
12911
- /* console.log('Entro al catch'); */
12912
12949
  this.renderPayPal();
12913
12950
  }
12914
12951
  }, 1000);
@@ -13421,6 +13458,9 @@ let SelectChannelEcComponent = class SelectChannelEcComponent extends ComponentH
13421
13458
  this.modalService = modalService;
13422
13459
  this.router = router;
13423
13460
  this.channels = [];
13461
+ this.unloadHandler = () => {
13462
+ this.authService.logout();
13463
+ };
13424
13464
  this.navigateByUrl = () => {
13425
13465
  this.router.navigateByUrl('');
13426
13466
  };
@@ -13434,7 +13474,9 @@ let SelectChannelEcComponent = class SelectChannelEcComponent extends ComponentH
13434
13474
  this.bsModalRef = this.modalService.show(this.template, { class: 'modal modal-dialog-centered ', keyboard: false, backdrop: 'static', animated: true });
13435
13475
  this.subsModal = this.modalService.onHide.subscribe(onClose => {
13436
13476
  this.bsModalRef = null;
13477
+ window.removeEventListener('unload', this.unloadHandler);
13437
13478
  });
13479
+ window.addEventListener('unload', this.unloadHandler);
13438
13480
  }
13439
13481
  };
13440
13482
  this.setSelect = (chanelSelect) => {
@@ -13448,6 +13490,7 @@ let SelectChannelEcComponent = class SelectChannelEcComponent extends ComponentH
13448
13490
  if (this.channels.find(chanel => chanel.selected)) {
13449
13491
  this.authService.channelAccess(this.channels.find(chanel => chanel.selected));
13450
13492
  this.bsModalRef.hide();
13493
+ window.removeEventListener('unload', this.unloadHandler);
13451
13494
  }
13452
13495
  };
13453
13496
  }
@@ -13464,6 +13507,7 @@ let SelectChannelEcComponent = class SelectChannelEcComponent extends ComponentH
13464
13507
  var _a, _b;
13465
13508
  (_a = this.subs) === null || _a === void 0 ? void 0 : _a.unsubscribe();
13466
13509
  (_b = this.subsModal) === null || _b === void 0 ? void 0 : _b.unsubscribe();
13510
+ window.removeEventListener('unload', this.unloadHandler);
13467
13511
  }
13468
13512
  };
13469
13513
  SelectChannelEcComponent.ctorParameters = () => [
@@ -16327,7 +16371,7 @@ let SidebarEcComponent = class SidebarEcComponent {
16327
16371
  });
16328
16372
  }
16329
16373
  actualizarCantidad(item, cantidad, stock, id) {
16330
- var _a;
16374
+ var _a, _b, _c;
16331
16375
  if (this.cartLoading) {
16332
16376
  return;
16333
16377
  }
@@ -16347,13 +16391,14 @@ let SidebarEcComponent = class SidebarEcComponent {
16347
16391
  newQuantity = Math.round(newQuantity / step) * step;
16348
16392
  }
16349
16393
  }
16394
+ const keepSameComment = (_c = (_b = item) === null || _b === void 0 ? void 0 : _b.comments, (_c !== null && _c !== void 0 ? _c : undefined));
16350
16395
  if (id) {
16351
16396
  const elem = document.getElementById(id);
16352
16397
  if (elem) {
16353
16398
  elem.disabled = true;
16354
16399
  }
16355
16400
  if (newQuantity > 0 && newQuantity <= stock) {
16356
- this.cartService.updateItemQuantity(item, newQuantity);
16401
+ this.cartService.updateItemQuantity(item, newQuantity, keepSameComment);
16357
16402
  }
16358
16403
  else {
16359
16404
  this.toastrService.show('out-of-stock-actually');
@@ -16366,7 +16411,7 @@ let SidebarEcComponent = class SidebarEcComponent {
16366
16411
  }
16367
16412
  else {
16368
16413
  if (newQuantity > 0 && newQuantity <= stock) {
16369
- this.cartService.updateItemQuantity(item, newQuantity);
16414
+ this.cartService.updateItemQuantity(item, newQuantity, keepSameComment);
16370
16415
  }
16371
16416
  }
16372
16417
  }