@infrab4a/connect-angular 3.7.5 → 3.7.6-beta.0

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.
@@ -796,12 +796,13 @@
796
796
  } });
797
797
 
798
798
  var CartService = /** @class */ (function () {
799
- function CartService(authService, checkoutService, defaultShop, productRepository) {
799
+ function CartService(authService, checkoutService, defaultShop, productRepository, variantRepository) {
800
800
  var _this = this;
801
801
  this.authService = authService;
802
802
  this.checkoutService = checkoutService;
803
803
  this.defaultShop = defaultShop;
804
804
  this.productRepository = productRepository;
805
+ this.variantRepository = variantRepository;
805
806
  this.cartSubject = new rxjs.Subject();
806
807
  this.updateLineItemInCart = function (lineItem, quantity, checkout) { return (i1$1.isNil(checkout) ? _this.checkoutService.getCheckout() : rxjs.of(checkout)).pipe(operators.concatMap(function (checkoutLoaded) {
807
808
  var _a;
@@ -828,17 +829,17 @@
828
829
  this.buildLineItem = function (_h) {
829
830
  var checkout = _h.checkout, item = _h.item, quantity = _h.quantity;
830
831
  return __awaiter(_this, void 0, void 0, function () {
831
- var _a, _b, _c, _d, _e, _f, _g, product, image, id, name, EAN, brand, slug, stock, price, weight, categories, sku, type, isGift, pricePaid;
832
+ var _a, _b, _c, _d, _e, _f, _g, product, image, id, name, EAN, slug, stock, price, weight, sku, type, isGift, pricePaid;
832
833
  return __generator(this, function (_h) {
833
834
  switch (_h.label) {
834
- case 0: return [4 /*yield*/, this.productRepository.get({ id: item.id })];
835
+ case 0: return [4 /*yield*/, this.getProductData(item.id)];
835
836
  case 1:
836
837
  product = _h.sent();
837
838
  item.quantity = (item === null || item === void 0 ? void 0 : item.quantity) || ((_b = (_a = checkout === null || checkout === void 0 ? void 0 : checkout.lineItems) === null || _a === void 0 ? void 0 : _a.find(function (lineItem) { return lineItem.sku === item.sku; })) === null || _b === void 0 ? void 0 : _b.quantity) || 0;
838
839
  if (this.checkMaxStock(item, quantity || 0))
839
840
  throw new Error('Desculpe! Temos apenas ' + ((_c = item.stock) === null || _c === void 0 ? void 0 : _c.quantity) + ' em estoque.');
840
841
  image = item.image || ((_d = item.images) === null || _d === void 0 ? void 0 : _d.shift());
841
- id = item.id, name = item.name, EAN = item.EAN, brand = item.brand, slug = item.slug, stock = item.stock, price = item.price, weight = item.weight, categories = item.categories, sku = item.sku, type = item.type;
842
+ id = item.id, name = item.name, EAN = item.EAN, slug = item.slug, stock = item.stock, price = item.price, weight = item.weight, sku = item.sku, type = item.type;
842
843
  isGift = item.isGift || null;
843
844
  pricePaid = this.getProductPrice({
844
845
  product: item,
@@ -935,7 +936,8 @@
935
936
  return __generator(this, function (_s) {
936
937
  switch (_s.label) {
937
938
  case 0:
938
- _j = (_h = this.checkoutService).updateCheckoutLineItems;
939
+ _j = (_h = this.checkoutService)
940
+ .updateCheckoutLineItems;
939
941
  _l = (_k = i1$1.Checkout).toInstance;
940
942
  _o = (_m = Object).assign;
941
943
  _p = [Object.assign({}, checkout.toPlain())];
@@ -953,7 +955,8 @@
953
955
  case 2:
954
956
  _r = [];
955
957
  _s.label = 3;
956
- case 3: return [2 /*return*/, _j.apply(_h, [_l.apply(_k, [_o.apply(_m, _p.concat([(_q.lineItems = _r, _q)]))])]).toPromise()];
958
+ case 3: return [2 /*return*/, _j.apply(_h, [_l.apply(_k, [_o.apply(_m, _p.concat([(_q.lineItems = _r, _q)]))])])
959
+ .toPromise()];
957
960
  }
958
961
  });
959
962
  }); }), operators.map(function (checkout) { return _this.generateCartObject(checkout.lineItems); }), operators.tap(function (cart) { return _this.cartSubject.next(cart); }));
@@ -969,9 +972,36 @@
969
972
  var _this = this;
970
973
  return this.checkoutService.getCheckout(checkoutData).pipe(operators.map(function (checkout) { return checkout.lineItems; }), operators.concatMap(function (lineItems) { return rxjs.of(_this.generateCartObject(lineItems)); }));
971
974
  };
975
+ CartService.prototype.getProductData = function (productId) {
976
+ return __awaiter(this, void 0, void 0, function () {
977
+ var product, variant, error_1;
978
+ return __generator(this, function (_h) {
979
+ switch (_h.label) {
980
+ case 0:
981
+ _h.trys.push([0, 2, , 6]);
982
+ return [4 /*yield*/, this.productRepository.get({ id: productId })];
983
+ case 1:
984
+ product = _h.sent();
985
+ return [3 /*break*/, 6];
986
+ case 2:
987
+ error_1 = _h.sent();
988
+ if (!(error_1 instanceof i1$1.NotFoundError)) return [3 /*break*/, 5];
989
+ return [4 /*yield*/, this.variantRepository.get({ id: productId })];
990
+ case 3:
991
+ variant = _h.sent();
992
+ return [4 /*yield*/, this.productRepository.get({ id: variant.productId })];
993
+ case 4:
994
+ product = _h.sent();
995
+ _h.label = 5;
996
+ case 5: throw error_1;
997
+ case 6: return [2 /*return*/, Object.assign(Object.assign({}, product.toPlain()), (variant && Object.assign({}, variant.toPlain())))];
998
+ }
999
+ });
1000
+ });
1001
+ };
972
1002
  return CartService;
973
1003
  }());
974
- CartService.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0__namespace, type: CartService, deps: [{ token: AuthService }, { token: CheckoutService }, { token: DEFAULT_SHOP }, { token: 'ProductRepository' }], target: i0__namespace.ɵɵFactoryTarget.Injectable });
1004
+ CartService.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0__namespace, type: CartService, deps: [{ token: AuthService }, { token: CheckoutService }, { token: DEFAULT_SHOP }, { token: 'ProductRepository' }, { token: 'VariantRepository' }], target: i0__namespace.ɵɵFactoryTarget.Injectable });
975
1005
  CartService.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0__namespace, type: CartService });
976
1006
  i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0__namespace, type: CartService, decorators: [{
977
1007
  type: i0.Injectable
@@ -982,6 +1012,9 @@
982
1012
  }] }, { type: undefined, decorators: [{
983
1013
  type: i0.Inject,
984
1014
  args: ['ProductRepository']
1015
+ }] }, { type: undefined, decorators: [{
1016
+ type: i0.Inject,
1017
+ args: ['VariantRepository']
985
1018
  }] }];
986
1019
  } });
987
1020