@infrab4a/connect-angular 2.0.0-beta.0 → 2.0.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.
@@ -792,15 +792,15 @@
792
792
  });
793
793
  return cart;
794
794
  };
795
- this.buildLineItem = function (_g) {
796
- var checkout = _g.checkout, item = _g.item, quantity = _g.quantity;
795
+ this.buildLineItem = function (_h) {
796
+ var checkout = _h.checkout, item = _h.item, quantity = _h.quantity;
797
797
  return __awaiter(_this, void 0, void 0, function () {
798
- var _a, _b, _c, _d, _e, _f, product, image, id, name, EAN, brand, slug, stock, price, weight, categories, sku, isGift, pricePaid;
799
- return __generator(this, function (_g) {
800
- switch (_g.label) {
798
+ var _a, _b, _c, _d, _e, _f, _g, product, image, id, name, EAN, brand, slug, stock, price, weight, categories, sku, isGift, pricePaid;
799
+ return __generator(this, function (_h) {
800
+ switch (_h.label) {
801
801
  case 0: return [4 /*yield*/, this.productRepository.get({ id: item.id })];
802
802
  case 1:
803
- product = _g.sent();
803
+ product = _h.sent();
804
804
  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;
805
805
  if (this.checkMaxStock(item, quantity || 0))
806
806
  throw new Error('Desculpe! Temos apenas ' + ((_c = item.stock) === null || _c === void 0 ? void 0 : _c.quantity) + ' em estoque.');
@@ -816,11 +816,11 @@
816
816
  checkout: checkout,
817
817
  lineItem: i2.LineItem.toInstance({
818
818
  id: id,
819
- name: name,
819
+ name: name !== null && name !== void 0 ? name : product.name,
820
820
  EAN: EAN !== null && EAN !== void 0 ? EAN : product.EAN,
821
821
  brand: product.brand,
822
- slug: slug,
823
- sku: sku,
822
+ slug: slug !== null && slug !== void 0 ? slug : product.slug,
823
+ sku: sku !== null && sku !== void 0 ? sku : product.sku,
824
824
  stock: stock,
825
825
  price: price,
826
826
  image: image,
@@ -829,15 +829,15 @@
829
829
  pricePaid: pricePaid,
830
830
  categories: (_f = product.categories) !== null && _f !== void 0 ? _f : [],
831
831
  isGift: isGift !== null && isGift !== void 0 ? isGift : null,
832
- costPrice: item === null || item === void 0 ? void 0 : item.costPrice,
832
+ costPrice: (_g = product.costPrice) !== null && _g !== void 0 ? _g : 0,
833
833
  }),
834
834
  }];
835
835
  }
836
836
  });
837
837
  });
838
838
  };
839
- this.getProductPrice = function (_g) {
840
- var product = _g.product, shop = _g.shop, isSubscriber = _g.isSubscriber;
839
+ this.getProductPrice = function (_h) {
840
+ var product = _h.product, shop = _h.shop, isSubscriber = _h.isSubscriber;
841
841
  var info = product.getInfoByShop(shop);
842
842
  if (product.isGift)
843
843
  return 0;
@@ -853,8 +853,13 @@
853
853
  CartService.prototype.addItem = function (item, quantity) {
854
854
  var _this = this;
855
855
  if (quantity === void 0) { quantity = 1; }
856
- return rxjs.from(this.checkoutService.getCheckout()).pipe(operators.concatMap(function (checkout) { return _this.buildLineItem({ checkout: checkout, item: item, quantity: quantity || 1 }); }), operators.mergeMap(function (_g) {
857
- var checkout = _g.checkout, lineItem = _g.lineItem;
856
+ return rxjs.from(this.checkoutService.getCheckout()).pipe(operators.concatMap(function (checkout) { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_h) {
857
+ switch (_h.label) {
858
+ case 0: return [4 /*yield*/, this.buildLineItem({ checkout: checkout, item: item, quantity: quantity || 1 })];
859
+ case 1: return [2 /*return*/, _h.sent()];
860
+ }
861
+ }); }); }), operators.mergeMap(function (_h) {
862
+ var checkout = _h.checkout, lineItem = _h.lineItem;
858
863
  return _this.updateLineItemInCart(lineItem, quantity || 1, checkout);
859
864
  }), operators.tap(function (cart) { return _this.cartSubject.next(cart); }));
860
865
  };
@@ -892,10 +897,10 @@
892
897
  var _this = this;
893
898
  return this.checkoutService.getCheckout().pipe(operators.concatMap(function (checkout) { return _this.checkoutService.updateCheckoutUser(i2.Checkout.toInstance(Object.assign(Object.assign({}, checkout.toPlain()), { user: user }))); }), operators.concatMap(function (checkout) {
894
899
  var _a;
895
- return _this.checkoutService.updateCheckoutLineItems(i2.Checkout.toInstance(Object.assign(Object.assign({}, checkout.toPlain()), { lineItems: ((_a = checkout.lineItems) === null || _a === void 0 ? void 0 : _a.map(function (item) { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_g) {
896
- switch (_g.label) {
900
+ return _this.checkoutService.updateCheckoutLineItems(i2.Checkout.toInstance(Object.assign(Object.assign({}, checkout.toPlain()), { lineItems: ((_a = checkout.lineItems) === null || _a === void 0 ? void 0 : _a.map(function (item) { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_h) {
901
+ switch (_h.label) {
897
902
  case 0: return [4 /*yield*/, this.buildLineItem({ checkout: checkout, item: item })];
898
- case 1: return [2 /*return*/, _g.sent()];
903
+ case 1: return [2 /*return*/, _h.sent()];
899
904
  }
900
905
  }); }); })) || [] })));
901
906
  }), operators.map(function (checkout) { return _this.generateCartObject(checkout.lineItems); }), operators.tap(function (cart) { return _this.cartSubject.next(cart); }));