@infrab4a/connect-angular 3.6.0-beta.13 → 3.6.0-beta.14
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 +155 -12
- package/bundles/infrab4a-connect-angular.umd.js.map +1 -1
- package/esm2015/services/cart.service.js +88 -3
- package/fesm2015/infrab4a-connect-angular.js +87 -2
- package/fesm2015/infrab4a-connect-angular.js.map +1 -1
- package/package.json +1 -1
- package/services/cart.service.d.ts +2 -0
|
@@ -807,6 +807,20 @@
|
|
|
807
807
|
this.buy2WinRepository = buy2WinRepository;
|
|
808
808
|
this.cartSubject = new rxjs.Subject();
|
|
809
809
|
this.updateLineItemInCart = function (lineItem, quantity, checkout) { return (i3.isNil(checkout) ? _this.checkoutService.getCheckout() : rxjs.of(checkout)).pipe(operators.concatMap(function (checkoutLoaded) {
|
|
810
|
+
var _a;
|
|
811
|
+
var items = [];
|
|
812
|
+
var index = (_a = checkoutLoaded.lineItems) === null || _a === void 0 ? void 0 : _a.map(function (checkoutItem) { return checkoutItem.sku; }).indexOf(lineItem.sku);
|
|
813
|
+
if (index > -1) {
|
|
814
|
+
checkoutLoaded.lineItems[index].quantity += quantity;
|
|
815
|
+
checkoutLoaded.lineItems[index].pricePaid = lineItem.pricePaid;
|
|
816
|
+
}
|
|
817
|
+
else
|
|
818
|
+
checkoutLoaded.lineItems = items.concat(checkoutLoaded.lineItems ? checkoutLoaded.lineItems.concat([lineItem]) : [lineItem]);
|
|
819
|
+
return _this.checkoutService
|
|
820
|
+
.updateCheckoutLineItems(checkoutLoaded)
|
|
821
|
+
.pipe(operators.map(function (updatedCheckout) { return _this.generateCartObject(updatedCheckout.lineItems); }));
|
|
822
|
+
})); };
|
|
823
|
+
this.updateLineItemInCartNew = function (lineItem, quantity, checkout) { return (i3.isNil(checkout) ? _this.checkoutService.getCheckout() : rxjs.of(checkout)).pipe(operators.concatMap(function (checkoutLoaded) {
|
|
810
824
|
var _a;
|
|
811
825
|
var items = [];
|
|
812
826
|
var index = (_a = checkoutLoaded.lineItems) === null || _a === void 0 ? void 0 : _a.map(function (checkoutItem) { return checkoutItem.sku; }).indexOf(lineItem.sku);
|
|
@@ -899,12 +913,11 @@
|
|
|
899
913
|
}); }); }), operators.mergeMap(function (_h) {
|
|
900
914
|
var checkout = _h.checkout, lineItem = _h.lineItem;
|
|
901
915
|
return _this.updateLineItemInCart(lineItem, quantity || 1, checkout);
|
|
902
|
-
}),
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
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); }));
|
|
916
|
+
}),
|
|
917
|
+
// concatMap(async (updatedCheckout) => await this.checkGifts(updatedCheckout)),
|
|
918
|
+
// concatMap((checkout) => this.checkoutService.updateCheckoutLineItems(checkout)),
|
|
919
|
+
// map((checkout) => this.generateCartObject(checkout.lineItems)),
|
|
920
|
+
operators.tap(function (cart) { return _this.cartSubject.next(cart); }));
|
|
908
921
|
};
|
|
909
922
|
CartService.prototype.decreaseItem = function (item) {
|
|
910
923
|
var _this = this;
|
|
@@ -914,12 +927,9 @@
|
|
|
914
927
|
if (!i3.isNil(checkoutItem))
|
|
915
928
|
checkoutItem.quantity -= checkoutItem.quantity > 1 ? 1 : 0;
|
|
916
929
|
return checkout;
|
|
917
|
-
}),
|
|
918
|
-
|
|
919
|
-
|
|
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); }));
|
|
930
|
+
}),
|
|
931
|
+
// concatMap(async (updatedCheckout) => await this.checkGifts(updatedCheckout)),
|
|
932
|
+
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
933
|
};
|
|
924
934
|
CartService.prototype.getCart = function (checkout) {
|
|
925
935
|
var _this = this;
|
|
@@ -1118,6 +1128,139 @@
|
|
|
1118
1128
|
});
|
|
1119
1129
|
});
|
|
1120
1130
|
};
|
|
1131
|
+
CartService.prototype.getGifts = function () {
|
|
1132
|
+
var _this = this;
|
|
1133
|
+
return this.checkoutService.getCheckout().pipe(operators.map(function (checkout) { return __awaiter(_this, void 0, void 0, function () {
|
|
1134
|
+
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, productArray, gifts;
|
|
1135
|
+
var e_6, _k, e_5, _l, e_4, _m;
|
|
1136
|
+
return __generator(this, function (_o) {
|
|
1137
|
+
switch (_o.label) {
|
|
1138
|
+
case 0: return [4 /*yield*/, this.buy2WinRepository
|
|
1139
|
+
.find({
|
|
1140
|
+
filters: {
|
|
1141
|
+
active: { operator: i3.Where.EQUALS, value: true },
|
|
1142
|
+
shop: { operator: i3.Where.EQUALS, value: this.defaultShop },
|
|
1143
|
+
},
|
|
1144
|
+
})
|
|
1145
|
+
.then(function (data) { return data.data; })];
|
|
1146
|
+
case 1:
|
|
1147
|
+
campaigns = _o.sent();
|
|
1148
|
+
notGiftItems = checkout.lineItems.filter(function (item) { return !item.isGift; });
|
|
1149
|
+
if (!campaigns.length)
|
|
1150
|
+
return [2 /*return*/, notGiftItems];
|
|
1151
|
+
cartTotal = notGiftItems.reduce(function (a, b) { return a + b.pricePaid * b.quantity; }, 0);
|
|
1152
|
+
elegibleCampaigns = [];
|
|
1153
|
+
_loop_2 = function (campaign) {
|
|
1154
|
+
// problemas: datas, valorcart e valor cartMin, filtros no código
|
|
1155
|
+
var today = new Date();
|
|
1156
|
+
if (!(campaign.startDate <= today) && !(campaign.endDate >= today))
|
|
1157
|
+
return "continue";
|
|
1158
|
+
// Passo 2: Verificar se a campanha é por categorias
|
|
1159
|
+
if (campaign.activeCategory) {
|
|
1160
|
+
var categoriesCampaing_2 = campaign.categories.map(function (c) { return c.id; });
|
|
1161
|
+
var filterProductsCategories = checkout.lineItems.filter(function (l) {
|
|
1162
|
+
var _a;
|
|
1163
|
+
if (!l.categories || !((_a = l.categories) === null || _a === void 0 ? void 0 : _a.length))
|
|
1164
|
+
return true;
|
|
1165
|
+
return l.categories.some(function (c) { return categoriesCampaing_2.some(function (cat) { return cat == c; }); });
|
|
1166
|
+
});
|
|
1167
|
+
if (filterProductsCategories.length) {
|
|
1168
|
+
var cartTotalCategories = filterProductsCategories.reduce(function (a, b) { return a + b.pricePaid * b.quantity; }, 0);
|
|
1169
|
+
if (cartTotalCategories >= campaign.cartValueMin)
|
|
1170
|
+
elegibleCampaigns.push(campaign);
|
|
1171
|
+
}
|
|
1172
|
+
}
|
|
1173
|
+
else {
|
|
1174
|
+
if (campaign.cartValue && campaign.cartValue > 0) {
|
|
1175
|
+
if (campaign.cartValue <= cartTotal)
|
|
1176
|
+
elegibleCampaigns.push(campaign);
|
|
1177
|
+
}
|
|
1178
|
+
}
|
|
1179
|
+
};
|
|
1180
|
+
try {
|
|
1181
|
+
for (campaigns_2 = __values(campaigns), campaigns_2_1 = campaigns_2.next(); !campaigns_2_1.done; campaigns_2_1 = campaigns_2.next()) {
|
|
1182
|
+
campaign = campaigns_2_1.value;
|
|
1183
|
+
_loop_2(campaign);
|
|
1184
|
+
}
|
|
1185
|
+
}
|
|
1186
|
+
catch (e_6_1) { e_6 = { error: e_6_1 }; }
|
|
1187
|
+
finally {
|
|
1188
|
+
try {
|
|
1189
|
+
if (campaigns_2_1 && !campaigns_2_1.done && (_k = campaigns_2.return)) _k.call(campaigns_2);
|
|
1190
|
+
}
|
|
1191
|
+
finally { if (e_6) throw e_6.error; }
|
|
1192
|
+
}
|
|
1193
|
+
if (!elegibleCampaigns.length)
|
|
1194
|
+
return [2 /*return*/, notGiftItems];
|
|
1195
|
+
campaingnProducts = [];
|
|
1196
|
+
_o.label = 2;
|
|
1197
|
+
case 2:
|
|
1198
|
+
_o.trys.push([2, 14, 15, 16]);
|
|
1199
|
+
elegibleCampaigns_2 = __values(elegibleCampaigns), elegibleCampaigns_2_1 = elegibleCampaigns_2.next();
|
|
1200
|
+
_o.label = 3;
|
|
1201
|
+
case 3:
|
|
1202
|
+
if (!!elegibleCampaigns_2_1.done) return [3 /*break*/, 13];
|
|
1203
|
+
campaign = elegibleCampaigns_2_1.value;
|
|
1204
|
+
elegibleProducts = [];
|
|
1205
|
+
_o.label = 4;
|
|
1206
|
+
case 4:
|
|
1207
|
+
_o.trys.push([4, 9, 10, 11]);
|
|
1208
|
+
_h = (e_4 = void 0, __values(campaign.products)), _j = _h.next();
|
|
1209
|
+
_o.label = 5;
|
|
1210
|
+
case 5:
|
|
1211
|
+
if (!!_j.done) return [3 /*break*/, 8];
|
|
1212
|
+
product = _j.value;
|
|
1213
|
+
return [4 /*yield*/, this.productRepository.get({ sku: product })];
|
|
1214
|
+
case 6:
|
|
1215
|
+
productData = _o.sent();
|
|
1216
|
+
if (!productData)
|
|
1217
|
+
return [3 /*break*/, 7];
|
|
1218
|
+
elegibleProducts.push(productData);
|
|
1219
|
+
_o.label = 7;
|
|
1220
|
+
case 7:
|
|
1221
|
+
_j = _h.next();
|
|
1222
|
+
return [3 /*break*/, 5];
|
|
1223
|
+
case 8: return [3 /*break*/, 11];
|
|
1224
|
+
case 9:
|
|
1225
|
+
e_4_1 = _o.sent();
|
|
1226
|
+
e_4 = { error: e_4_1 };
|
|
1227
|
+
return [3 /*break*/, 11];
|
|
1228
|
+
case 10:
|
|
1229
|
+
try {
|
|
1230
|
+
if (_j && !_j.done && (_m = _h.return)) _m.call(_h);
|
|
1231
|
+
}
|
|
1232
|
+
finally { if (e_4) throw e_4.error; }
|
|
1233
|
+
return [7 /*endfinally*/];
|
|
1234
|
+
case 11:
|
|
1235
|
+
campaingnProducts.push(elegibleProducts);
|
|
1236
|
+
_o.label = 12;
|
|
1237
|
+
case 12:
|
|
1238
|
+
elegibleCampaigns_2_1 = elegibleCampaigns_2.next();
|
|
1239
|
+
return [3 /*break*/, 3];
|
|
1240
|
+
case 13: return [3 /*break*/, 16];
|
|
1241
|
+
case 14:
|
|
1242
|
+
e_5_1 = _o.sent();
|
|
1243
|
+
e_5 = { error: e_5_1 };
|
|
1244
|
+
return [3 /*break*/, 16];
|
|
1245
|
+
case 15:
|
|
1246
|
+
try {
|
|
1247
|
+
if (elegibleCampaigns_2_1 && !elegibleCampaigns_2_1.done && (_l = elegibleCampaigns_2.return)) _l.call(elegibleCampaigns_2);
|
|
1248
|
+
}
|
|
1249
|
+
finally { if (e_5) throw e_5.error; }
|
|
1250
|
+
return [7 /*endfinally*/];
|
|
1251
|
+
case 16:
|
|
1252
|
+
if (!campaingnProducts.length)
|
|
1253
|
+
return [2 /*return*/, notGiftItems];
|
|
1254
|
+
productArray = campaingnProducts.reduce(function (acc, curr) { return acc.reduce(function (aAcc, aCurr) { return aAcc + aCurr.price.price; }, 0) >
|
|
1255
|
+
curr.reduce(function (cAcc, cCurr) { return cAcc + cCurr.price.price; }, 0)
|
|
1256
|
+
? acc
|
|
1257
|
+
: curr; });
|
|
1258
|
+
gifts = this.giftToLineItems(productArray);
|
|
1259
|
+
return [2 /*return*/, notGiftItems.concat(gifts)];
|
|
1260
|
+
}
|
|
1261
|
+
});
|
|
1262
|
+
}); }));
|
|
1263
|
+
};
|
|
1121
1264
|
CartService.prototype.giftToLineItems = function (items) {
|
|
1122
1265
|
return items.map(function (item) {
|
|
1123
1266
|
var _a;
|