@infrab4a/connect-angular 3.6.0-beta.13 → 3.6.0-beta.15
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.
- package/bundles/infrab4a-connect-angular.umd.js +132 -16
- package/bundles/infrab4a-connect-angular.umd.js.map +1 -1
- package/esm2015/services/cart.service.js +65 -7
- package/fesm2015/infrab4a-connect-angular.js +64 -6
- package/fesm2015/infrab4a-connect-angular.js.map +1 -1
- package/package.json +1 -1
- package/services/cart.service.d.ts +1 -0
|
@@ -816,10 +816,9 @@
|
|
|
816
816
|
}
|
|
817
817
|
else
|
|
818
818
|
checkoutLoaded.lineItems = items.concat(checkoutLoaded.lineItems ? checkoutLoaded.lineItems.concat([lineItem]) : [lineItem]);
|
|
819
|
-
return
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
// .pipe(map((updatedCheckout) => this.generateCartObject(updatedCheckout.lineItems)))
|
|
819
|
+
return _this.checkoutService
|
|
820
|
+
.updateCheckoutLineItems(checkoutLoaded)
|
|
821
|
+
.pipe(operators.map(function (updatedCheckout) { return _this.generateCartObject(updatedCheckout.lineItems); }));
|
|
823
822
|
})); };
|
|
824
823
|
this.generateCartObject = function (items) {
|
|
825
824
|
var cart = {};
|
|
@@ -899,12 +898,7 @@
|
|
|
899
898
|
}); }); }), operators.mergeMap(function (_h) {
|
|
900
899
|
var checkout = _h.checkout, lineItem = _h.lineItem;
|
|
901
900
|
return _this.updateLineItemInCart(lineItem, quantity || 1, checkout);
|
|
902
|
-
}), operators.
|
|
903
|
-
switch (_h.label) {
|
|
904
|
-
case 0: return [4 /*yield*/, this.checkGifts(updatedCheckout)];
|
|
905
|
-
case 1: return [2 /*return*/, _h.sent()];
|
|
906
|
-
}
|
|
907
|
-
}); }); }), operators.concatMap(function (checkout) { return _this.checkoutService.updateCheckoutLineItems(checkout); }), operators.map(function (checkout) { return _this.generateCartObject(checkout.lineItems); }), operators.tap(function (cart) { return _this.cartSubject.next(cart); }));
|
|
901
|
+
}), operators.tap(function (cart) { return _this.cartSubject.next(cart); }));
|
|
908
902
|
};
|
|
909
903
|
CartService.prototype.decreaseItem = function (item) {
|
|
910
904
|
var _this = this;
|
|
@@ -914,12 +908,7 @@
|
|
|
914
908
|
if (!i3.isNil(checkoutItem))
|
|
915
909
|
checkoutItem.quantity -= checkoutItem.quantity > 1 ? 1 : 0;
|
|
916
910
|
return checkout;
|
|
917
|
-
}), operators.concatMap(function (
|
|
918
|
-
switch (_h.label) {
|
|
919
|
-
case 0: return [4 /*yield*/, this.checkGifts(updatedCheckout)];
|
|
920
|
-
case 1: return [2 /*return*/, _h.sent()];
|
|
921
|
-
}
|
|
922
|
-
}); }); }), operators.concatMap(function (checkout) { return _this.checkoutService.updateCheckoutLineItems(checkout); }), operators.map(function (checkout) { return _this.generateCartObject(checkout.lineItems); }), operators.tap(function (cart) { return _this.cartSubject.next(cart); }));
|
|
911
|
+
}), operators.concatMap(function (checkout) { return _this.checkoutService.updateCheckoutLineItems(checkout); }), operators.map(function (checkout) { return _this.generateCartObject(checkout.lineItems); }), operators.tap(function (cart) { return _this.cartSubject.next(cart); }));
|
|
923
912
|
};
|
|
924
913
|
CartService.prototype.getCart = function (checkout) {
|
|
925
914
|
var _this = this;
|
|
@@ -1118,6 +1107,133 @@
|
|
|
1118
1107
|
});
|
|
1119
1108
|
});
|
|
1120
1109
|
};
|
|
1110
|
+
CartService.prototype.getGifts = function () {
|
|
1111
|
+
var _this = this;
|
|
1112
|
+
return this.checkoutService.getCheckout().pipe(operators.mergeMap(function (checkout) { return __awaiter(_this, void 0, void 0, function () {
|
|
1113
|
+
var campaigns, notGiftItems, cartTotal, elegibleCampaigns, _loop_2, campaigns_2, campaigns_2_1, campaign, campaingnProducts, elegibleCampaigns_2, elegibleCampaigns_2_1, campaign, elegibleProducts, _h, _j, product, productData, e_4_1, e_5_1, gifts;
|
|
1114
|
+
var e_6, _k, e_5, _l, e_4, _m;
|
|
1115
|
+
return __generator(this, function (_o) {
|
|
1116
|
+
switch (_o.label) {
|
|
1117
|
+
case 0: return [4 /*yield*/, this.buy2WinRepository
|
|
1118
|
+
.find({
|
|
1119
|
+
filters: {
|
|
1120
|
+
active: { operator: i3.Where.EQUALS, value: true },
|
|
1121
|
+
shop: { operator: i3.Where.EQUALS, value: this.defaultShop },
|
|
1122
|
+
},
|
|
1123
|
+
})
|
|
1124
|
+
.then(function (data) { return data.data; })];
|
|
1125
|
+
case 1:
|
|
1126
|
+
campaigns = _o.sent();
|
|
1127
|
+
notGiftItems = checkout.lineItems.filter(function (item) { return !item.isGift; });
|
|
1128
|
+
if (!campaigns.length)
|
|
1129
|
+
return [2 /*return*/, Object.assign(Object.assign({}, checkout), { lineItems: notGiftItems })];
|
|
1130
|
+
cartTotal = notGiftItems.reduce(function (a, b) { return a + b.pricePaid * b.quantity; }, 0);
|
|
1131
|
+
elegibleCampaigns = [];
|
|
1132
|
+
_loop_2 = function (campaign) {
|
|
1133
|
+
var today = new Date();
|
|
1134
|
+
if (!(campaign.startDate <= today) && !(campaign.endDate >= today))
|
|
1135
|
+
return "continue";
|
|
1136
|
+
if (campaign.activeCategory) {
|
|
1137
|
+
var categoriesCampaing_2 = campaign.categories.map(function (c) { return c.id; });
|
|
1138
|
+
var filterProductsCategories = checkout.lineItems.filter(function (l) {
|
|
1139
|
+
var _a;
|
|
1140
|
+
if (!l.categories || !((_a = l.categories) === null || _a === void 0 ? void 0 : _a.length))
|
|
1141
|
+
return true;
|
|
1142
|
+
return l.categories.some(function (c) { return categoriesCampaing_2.some(function (cat) { return cat == c; }); });
|
|
1143
|
+
});
|
|
1144
|
+
if (filterProductsCategories.length) {
|
|
1145
|
+
var cartTotalCategories = filterProductsCategories.reduce(function (a, b) { return a + b.pricePaid * b.quantity; }, 0);
|
|
1146
|
+
if (cartTotalCategories >= campaign.cartValueMin)
|
|
1147
|
+
elegibleCampaigns.push(campaign);
|
|
1148
|
+
}
|
|
1149
|
+
}
|
|
1150
|
+
else {
|
|
1151
|
+
if (campaign.cartValue && campaign.cartValue > 0) {
|
|
1152
|
+
if (campaign.cartValue <= cartTotal)
|
|
1153
|
+
elegibleCampaigns.push(campaign);
|
|
1154
|
+
}
|
|
1155
|
+
}
|
|
1156
|
+
};
|
|
1157
|
+
try {
|
|
1158
|
+
for (campaigns_2 = __values(campaigns), campaigns_2_1 = campaigns_2.next(); !campaigns_2_1.done; campaigns_2_1 = campaigns_2.next()) {
|
|
1159
|
+
campaign = campaigns_2_1.value;
|
|
1160
|
+
_loop_2(campaign);
|
|
1161
|
+
}
|
|
1162
|
+
}
|
|
1163
|
+
catch (e_6_1) { e_6 = { error: e_6_1 }; }
|
|
1164
|
+
finally {
|
|
1165
|
+
try {
|
|
1166
|
+
if (campaigns_2_1 && !campaigns_2_1.done && (_k = campaigns_2.return)) _k.call(campaigns_2);
|
|
1167
|
+
}
|
|
1168
|
+
finally { if (e_6) throw e_6.error; }
|
|
1169
|
+
}
|
|
1170
|
+
if (!elegibleCampaigns.length)
|
|
1171
|
+
return [2 /*return*/, Object.assign(Object.assign({}, checkout), { lineItems: notGiftItems })];
|
|
1172
|
+
campaingnProducts = [];
|
|
1173
|
+
_o.label = 2;
|
|
1174
|
+
case 2:
|
|
1175
|
+
_o.trys.push([2, 14, 15, 16]);
|
|
1176
|
+
elegibleCampaigns_2 = __values(elegibleCampaigns), elegibleCampaigns_2_1 = elegibleCampaigns_2.next();
|
|
1177
|
+
_o.label = 3;
|
|
1178
|
+
case 3:
|
|
1179
|
+
if (!!elegibleCampaigns_2_1.done) return [3 /*break*/, 13];
|
|
1180
|
+
campaign = elegibleCampaigns_2_1.value;
|
|
1181
|
+
elegibleProducts = [];
|
|
1182
|
+
_o.label = 4;
|
|
1183
|
+
case 4:
|
|
1184
|
+
_o.trys.push([4, 9, 10, 11]);
|
|
1185
|
+
_h = (e_4 = void 0, __values(campaign.products)), _j = _h.next();
|
|
1186
|
+
_o.label = 5;
|
|
1187
|
+
case 5:
|
|
1188
|
+
if (!!_j.done) return [3 /*break*/, 8];
|
|
1189
|
+
product = _j.value;
|
|
1190
|
+
return [4 /*yield*/, this.productRepository.get({ sku: product })];
|
|
1191
|
+
case 6:
|
|
1192
|
+
productData = _o.sent();
|
|
1193
|
+
if (!productData)
|
|
1194
|
+
return [3 /*break*/, 7];
|
|
1195
|
+
elegibleProducts.push(productData);
|
|
1196
|
+
_o.label = 7;
|
|
1197
|
+
case 7:
|
|
1198
|
+
_j = _h.next();
|
|
1199
|
+
return [3 /*break*/, 5];
|
|
1200
|
+
case 8: return [3 /*break*/, 11];
|
|
1201
|
+
case 9:
|
|
1202
|
+
e_4_1 = _o.sent();
|
|
1203
|
+
e_4 = { error: e_4_1 };
|
|
1204
|
+
return [3 /*break*/, 11];
|
|
1205
|
+
case 10:
|
|
1206
|
+
try {
|
|
1207
|
+
if (_j && !_j.done && (_m = _h.return)) _m.call(_h);
|
|
1208
|
+
}
|
|
1209
|
+
finally { if (e_4) throw e_4.error; }
|
|
1210
|
+
return [7 /*endfinally*/];
|
|
1211
|
+
case 11:
|
|
1212
|
+
campaingnProducts.push(elegibleProducts);
|
|
1213
|
+
_o.label = 12;
|
|
1214
|
+
case 12:
|
|
1215
|
+
elegibleCampaigns_2_1 = elegibleCampaigns_2.next();
|
|
1216
|
+
return [3 /*break*/, 3];
|
|
1217
|
+
case 13: return [3 /*break*/, 16];
|
|
1218
|
+
case 14:
|
|
1219
|
+
e_5_1 = _o.sent();
|
|
1220
|
+
e_5 = { error: e_5_1 };
|
|
1221
|
+
return [3 /*break*/, 16];
|
|
1222
|
+
case 15:
|
|
1223
|
+
try {
|
|
1224
|
+
if (elegibleCampaigns_2_1 && !elegibleCampaigns_2_1.done && (_l = elegibleCampaigns_2.return)) _l.call(elegibleCampaigns_2);
|
|
1225
|
+
}
|
|
1226
|
+
finally { if (e_5) throw e_5.error; }
|
|
1227
|
+
return [7 /*endfinally*/];
|
|
1228
|
+
case 16:
|
|
1229
|
+
if (!campaingnProducts.length)
|
|
1230
|
+
return [2 /*return*/, Object.assign(Object.assign({}, checkout), { lineItems: notGiftItems })];
|
|
1231
|
+
gifts = this.giftToLineItems([].concat.apply([], __spreadArray([], __read(campaingnProducts))));
|
|
1232
|
+
return [2 /*return*/, Object.assign(Object.assign({}, checkout), { lineItems: notGiftItems.concat(gifts) })];
|
|
1233
|
+
}
|
|
1234
|
+
});
|
|
1235
|
+
}); }), operators.concatMap(function (checkout) { return _this.checkoutService.updateCheckoutLineItems(checkout); }), operators.map(function (checkout) { return _this.generateCartObject(checkout.lineItems); }), operators.tap(function (cart) { return _this.cartSubject.next(cart); }));
|
|
1236
|
+
};
|
|
1121
1237
|
CartService.prototype.giftToLineItems = function (items) {
|
|
1122
1238
|
return items.map(function (item) {
|
|
1123
1239
|
var _a;
|