@infrab4a/connect-angular 3.8.1 → 3.8.3-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.
@@ -819,11 +819,13 @@
819
819
  .updateCheckoutLineItems(checkoutLoaded)
820
820
  .pipe(operators.map(function (updatedCheckout) { return _this.generateCartObject(updatedCheckout.lineItems); }));
821
821
  })); };
822
- this.generateCartObject = function (items) { return items.reduce(function (cart, item) {
823
- var _h;
824
- var _a;
825
- return (Object.assign(Object.assign({}, cart), (_h = {}, _h[item.id] = i3.LineItem.toInstance(Object.assign(Object.assign({}, (cart[item.id] || item)), { quantity: (((_a = cart[item.id]) === null || _a === void 0 ? void 0 : _a.quantity) || 0) + (item.quantity ? item.quantity : 1) })), _h)));
826
- }, {}); };
822
+ this.generateCartObject = function (items) { return items
823
+ ? items.reduce(function (cart, item) {
824
+ var _h;
825
+ var _a;
826
+ return (Object.assign(Object.assign({}, cart), (_h = {}, _h[item.id] = i3.LineItem.toInstance(Object.assign(Object.assign({}, (cart[item.id] || item)), { quantity: (((_a = cart[item.id]) === null || _a === void 0 ? void 0 : _a.quantity) || 0) + (item.quantity ? item.quantity : 1) })), _h)));
827
+ }, {})
828
+ : []; };
827
829
  this.buildLineItem = function (_h) {
828
830
  var checkout = _h.checkout, item = _h.item, quantity = _h.quantity;
829
831
  return __awaiter(_this, void 0, void 0, function () {
@@ -1000,12 +1002,12 @@
1000
1002
  CartService.prototype.getGifts = function () {
1001
1003
  var _this = this;
1002
1004
  return this.checkoutService.getCheckout().pipe(operators.mergeMap(function (checkout) { return __awaiter(_this, void 0, void 0, function () {
1003
- var notGiftItems, cartTotal, campaigns, elegibleCampaigns, _loop_1, campaigns_1, campaigns_1_1, campaign, campaingnProducts, elegibleCampaigns_1, elegibleCampaigns_1_1, campaign, elegibleProducts, _h, _j, product, productData, e_1_1, e_2_1, gifts;
1005
+ var notGiftItems, cartTotal, campaigns, elegibleCampaigns, _loop_1, campaigns_1, campaigns_1_1, campaign, campaingnProducts, elegibleCampaigns_1, elegibleCampaigns_1_1, campaign, elegibleProducts, _h, _j, product, productData, gift, e_1_1, e_2_1, gifts;
1004
1006
  var e_3, _k, e_2, _l, e_1, _m;
1005
1007
  return __generator(this, function (_o) {
1006
1008
  switch (_o.label) {
1007
1009
  case 0:
1008
- notGiftItems = checkout.lineItems.filter(function (item) { return !item.isGift; });
1010
+ notGiftItems = checkout.lineItems ? checkout.lineItems.filter(function (item) { return !item.isGift; }) : [];
1009
1011
  if (!notGiftItems.length)
1010
1012
  return [2 /*return*/, Object.assign(Object.assign({}, checkout), { lineItems: [] })];
1011
1013
  cartTotal = notGiftItems.reduce(function (a, b) { return a + b.pricePaid * b.quantity; }, 0);
@@ -1085,7 +1087,10 @@
1085
1087
  productData = (_o.sent()).data;
1086
1088
  if (!productData.length)
1087
1089
  return [3 /*break*/, 7];
1088
- elegibleProducts.push(productData.shift());
1090
+ gift = productData.shift();
1091
+ if (gift.stock.quantity < 1)
1092
+ return [3 /*break*/, 7];
1093
+ elegibleProducts.push(gift);
1089
1094
  _o.label = 7;
1090
1095
  case 7:
1091
1096
  _j = _h.next();