@infrab4a/connect-angular 3.2.2-beta.5 → 3.2.2
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 +35 -199
- package/bundles/infrab4a-connect-angular.umd.js.map +1 -1
- package/esm2015/services/cart.service.js +12 -113
- package/esm2015/services/home-shop.service.js +25 -22
- package/fesm2015/infrab4a-connect-angular.js +32 -130
- package/fesm2015/infrab4a-connect-angular.js.map +1 -1
- package/package.json +2 -2
- package/services/cart.service.d.ts +2 -7
|
@@ -820,13 +820,12 @@
|
|
|
820
820
|
} });
|
|
821
821
|
|
|
822
822
|
var CartService = /** @class */ (function () {
|
|
823
|
-
function CartService(authService, checkoutService, defaultShop, productRepository
|
|
823
|
+
function CartService(authService, checkoutService, defaultShop, productRepository) {
|
|
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;
|
|
830
829
|
this.cartSubject = new rxjs.Subject();
|
|
831
830
|
this.updateLineItemInCart = function (lineItem, quantity, checkout) { return (i2.isNil(checkout) ? _this.checkoutService.getCheckout() : rxjs.of(checkout)).pipe(operators.concatMap(function (checkoutLoaded) {
|
|
832
831
|
var _a;
|
|
@@ -838,15 +837,10 @@
|
|
|
838
837
|
}
|
|
839
838
|
else
|
|
840
839
|
checkoutLoaded.lineItems = items.concat(checkoutLoaded.lineItems ? checkoutLoaded.lineItems.concat([lineItem]) : [lineItem]);
|
|
841
|
-
return
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
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); })); })); };
|
|
840
|
+
return _this.checkoutService
|
|
841
|
+
.updateCheckoutLineItems(checkoutLoaded)
|
|
842
|
+
.pipe(operators.map(function (updatedCheckout) { return _this.generateCartObject(updatedCheckout.lineItems); }));
|
|
843
|
+
})); };
|
|
850
844
|
this.generateCartObject = function (items) {
|
|
851
845
|
var cart = {};
|
|
852
846
|
items === null || items === void 0 ? void 0 : items.forEach(function (item) {
|
|
@@ -922,7 +916,7 @@
|
|
|
922
916
|
case 0: return [4 /*yield*/, this.buildLineItem({ checkout: checkout, item: item, quantity: quantity || 1 })];
|
|
923
917
|
case 1: return [2 /*return*/, _h.sent()];
|
|
924
918
|
}
|
|
925
|
-
}); }); }), operators.
|
|
919
|
+
}); }); }), operators.mergeMap(function (_h) {
|
|
926
920
|
var checkout = _h.checkout, lineItem = _h.lineItem;
|
|
927
921
|
return _this.updateLineItemInCart(lineItem, quantity || 1, checkout);
|
|
928
922
|
}), operators.tap(function (cart) { return _this.cartSubject.next(cart); }));
|
|
@@ -965,8 +959,7 @@
|
|
|
965
959
|
return __generator(this, function (_s) {
|
|
966
960
|
switch (_s.label) {
|
|
967
961
|
case 0:
|
|
968
|
-
_j = (_h = this.checkoutService)
|
|
969
|
-
.updateCheckoutLineItems;
|
|
962
|
+
_j = (_h = this.checkoutService).updateCheckoutLineItems;
|
|
970
963
|
_l = (_k = i2.Checkout).toInstance;
|
|
971
964
|
_o = (_m = Object).assign;
|
|
972
965
|
_p = [Object.assign({}, checkout.toPlain())];
|
|
@@ -984,8 +977,7 @@
|
|
|
984
977
|
case 2:
|
|
985
978
|
_r = [];
|
|
986
979
|
_s.label = 3;
|
|
987
|
-
case 3: return [2 /*return*/, _j.apply(_h, [_l.apply(_k, [_o.apply(_m, _p.concat([(_q.lineItems = _r, _q)]))])])
|
|
988
|
-
.toPromise()];
|
|
980
|
+
case 3: return [2 /*return*/, _j.apply(_h, [_l.apply(_k, [_o.apply(_m, _p.concat([(_q.lineItems = _r, _q)]))])]).toPromise()];
|
|
989
981
|
}
|
|
990
982
|
});
|
|
991
983
|
}); }), operators.map(function (checkout) { return _this.generateCartObject(checkout.lineItems); }), operators.tap(function (cart) { return _this.cartSubject.next(cart); }));
|
|
@@ -1001,165 +993,9 @@
|
|
|
1001
993
|
var _this = this;
|
|
1002
994
|
return this.checkoutService.getCheckout(checkoutData).pipe(operators.map(function (checkout) { return checkout.lineItems; }), operators.concatMap(function (lineItems) { return rxjs.of(_this.generateCartObject(lineItems)); }));
|
|
1003
995
|
};
|
|
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
|
-
};
|
|
1160
996
|
return CartService;
|
|
1161
997
|
}());
|
|
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' }
|
|
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 });
|
|
1163
999
|
CartService.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0__namespace, type: CartService });
|
|
1164
1000
|
i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0__namespace, type: CartService, decorators: [{
|
|
1165
1001
|
type: i0.Injectable
|
|
@@ -1170,9 +1006,6 @@
|
|
|
1170
1006
|
}] }, { type: undefined, decorators: [{
|
|
1171
1007
|
type: i0.Inject,
|
|
1172
1008
|
args: ['ProductRepository']
|
|
1173
|
-
}] }, { type: undefined, decorators: [{
|
|
1174
|
-
type: i0.Inject,
|
|
1175
|
-
args: ['Buy2WinRepository']
|
|
1176
1009
|
}] }];
|
|
1177
1010
|
} });
|
|
1178
1011
|
|
|
@@ -1264,25 +1097,28 @@
|
|
|
1264
1097
|
this.homeRepository = homeRepository;
|
|
1265
1098
|
this.productRepository = productRepository;
|
|
1266
1099
|
this.defaultShop = defaultShop;
|
|
1267
|
-
this.buildCategoryGroupWithRequiredData = function (group) {
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
'id',
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1100
|
+
this.buildCategoryGroupWithRequiredData = function (group) {
|
|
1101
|
+
var _a, _b;
|
|
1102
|
+
return ({
|
|
1103
|
+
category: i2.Category.toInstance(i2.pick(((_a = group === null || group === void 0 ? void 0 : group.category) === null || _a === void 0 ? void 0 : _a.toPlain()) || {}, ['id', 'name', 'slug', 'conditions'])),
|
|
1104
|
+
products: ((_b = group === null || group === void 0 ? void 0 : group.products) === null || _b === void 0 ? void 0 : _b.map(function (product) { return i2.Product.toInstance(i2.pick((product === null || product === void 0 ? void 0 : product.toPlain()) || {}, [
|
|
1105
|
+
'id',
|
|
1106
|
+
'price',
|
|
1107
|
+
'reviews',
|
|
1108
|
+
'hasVariants',
|
|
1109
|
+
'slug',
|
|
1110
|
+
'sku',
|
|
1111
|
+
'stock',
|
|
1112
|
+
'costPrice',
|
|
1113
|
+
'images',
|
|
1114
|
+
'miniatures',
|
|
1115
|
+
'name',
|
|
1116
|
+
'weight',
|
|
1117
|
+
'rate',
|
|
1118
|
+
'type',
|
|
1119
|
+
])); })) || [],
|
|
1120
|
+
});
|
|
1121
|
+
};
|
|
1286
1122
|
}
|
|
1287
1123
|
Object.defineProperty(HomeShopService.prototype, "homeId", {
|
|
1288
1124
|
get: function () {
|
|
@@ -1299,8 +1135,8 @@
|
|
|
1299
1135
|
var _this = this;
|
|
1300
1136
|
return this.getHomeConfiguration().pipe(operators.map(function (home) { var _a; return (((_a = home === null || home === void 0 ? void 0 : home.data) === null || _a === void 0 ? void 0 : _a.expiresAt) > new Date() ? home : null); }), operators.concatMap(function (home) { return home
|
|
1301
1137
|
? rxjs.of(home)
|
|
1302
|
-
: rxjs.forkJoin([_this.getDiscoverProducts(), _this.getFeaturedProducts(), _this.getVerticalProducts()]).pipe(operators.map(function (
|
|
1303
|
-
var
|
|
1138
|
+
: rxjs.forkJoin([_this.getDiscoverProducts(), _this.getFeaturedProducts(), _this.getVerticalProducts()]).pipe(operators.map(function (_c) {
|
|
1139
|
+
var _d = __read(_c, 3), discoverProducts = _d[0], featuredProducts = _d[1], verticalProducts = _d[2];
|
|
1304
1140
|
return ({
|
|
1305
1141
|
discoverProducts: discoverProducts,
|
|
1306
1142
|
featuredProducts: featuredProducts,
|
|
@@ -1336,8 +1172,8 @@
|
|
|
1336
1172
|
return this.getHomeConfiguration().pipe(operators.concatMap(function (home) { return rxjs.forkJoin(home.verticalCarousels.filter(Boolean).map(function (id) { return rxjs.from(_this.categoryRepository.get({ id: id })).pipe(operators.concatMap(function (category) { return rxjs.from(_this.productRepository.find({
|
|
1337
1173
|
filters: { categories: { operator: i2.Where.IN, value: [category.id] } },
|
|
1338
1174
|
limits: { limit: 12 },
|
|
1339
|
-
})).pipe(operators.map(function (products) { return ({ category: category, products: products }); })); }), operators.map(function (
|
|
1340
|
-
var category =
|
|
1175
|
+
})).pipe(operators.map(function (products) { return ({ category: category, products: products }); })); }), operators.map(function (_c) {
|
|
1176
|
+
var category = _c.category, products = _c.products;
|
|
1341
1177
|
return ({ category: category, products: products.data });
|
|
1342
1178
|
}), operators.map(_this.buildCategoryGroupWithRequiredData)); })); }));
|
|
1343
1179
|
};
|