@infrab4a/connect-angular 3.2.1 → 3.2.2-beta.5
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 +176 -9
- package/bundles/infrab4a-connect-angular.umd.js.map +1 -1
- package/esm2015/services/cart.service.js +113 -12
- package/fesm2015/infrab4a-connect-angular.js +110 -9
- package/fesm2015/infrab4a-connect-angular.js.map +1 -1
- package/package.json +1 -1
- package/services/cart.service.d.ts +7 -2
|
@@ -820,12 +820,13 @@
|
|
|
820
820
|
} });
|
|
821
821
|
|
|
822
822
|
var CartService = /** @class */ (function () {
|
|
823
|
-
function CartService(authService, checkoutService, defaultShop, productRepository) {
|
|
823
|
+
function CartService(authService, checkoutService, defaultShop, productRepository, buy2WinRepository) {
|
|
824
824
|
var _this = this;
|
|
825
825
|
this.authService = authService;
|
|
826
826
|
this.checkoutService = checkoutService;
|
|
827
827
|
this.defaultShop = defaultShop;
|
|
828
828
|
this.productRepository = productRepository;
|
|
829
|
+
this.buy2WinRepository = buy2WinRepository;
|
|
829
830
|
this.cartSubject = new rxjs.Subject();
|
|
830
831
|
this.updateLineItemInCart = function (lineItem, quantity, checkout) { return (i2.isNil(checkout) ? _this.checkoutService.getCheckout() : rxjs.of(checkout)).pipe(operators.concatMap(function (checkoutLoaded) {
|
|
831
832
|
var _a;
|
|
@@ -837,10 +838,15 @@
|
|
|
837
838
|
}
|
|
838
839
|
else
|
|
839
840
|
checkoutLoaded.lineItems = items.concat(checkoutLoaded.lineItems ? checkoutLoaded.lineItems.concat([lineItem]) : [lineItem]);
|
|
840
|
-
return
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
841
|
+
return rxjs.of(checkoutLoaded);
|
|
842
|
+
}), operators.concatMap(function (newCheckout) { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_h) {
|
|
843
|
+
switch (_h.label) {
|
|
844
|
+
case 0: return [4 /*yield*/, this.checkBuy2Win(newCheckout)];
|
|
845
|
+
case 1: return [2 /*return*/, _h.sent()];
|
|
846
|
+
}
|
|
847
|
+
}); }); }), operators.concatMap(function (newCheckout) { return _this.checkoutService
|
|
848
|
+
.updateCheckoutLineItems(newCheckout)
|
|
849
|
+
.pipe(operators.map(function (updatedCheckout) { return _this.generateCartObject(updatedCheckout.lineItems); })); })); };
|
|
844
850
|
this.generateCartObject = function (items) {
|
|
845
851
|
var cart = {};
|
|
846
852
|
items === null || items === void 0 ? void 0 : items.forEach(function (item) {
|
|
@@ -916,7 +922,7 @@
|
|
|
916
922
|
case 0: return [4 /*yield*/, this.buildLineItem({ checkout: checkout, item: item, quantity: quantity || 1 })];
|
|
917
923
|
case 1: return [2 /*return*/, _h.sent()];
|
|
918
924
|
}
|
|
919
|
-
}); }); }), operators.
|
|
925
|
+
}); }); }), operators.concatMap(function (_h) {
|
|
920
926
|
var checkout = _h.checkout, lineItem = _h.lineItem;
|
|
921
927
|
return _this.updateLineItemInCart(lineItem, quantity || 1, checkout);
|
|
922
928
|
}), operators.tap(function (cart) { return _this.cartSubject.next(cart); }));
|
|
@@ -959,7 +965,8 @@
|
|
|
959
965
|
return __generator(this, function (_s) {
|
|
960
966
|
switch (_s.label) {
|
|
961
967
|
case 0:
|
|
962
|
-
_j = (_h = this.checkoutService)
|
|
968
|
+
_j = (_h = this.checkoutService)
|
|
969
|
+
.updateCheckoutLineItems;
|
|
963
970
|
_l = (_k = i2.Checkout).toInstance;
|
|
964
971
|
_o = (_m = Object).assign;
|
|
965
972
|
_p = [Object.assign({}, checkout.toPlain())];
|
|
@@ -977,7 +984,8 @@
|
|
|
977
984
|
case 2:
|
|
978
985
|
_r = [];
|
|
979
986
|
_s.label = 3;
|
|
980
|
-
case 3: return [2 /*return*/, _j.apply(_h, [_l.apply(_k, [_o.apply(_m, _p.concat([(_q.lineItems = _r, _q)]))])])
|
|
987
|
+
case 3: return [2 /*return*/, _j.apply(_h, [_l.apply(_k, [_o.apply(_m, _p.concat([(_q.lineItems = _r, _q)]))])])
|
|
988
|
+
.toPromise()];
|
|
981
989
|
}
|
|
982
990
|
});
|
|
983
991
|
}); }), operators.map(function (checkout) { return _this.generateCartObject(checkout.lineItems); }), operators.tap(function (cart) { return _this.cartSubject.next(cart); }));
|
|
@@ -993,9 +1001,165 @@
|
|
|
993
1001
|
var _this = this;
|
|
994
1002
|
return this.checkoutService.getCheckout(checkoutData).pipe(operators.map(function (checkout) { return checkout.lineItems; }), operators.concatMap(function (lineItems) { return rxjs.of(_this.generateCartObject(lineItems)); }));
|
|
995
1003
|
};
|
|
1004
|
+
CartService.prototype.getBu2Win = function (checkout) {
|
|
1005
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1006
|
+
var data, campaigns, elegibleCampaigns, products, elegibleCampaigns_1, elegibleCampaigns_1_1, campaign, elegibleProducts, _h, _j, product, productData, e_1_1, e_2_1, productArray;
|
|
1007
|
+
var e_2, _k, e_1, _l;
|
|
1008
|
+
return __generator(this, function (_m) {
|
|
1009
|
+
switch (_m.label) {
|
|
1010
|
+
case 0:
|
|
1011
|
+
data = {
|
|
1012
|
+
cartTotal: checkout.totalPrice,
|
|
1013
|
+
categories: checkout.lineItems.map(function (item) { return item.categories; }).reduce(function (acc, it) { return __spreadArray(__spreadArray([], __read(acc)), __read(it)); }, []),
|
|
1014
|
+
shop: this.defaultShop,
|
|
1015
|
+
};
|
|
1016
|
+
return [4 /*yield*/, this.buy2WinRepository
|
|
1017
|
+
.find({
|
|
1018
|
+
filters: { active: true, shop: this.defaultShop },
|
|
1019
|
+
})
|
|
1020
|
+
.then(function (data) { return data.data; })];
|
|
1021
|
+
case 1:
|
|
1022
|
+
campaigns = _m.sent();
|
|
1023
|
+
elegibleCampaigns = [];
|
|
1024
|
+
campaigns.forEach(function (campaign) {
|
|
1025
|
+
if (campaign.cartValue > 0 && campaign.categories.length > 0) {
|
|
1026
|
+
if (campaign.cartValue <= data.cartTotal &&
|
|
1027
|
+
campaign.categories.filter(function (category) { var _a; return (_a = data.categories) === null || _a === void 0 ? void 0 : _a.includes(category.id); }).length > 0)
|
|
1028
|
+
elegibleCampaigns.push(campaign);
|
|
1029
|
+
}
|
|
1030
|
+
else if (campaign.cartValue > 0) {
|
|
1031
|
+
if (campaign.cartValue <= data.cartTotal)
|
|
1032
|
+
elegibleCampaigns.push(campaign);
|
|
1033
|
+
}
|
|
1034
|
+
else if (campaign.categories.length > 0) {
|
|
1035
|
+
if (campaign.categories.filter(function (category) { var _a; return (_a = data.categories) === null || _a === void 0 ? void 0 : _a.includes(category.id); }).length > 0)
|
|
1036
|
+
elegibleCampaigns.push(campaign);
|
|
1037
|
+
}
|
|
1038
|
+
});
|
|
1039
|
+
if (elegibleCampaigns.length < 1)
|
|
1040
|
+
return [2 /*return*/];
|
|
1041
|
+
products = [];
|
|
1042
|
+
_m.label = 2;
|
|
1043
|
+
case 2:
|
|
1044
|
+
_m.trys.push([2, 14, 15, 16]);
|
|
1045
|
+
elegibleCampaigns_1 = __values(elegibleCampaigns), elegibleCampaigns_1_1 = elegibleCampaigns_1.next();
|
|
1046
|
+
_m.label = 3;
|
|
1047
|
+
case 3:
|
|
1048
|
+
if (!!elegibleCampaigns_1_1.done) return [3 /*break*/, 13];
|
|
1049
|
+
campaign = elegibleCampaigns_1_1.value;
|
|
1050
|
+
elegibleProducts = [];
|
|
1051
|
+
_m.label = 4;
|
|
1052
|
+
case 4:
|
|
1053
|
+
_m.trys.push([4, 9, 10, 11]);
|
|
1054
|
+
_h = (e_1 = void 0, __values(campaign.products)), _j = _h.next();
|
|
1055
|
+
_m.label = 5;
|
|
1056
|
+
case 5:
|
|
1057
|
+
if (!!_j.done) return [3 /*break*/, 8];
|
|
1058
|
+
product = _j.value;
|
|
1059
|
+
return [4 /*yield*/, this.productRepository.get({ sku: product })];
|
|
1060
|
+
case 6:
|
|
1061
|
+
productData = _m.sent();
|
|
1062
|
+
if (!productData)
|
|
1063
|
+
return [3 /*break*/, 7];
|
|
1064
|
+
elegibleProducts.push(productData);
|
|
1065
|
+
_m.label = 7;
|
|
1066
|
+
case 7:
|
|
1067
|
+
_j = _h.next();
|
|
1068
|
+
return [3 /*break*/, 5];
|
|
1069
|
+
case 8: return [3 /*break*/, 11];
|
|
1070
|
+
case 9:
|
|
1071
|
+
e_1_1 = _m.sent();
|
|
1072
|
+
e_1 = { error: e_1_1 };
|
|
1073
|
+
return [3 /*break*/, 11];
|
|
1074
|
+
case 10:
|
|
1075
|
+
try {
|
|
1076
|
+
if (_j && !_j.done && (_l = _h.return)) _l.call(_h);
|
|
1077
|
+
}
|
|
1078
|
+
finally { if (e_1) throw e_1.error; }
|
|
1079
|
+
return [7 /*endfinally*/];
|
|
1080
|
+
case 11:
|
|
1081
|
+
products.push(elegibleProducts);
|
|
1082
|
+
elegibleProducts = [];
|
|
1083
|
+
_m.label = 12;
|
|
1084
|
+
case 12:
|
|
1085
|
+
elegibleCampaigns_1_1 = elegibleCampaigns_1.next();
|
|
1086
|
+
return [3 /*break*/, 3];
|
|
1087
|
+
case 13: return [3 /*break*/, 16];
|
|
1088
|
+
case 14:
|
|
1089
|
+
e_2_1 = _m.sent();
|
|
1090
|
+
e_2 = { error: e_2_1 };
|
|
1091
|
+
return [3 /*break*/, 16];
|
|
1092
|
+
case 15:
|
|
1093
|
+
try {
|
|
1094
|
+
if (elegibleCampaigns_1_1 && !elegibleCampaigns_1_1.done && (_k = elegibleCampaigns_1.return)) _k.call(elegibleCampaigns_1);
|
|
1095
|
+
}
|
|
1096
|
+
finally { if (e_2) throw e_2.error; }
|
|
1097
|
+
return [7 /*endfinally*/];
|
|
1098
|
+
case 16:
|
|
1099
|
+
if (products.length < 1)
|
|
1100
|
+
return [2 /*return*/];
|
|
1101
|
+
productArray = products.reduce(function (acc, curr) { return acc.reduce(function (aAcc, aCurr) { return aAcc + aCurr.price.price; }, 0) >
|
|
1102
|
+
curr.reduce(function (cAcc, cCurr) { return cAcc + cCurr.price.price; }, 0)
|
|
1103
|
+
? acc
|
|
1104
|
+
: curr; });
|
|
1105
|
+
productArray.map(function (p) {
|
|
1106
|
+
var id = '' + p.id;
|
|
1107
|
+
delete p.id;
|
|
1108
|
+
return Object.assign({ id: id }, p);
|
|
1109
|
+
});
|
|
1110
|
+
return [2 /*return*/, productArray];
|
|
1111
|
+
}
|
|
1112
|
+
});
|
|
1113
|
+
});
|
|
1114
|
+
};
|
|
1115
|
+
CartService.prototype.checkBuy2Win = function (checkout) {
|
|
1116
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1117
|
+
var notGiftItems, res, giftItems;
|
|
1118
|
+
return __generator(this, function (_h) {
|
|
1119
|
+
switch (_h.label) {
|
|
1120
|
+
case 0:
|
|
1121
|
+
notGiftItems = checkout.lineItems.filter(function (item) { return !item.isGift; });
|
|
1122
|
+
if (!notGiftItems.length) return [3 /*break*/, 2];
|
|
1123
|
+
return [4 /*yield*/, this.getBu2Win(checkout)];
|
|
1124
|
+
case 1:
|
|
1125
|
+
res = _h.sent();
|
|
1126
|
+
giftItems = res.length ? this.productsToLineItems(res) : [];
|
|
1127
|
+
checkout.lineItems = notGiftItems.concat(giftItems);
|
|
1128
|
+
return [3 /*break*/, 3];
|
|
1129
|
+
case 2:
|
|
1130
|
+
this.clearCart();
|
|
1131
|
+
_h.label = 3;
|
|
1132
|
+
case 3: return [2 /*return*/, checkout];
|
|
1133
|
+
}
|
|
1134
|
+
});
|
|
1135
|
+
});
|
|
1136
|
+
};
|
|
1137
|
+
CartService.prototype.productsToLineItems = function (items) {
|
|
1138
|
+
return items.map(function (item) {
|
|
1139
|
+
var _a;
|
|
1140
|
+
var brand = item.brand, categories = item.categories, id = item.id, name = item.name, price = item.price, sku = item.sku, slug = item.slug, stock = item.stock, weight = item.weight, EAN = item.EAN;
|
|
1141
|
+
var image = ((_a = item === null || item === void 0 ? void 0 : item.miniatures) === null || _a === void 0 ? void 0 : _a.length) ? item.miniatures[0] : item.images[0];
|
|
1142
|
+
return i2.LineItem.toInstance({
|
|
1143
|
+
brand: brand,
|
|
1144
|
+
categories: categories,
|
|
1145
|
+
id: id,
|
|
1146
|
+
name: name,
|
|
1147
|
+
price: price,
|
|
1148
|
+
sku: sku,
|
|
1149
|
+
slug: slug,
|
|
1150
|
+
stock: stock,
|
|
1151
|
+
weight: weight,
|
|
1152
|
+
EAN: EAN,
|
|
1153
|
+
image: image,
|
|
1154
|
+
pricePaid: 0,
|
|
1155
|
+
quantity: 1,
|
|
1156
|
+
isGift: true,
|
|
1157
|
+
});
|
|
1158
|
+
});
|
|
1159
|
+
};
|
|
996
1160
|
return CartService;
|
|
997
1161
|
}());
|
|
998
|
-
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 });
|
|
1162
|
+
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: 'Buy2WinRepository' }], target: i0__namespace.ɵɵFactoryTarget.Injectable });
|
|
999
1163
|
CartService.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0__namespace, type: CartService });
|
|
1000
1164
|
i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0__namespace, type: CartService, decorators: [{
|
|
1001
1165
|
type: i0.Injectable
|
|
@@ -1006,6 +1170,9 @@
|
|
|
1006
1170
|
}] }, { type: undefined, decorators: [{
|
|
1007
1171
|
type: i0.Inject,
|
|
1008
1172
|
args: ['ProductRepository']
|
|
1173
|
+
}] }, { type: undefined, decorators: [{
|
|
1174
|
+
type: i0.Inject,
|
|
1175
|
+
args: ['Buy2WinRepository']
|
|
1009
1176
|
}] }];
|
|
1010
1177
|
} });
|
|
1011
1178
|
|