@infrab4a/connect-angular 3.10.0-beta.0 → 3.10.0-beta.10
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 +187 -101
- package/bundles/infrab4a-connect-angular.umd.js.map +1 -1
- package/esm2015/services/cart.service.js +32 -12
- package/esm2015/services/coupon.service.js +37 -19
- package/fesm2015/infrab4a-connect-angular.js +66 -28
- package/fesm2015/infrab4a-connect-angular.js.map +1 -1
- package/package.json +2 -2
- package/services/cart.service.d.ts +4 -2
- package/services/coupon.service.d.ts +1 -0
|
@@ -423,9 +423,9 @@
|
|
|
423
423
|
return __generator(this, function (_c) {
|
|
424
424
|
if (!coupon)
|
|
425
425
|
throw 'Cupom inválido.';
|
|
426
|
-
if ((coupon === null || coupon === void 0 ? void 0 : coupon.beginAt) && (coupon === null || coupon === void 0 ? void 0 : coupon.beginAt) > new Date())
|
|
426
|
+
if ((coupon === null || coupon === void 0 ? void 0 : coupon.beginAt) && (coupon === null || coupon === void 0 ? void 0 : coupon.beginAt.getTime()) > new Date().getTime())
|
|
427
427
|
throw 'Cupom inválido.';
|
|
428
|
-
if ((coupon === null || coupon === void 0 ? void 0 : coupon.expiresIn) && (coupon === null || coupon === void 0 ? void 0 : coupon.expiresIn) < new Date())
|
|
428
|
+
if ((coupon === null || coupon === void 0 ? void 0 : coupon.expiresIn) && (coupon === null || coupon === void 0 ? void 0 : coupon.expiresIn.getTime()) < new Date().getTime())
|
|
429
429
|
throw 'Cupom expirado.';
|
|
430
430
|
isInShop = coupon.shopAvailability === i3.Shops.ALL || coupon.shopAvailability === this.defaultShop;
|
|
431
431
|
if (!isInShop)
|
|
@@ -439,7 +439,7 @@
|
|
|
439
439
|
};
|
|
440
440
|
CouponService.prototype.couponRulesValidation = function (coupon, checkoutType, checkout, plan) {
|
|
441
441
|
return __awaiter(this, void 0, void 0, function () {
|
|
442
|
-
var orders, ordersWithUser,
|
|
442
|
+
var validUser, orders, ordersWithUser, couponUseLimits, hasProductCategories, hasMinSubTotal;
|
|
443
443
|
return __generator(this, function (_c) {
|
|
444
444
|
switch (_c.label) {
|
|
445
445
|
case 0:
|
|
@@ -448,17 +448,18 @@
|
|
|
448
448
|
throw 'Cupom inválido para sua assinatura.';
|
|
449
449
|
return [2 /*return*/, coupon];
|
|
450
450
|
}
|
|
451
|
+
validUser = this.coupomUserValidation(coupon, checkout === null || checkout === void 0 ? void 0 : checkout.user);
|
|
452
|
+
if (!validUser)
|
|
453
|
+
throw 'Usuário não elegível.';
|
|
451
454
|
return [4 /*yield*/, this.getOrdersWithCoupon(coupon)];
|
|
452
455
|
case 1:
|
|
453
456
|
orders = _c.sent();
|
|
454
457
|
ordersWithUser = this.countOrdersWithUser(orders, checkout.user.email);
|
|
455
|
-
|
|
458
|
+
couponUseLimits = this.getCouponUseLimits(coupon, checkoutType, checkout.user);
|
|
459
|
+
if (couponUseLimits.limitedPerUser && ordersWithUser > 0)
|
|
456
460
|
throw 'Limite de uso por usuário atingido.';
|
|
457
|
-
if (!
|
|
461
|
+
if (!couponUseLimits.unlimited && couponUseLimits.total && orders.length >= couponUseLimits.total)
|
|
458
462
|
throw 'Limite de uso atingido.';
|
|
459
|
-
validUser = this.coupomUserValidation(coupon, checkout === null || checkout === void 0 ? void 0 : checkout.user);
|
|
460
|
-
if (!validUser)
|
|
461
|
-
throw 'Usuário não elegível.';
|
|
462
463
|
return [4 /*yield*/, this.hasProductCategories(coupon, checkout)];
|
|
463
464
|
case 2:
|
|
464
465
|
hasProductCategories = _c.sent();
|
|
@@ -561,7 +562,7 @@
|
|
|
561
562
|
var _a;
|
|
562
563
|
if (!i.categories || !((_a = i.categories) === null || _a === void 0 ? void 0 : _a.length))
|
|
563
564
|
return true;
|
|
564
|
-
return i.categories.some(function (c) { return couponCategories.some(function (cat) { return cat
|
|
565
|
+
return i.categories.some(function (c) { return couponCategories.some(function (cat) { return cat == c; }); });
|
|
565
566
|
});
|
|
566
567
|
return [2 /*return*/, hasCategories.length ? true : false];
|
|
567
568
|
}
|
|
@@ -576,17 +577,21 @@
|
|
|
576
577
|
userTypes.push(i3.Exclusivities.COLLABORATORS);
|
|
577
578
|
if (coupon.exclusivityType.includes(i3.Exclusivities.SPECIFIC_USER) && coupon.userExclusiveEmail.includes(user.email))
|
|
578
579
|
userTypes.push(i3.Exclusivities.SPECIFIC_USER);
|
|
579
|
-
if (coupon.exclusivityType.includes(i3.Exclusivities.ACTIVE_SUBSCRIBER) &&
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
coupon.exclusivityType.includes(i3.Exclusivities.INACTIVE_SUBSCRIBER)) &&
|
|
583
|
-
!user.isSubscriber)
|
|
580
|
+
if (coupon.exclusivityType.includes(i3.Exclusivities.ACTIVE_SUBSCRIBER) &&
|
|
581
|
+
user.isSubscriber &&
|
|
582
|
+
user.subscriptionPlan != '')
|
|
584
583
|
userTypes.push(i3.Exclusivities.ACTIVE_SUBSCRIBER);
|
|
584
|
+
if (user.isSubscriber &&
|
|
585
|
+
user.subscriptionPlan == '' &&
|
|
586
|
+
coupon.exclusivityType.includes(i3.Exclusivities.INACTIVE_SUBSCRIBER))
|
|
587
|
+
userTypes.push(i3.Exclusivities.INACTIVE_SUBSCRIBER);
|
|
588
|
+
if (coupon.exclusivityType.includes(i3.Exclusivities.NON_SUBSCRIBER) && !user.isSubscriber)
|
|
589
|
+
userTypes.push(i3.Exclusivities.NON_SUBSCRIBER);
|
|
585
590
|
return coupon.exclusivityType.some(function (r) { return userTypes.includes(r); });
|
|
586
591
|
};
|
|
587
592
|
CouponService.prototype.getCouponCategoriesId = function (productsCategories) {
|
|
588
593
|
return __awaiter(this, void 0, void 0, function () {
|
|
589
|
-
var couponCategories, index,
|
|
594
|
+
var couponCategories, index, category, children;
|
|
590
595
|
return __generator(this, function (_c) {
|
|
591
596
|
switch (_c.label) {
|
|
592
597
|
case 0:
|
|
@@ -594,18 +599,22 @@
|
|
|
594
599
|
index = 0;
|
|
595
600
|
_c.label = 1;
|
|
596
601
|
case 1:
|
|
597
|
-
if (!(index < productsCategories.length)) return [3 /*break*/,
|
|
602
|
+
if (!(index < productsCategories.length)) return [3 /*break*/, 5];
|
|
598
603
|
return [4 /*yield*/, this.categoryRepository.get({
|
|
599
604
|
id: productsCategories[index],
|
|
600
605
|
})];
|
|
601
606
|
case 2:
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
607
|
+
category = _c.sent();
|
|
608
|
+
if (!category) return [3 /*break*/, 4];
|
|
609
|
+
return [4 /*yield*/, this.categoryRepository.getChildren(parseInt(productsCategories[index]))];
|
|
605
610
|
case 3:
|
|
611
|
+
children = _c.sent();
|
|
612
|
+
couponCategories.push.apply(couponCategories, __spreadArray([category.id], __read(children.map(function (c) { return c.id.toString(); }))));
|
|
613
|
+
_c.label = 4;
|
|
614
|
+
case 4:
|
|
606
615
|
index++;
|
|
607
616
|
return [3 /*break*/, 1];
|
|
608
|
-
case
|
|
617
|
+
case 5: return [2 /*return*/, __spreadArray([], __read(new Set(couponCategories)))];
|
|
609
618
|
}
|
|
610
619
|
});
|
|
611
620
|
});
|
|
@@ -625,7 +634,7 @@
|
|
|
625
634
|
lineItensDiscount = (_a = checkout.lineItems) === null || _a === void 0 ? void 0 : _a.filter(function (i) {
|
|
626
635
|
var _a;
|
|
627
636
|
if ((_a = i.categories) === null || _a === void 0 ? void 0 : _a.length) {
|
|
628
|
-
return i.categories.some(function (c) { return couponCategories.some(function (cat) { return cat
|
|
637
|
+
return i.categories.some(function (c) { return couponCategories.some(function (cat) { return cat == c; }); });
|
|
629
638
|
}
|
|
630
639
|
return true;
|
|
631
640
|
});
|
|
@@ -666,6 +675,16 @@
|
|
|
666
675
|
CouponService.prototype.countOrdersWithUser = function (orders, email) {
|
|
667
676
|
return orders.filter(function (o) { return o.user.email == email; }).length;
|
|
668
677
|
};
|
|
678
|
+
CouponService.prototype.getCouponUseLimits = function (coupon, checkoutType, user) {
|
|
679
|
+
var couponUseLimits;
|
|
680
|
+
if (checkoutType == i3.CheckoutTypes.ECOMMERCE || checkoutType == i3.CheckoutTypes.ALL) {
|
|
681
|
+
couponUseLimits = user && user.isSubscriber ? coupon.useLimits.subscriber : coupon.useLimits.non_subscriber;
|
|
682
|
+
}
|
|
683
|
+
else {
|
|
684
|
+
couponUseLimits = coupon.useLimits.subscription;
|
|
685
|
+
}
|
|
686
|
+
return couponUseLimits;
|
|
687
|
+
};
|
|
669
688
|
return CouponService;
|
|
670
689
|
}());
|
|
671
690
|
CouponService.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0__namespace, type: CouponService, deps: [{ token: 'CouponRepository' }, { token: DEFAULT_SHOP }, { token: 'OrderRepository' }, { token: 'CategoryRepository' }], target: i0__namespace.ɵɵFactoryTarget.Injectable });
|
|
@@ -769,12 +788,13 @@
|
|
|
769
788
|
} });
|
|
770
789
|
|
|
771
790
|
var CartService = /** @class */ (function () {
|
|
772
|
-
function CartService(authService, checkoutService, defaultShop, productRepository, variantRepository, buy2WinRepository) {
|
|
791
|
+
function CartService(authService, checkoutService, defaultShop, productRepository, categoryRepository, variantRepository, buy2WinRepository) {
|
|
773
792
|
var _this = this;
|
|
774
793
|
this.authService = authService;
|
|
775
794
|
this.checkoutService = checkoutService;
|
|
776
795
|
this.defaultShop = defaultShop;
|
|
777
796
|
this.productRepository = productRepository;
|
|
797
|
+
this.categoryRepository = categoryRepository;
|
|
778
798
|
this.variantRepository = variantRepository;
|
|
779
799
|
this.buy2WinRepository = buy2WinRepository;
|
|
780
800
|
this.cartSubject = new rxjs.Subject();
|
|
@@ -819,6 +839,7 @@
|
|
|
819
839
|
shop: checkout.shop || this.defaultShop,
|
|
820
840
|
isSubscriber: (_e = checkout.user) === null || _e === void 0 ? void 0 : _e.isSubscriber,
|
|
821
841
|
});
|
|
842
|
+
i3.RoundProductPricesHelper.roundProductPrices(item);
|
|
822
843
|
return [2 /*return*/, {
|
|
823
844
|
checkout: checkout,
|
|
824
845
|
lineItem: i3.LineItem.toInstance({
|
|
@@ -829,7 +850,7 @@
|
|
|
829
850
|
slug: slug !== null && slug !== void 0 ? slug : product.slug,
|
|
830
851
|
sku: sku !== null && sku !== void 0 ? sku : product.sku,
|
|
831
852
|
stock: stock,
|
|
832
|
-
price: price,
|
|
853
|
+
price: this.roundPrice(price),
|
|
833
854
|
image: image,
|
|
834
855
|
weight: weight !== null && weight !== void 0 ? weight : product.weight,
|
|
835
856
|
quantity: (item.quantity || 0) + (quantity || 0),
|
|
@@ -849,7 +870,9 @@
|
|
|
849
870
|
var info = product.price;
|
|
850
871
|
if (product.isGift)
|
|
851
872
|
return 0;
|
|
852
|
-
return isSubscriber && info.subscriberPrice > 0
|
|
873
|
+
return isSubscriber && info.subscriberPrice > 0
|
|
874
|
+
? Number(info.subscriberPrice.toFixed(2))
|
|
875
|
+
: Number(info.price.toFixed(2));
|
|
853
876
|
};
|
|
854
877
|
this.checkMaxStock = function (item, quantity) {
|
|
855
878
|
var _a;
|
|
@@ -945,9 +968,13 @@
|
|
|
945
968
|
var _this = this;
|
|
946
969
|
return this.checkoutService.getCheckout(checkoutData).pipe(operators.map(function (checkout) { return checkout.lineItems; }), operators.concatMap(function (lineItems) { return rxjs.of(_this.generateCartObject(lineItems)); }));
|
|
947
970
|
};
|
|
971
|
+
CartService.prototype.roundPrice = function (productPrice) {
|
|
972
|
+
var price = productPrice.price, fullPrice = productPrice.fullPrice, subscriberPrice = productPrice.subscriberPrice;
|
|
973
|
+
return Object.assign(Object.assign(Object.assign({}, productPrice), { price: Number(price.toFixed(2)), fullPrice: Number(fullPrice.toFixed(2)) }), (subscriberPrice && { subscriberPrice: Number(subscriberPrice.toFixed(2)) }));
|
|
974
|
+
};
|
|
948
975
|
CartService.prototype.getProductData = function (productId) {
|
|
949
976
|
return __awaiter(this, void 0, void 0, function () {
|
|
950
|
-
var product, variant, error_1;
|
|
977
|
+
var product, variant, error_1, variants;
|
|
951
978
|
return __generator(this, function (_h) {
|
|
952
979
|
switch (_h.label) {
|
|
953
980
|
case 0:
|
|
@@ -960,9 +987,12 @@
|
|
|
960
987
|
error_1 = _h.sent();
|
|
961
988
|
if (!(error_1 instanceof i3.NotFoundError))
|
|
962
989
|
throw error_1;
|
|
963
|
-
return [4 /*yield*/, this.variantRepository.
|
|
990
|
+
return [4 /*yield*/, this.variantRepository.find({ filters: { id: productId } })];
|
|
964
991
|
case 3:
|
|
965
|
-
|
|
992
|
+
variants = (_h.sent()).data;
|
|
993
|
+
variant = variants.shift();
|
|
994
|
+
if (!variant)
|
|
995
|
+
throw error_1;
|
|
966
996
|
return [4 /*yield*/, this.productRepository.get({ id: variant.productId })];
|
|
967
997
|
case 4:
|
|
968
998
|
product = _h.sent();
|
|
@@ -975,8 +1005,8 @@
|
|
|
975
1005
|
CartService.prototype.getGifts = function () {
|
|
976
1006
|
var _this = this;
|
|
977
1007
|
return this.checkoutService.getCheckout().pipe(operators.mergeMap(function (checkout) { return __awaiter(_this, void 0, void 0, function () {
|
|
978
|
-
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,
|
|
979
|
-
var
|
|
1008
|
+
var notGiftItems, cartTotal, campaigns, elegibleCampaigns, _loop_1, this_1, campaigns_1, campaigns_1_1, campaign, e_1_1, campaingnProducts, elegibleCampaigns_1, elegibleCampaigns_1_1, campaign, elegibleProducts, _h, _j, product, productData, gift, e_2_1, e_3_1, gifts;
|
|
1009
|
+
var e_1, _k, e_3, _l, e_2, _m;
|
|
980
1010
|
return __generator(this, function (_o) {
|
|
981
1011
|
switch (_o.label) {
|
|
982
1012
|
case 0:
|
|
@@ -998,105 +1028,158 @@
|
|
|
998
1028
|
return [2 /*return*/, Object.assign(Object.assign({}, checkout), { lineItems: notGiftItems })];
|
|
999
1029
|
elegibleCampaigns = [];
|
|
1000
1030
|
_loop_1 = function (campaign) {
|
|
1001
|
-
var today
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
return
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1031
|
+
var today, categoriesCampaing, categoriesCampaingFullTree, categoriesCampaing_1, categoriesCampaing_1_1, id, children, e_4_1, categoriesCampaingTree_1, filterProductsCategories, cartTotalCategories;
|
|
1032
|
+
var e_4, _p;
|
|
1033
|
+
return __generator(this, function (_q) {
|
|
1034
|
+
switch (_q.label) {
|
|
1035
|
+
case 0:
|
|
1036
|
+
today = new Date().getDate();
|
|
1037
|
+
if (!(campaign.startDate.getDate() <= today) && !(campaign.endDate.getDate() >= today))
|
|
1038
|
+
return [2 /*return*/, "continue"];
|
|
1039
|
+
if (!campaign.activeCategory) return [3 /*break*/, 9];
|
|
1040
|
+
categoriesCampaing = campaign.categories.map(function (c) { return c.id.toString(); });
|
|
1041
|
+
categoriesCampaingFullTree = [];
|
|
1042
|
+
_q.label = 1;
|
|
1043
|
+
case 1:
|
|
1044
|
+
_q.trys.push([1, 6, 7, 8]);
|
|
1045
|
+
categoriesCampaing_1 = (e_4 = void 0, __values(categoriesCampaing)), categoriesCampaing_1_1 = categoriesCampaing_1.next();
|
|
1046
|
+
_q.label = 2;
|
|
1047
|
+
case 2:
|
|
1048
|
+
if (!!categoriesCampaing_1_1.done) return [3 /*break*/, 5];
|
|
1049
|
+
id = categoriesCampaing_1_1.value;
|
|
1050
|
+
return [4 /*yield*/, this_1.categoryRepository.getChildren(parseInt(id))];
|
|
1051
|
+
case 3:
|
|
1052
|
+
children = _q.sent();
|
|
1053
|
+
categoriesCampaingFullTree.push.apply(categoriesCampaingFullTree, __spreadArray([id], __read(children.map(function (c) { return c.id.toString(); }))));
|
|
1054
|
+
_q.label = 4;
|
|
1055
|
+
case 4:
|
|
1056
|
+
categoriesCampaing_1_1 = categoriesCampaing_1.next();
|
|
1057
|
+
return [3 /*break*/, 2];
|
|
1058
|
+
case 5: return [3 /*break*/, 8];
|
|
1059
|
+
case 6:
|
|
1060
|
+
e_4_1 = _q.sent();
|
|
1061
|
+
e_4 = { error: e_4_1 };
|
|
1062
|
+
return [3 /*break*/, 8];
|
|
1063
|
+
case 7:
|
|
1064
|
+
try {
|
|
1065
|
+
if (categoriesCampaing_1_1 && !categoriesCampaing_1_1.done && (_p = categoriesCampaing_1.return)) _p.call(categoriesCampaing_1);
|
|
1066
|
+
}
|
|
1067
|
+
finally { if (e_4) throw e_4.error; }
|
|
1068
|
+
return [7 /*endfinally*/];
|
|
1069
|
+
case 8:
|
|
1070
|
+
categoriesCampaingTree_1 = __spreadArray([], __read(new Set(categoriesCampaingFullTree)));
|
|
1071
|
+
filterProductsCategories = checkout.lineItems.filter(function (l) {
|
|
1072
|
+
var _a;
|
|
1073
|
+
if (!l.categories || !((_a = l.categories) === null || _a === void 0 ? void 0 : _a.length))
|
|
1074
|
+
return true;
|
|
1075
|
+
return l.categories.some(function (c) { return categoriesCampaingTree_1.some(function (cat) { return cat == c; }); });
|
|
1076
|
+
});
|
|
1077
|
+
if (filterProductsCategories.length) {
|
|
1078
|
+
cartTotalCategories = filterProductsCategories.reduce(function (a, b) { return a + b.pricePaid * b.quantity; }, 0);
|
|
1079
|
+
if (cartTotalCategories >= campaign.cartValueMin)
|
|
1080
|
+
elegibleCampaigns.push(campaign);
|
|
1081
|
+
}
|
|
1082
|
+
return [3 /*break*/, 10];
|
|
1083
|
+
case 9:
|
|
1084
|
+
if (campaign.cartValue && campaign.cartValue > 0) {
|
|
1085
|
+
if (campaign.cartValue <= cartTotal)
|
|
1086
|
+
elegibleCampaigns.push(campaign);
|
|
1087
|
+
}
|
|
1088
|
+
_q.label = 10;
|
|
1089
|
+
case 10: return [2 /*return*/];
|
|
1022
1090
|
}
|
|
1023
|
-
}
|
|
1091
|
+
});
|
|
1024
1092
|
};
|
|
1093
|
+
this_1 = this;
|
|
1094
|
+
_o.label = 2;
|
|
1095
|
+
case 2:
|
|
1096
|
+
_o.trys.push([2, 7, 8, 9]);
|
|
1097
|
+
campaigns_1 = __values(campaigns), campaigns_1_1 = campaigns_1.next();
|
|
1098
|
+
_o.label = 3;
|
|
1099
|
+
case 3:
|
|
1100
|
+
if (!!campaigns_1_1.done) return [3 /*break*/, 6];
|
|
1101
|
+
campaign = campaigns_1_1.value;
|
|
1102
|
+
return [5 /*yield**/, _loop_1(campaign)];
|
|
1103
|
+
case 4:
|
|
1104
|
+
_o.sent();
|
|
1105
|
+
_o.label = 5;
|
|
1106
|
+
case 5:
|
|
1107
|
+
campaigns_1_1 = campaigns_1.next();
|
|
1108
|
+
return [3 /*break*/, 3];
|
|
1109
|
+
case 6: return [3 /*break*/, 9];
|
|
1110
|
+
case 7:
|
|
1111
|
+
e_1_1 = _o.sent();
|
|
1112
|
+
e_1 = { error: e_1_1 };
|
|
1113
|
+
return [3 /*break*/, 9];
|
|
1114
|
+
case 8:
|
|
1025
1115
|
try {
|
|
1026
|
-
|
|
1027
|
-
campaign = campaigns_1_1.value;
|
|
1028
|
-
_loop_1(campaign);
|
|
1029
|
-
}
|
|
1030
|
-
}
|
|
1031
|
-
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
1032
|
-
finally {
|
|
1033
|
-
try {
|
|
1034
|
-
if (campaigns_1_1 && !campaigns_1_1.done && (_k = campaigns_1.return)) _k.call(campaigns_1);
|
|
1035
|
-
}
|
|
1036
|
-
finally { if (e_3) throw e_3.error; }
|
|
1116
|
+
if (campaigns_1_1 && !campaigns_1_1.done && (_k = campaigns_1.return)) _k.call(campaigns_1);
|
|
1037
1117
|
}
|
|
1118
|
+
finally { if (e_1) throw e_1.error; }
|
|
1119
|
+
return [7 /*endfinally*/];
|
|
1120
|
+
case 9:
|
|
1038
1121
|
if (!elegibleCampaigns.length)
|
|
1039
1122
|
return [2 /*return*/, Object.assign(Object.assign({}, checkout), { lineItems: notGiftItems })];
|
|
1040
1123
|
campaingnProducts = [];
|
|
1041
|
-
_o.label =
|
|
1042
|
-
case
|
|
1043
|
-
_o.trys.push([
|
|
1124
|
+
_o.label = 10;
|
|
1125
|
+
case 10:
|
|
1126
|
+
_o.trys.push([10, 22, 23, 24]);
|
|
1044
1127
|
elegibleCampaigns_1 = __values(elegibleCampaigns), elegibleCampaigns_1_1 = elegibleCampaigns_1.next();
|
|
1045
|
-
_o.label =
|
|
1046
|
-
case
|
|
1047
|
-
if (!!elegibleCampaigns_1_1.done) return [3 /*break*/,
|
|
1128
|
+
_o.label = 11;
|
|
1129
|
+
case 11:
|
|
1130
|
+
if (!!elegibleCampaigns_1_1.done) return [3 /*break*/, 21];
|
|
1048
1131
|
campaign = elegibleCampaigns_1_1.value;
|
|
1049
1132
|
elegibleProducts = [];
|
|
1050
|
-
_o.label =
|
|
1051
|
-
case
|
|
1052
|
-
_o.trys.push([
|
|
1053
|
-
_h = (
|
|
1054
|
-
_o.label =
|
|
1055
|
-
case
|
|
1056
|
-
if (!!_j.done) return [3 /*break*/,
|
|
1133
|
+
_o.label = 12;
|
|
1134
|
+
case 12:
|
|
1135
|
+
_o.trys.push([12, 17, 18, 19]);
|
|
1136
|
+
_h = (e_2 = void 0, __values(campaign.products)), _j = _h.next();
|
|
1137
|
+
_o.label = 13;
|
|
1138
|
+
case 13:
|
|
1139
|
+
if (!!_j.done) return [3 /*break*/, 16];
|
|
1057
1140
|
product = _j.value;
|
|
1058
1141
|
return [4 /*yield*/, this.productRepository.find({ filters: { sku: product } })];
|
|
1059
|
-
case
|
|
1142
|
+
case 14:
|
|
1060
1143
|
productData = (_o.sent()).data;
|
|
1061
1144
|
if (!productData.length)
|
|
1062
|
-
return [3 /*break*/,
|
|
1145
|
+
return [3 /*break*/, 15];
|
|
1063
1146
|
gift = productData.shift();
|
|
1064
1147
|
if (gift.stock.quantity < 1)
|
|
1065
|
-
return [3 /*break*/,
|
|
1148
|
+
return [3 /*break*/, 15];
|
|
1066
1149
|
elegibleProducts.push(gift);
|
|
1067
|
-
_o.label =
|
|
1068
|
-
case
|
|
1150
|
+
_o.label = 15;
|
|
1151
|
+
case 15:
|
|
1069
1152
|
_j = _h.next();
|
|
1070
|
-
return [3 /*break*/,
|
|
1071
|
-
case
|
|
1072
|
-
case
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
return [3 /*break*/,
|
|
1076
|
-
case
|
|
1153
|
+
return [3 /*break*/, 13];
|
|
1154
|
+
case 16: return [3 /*break*/, 19];
|
|
1155
|
+
case 17:
|
|
1156
|
+
e_2_1 = _o.sent();
|
|
1157
|
+
e_2 = { error: e_2_1 };
|
|
1158
|
+
return [3 /*break*/, 19];
|
|
1159
|
+
case 18:
|
|
1077
1160
|
try {
|
|
1078
1161
|
if (_j && !_j.done && (_m = _h.return)) _m.call(_h);
|
|
1079
1162
|
}
|
|
1080
|
-
finally { if (
|
|
1163
|
+
finally { if (e_2) throw e_2.error; }
|
|
1081
1164
|
return [7 /*endfinally*/];
|
|
1082
|
-
case
|
|
1165
|
+
case 19:
|
|
1083
1166
|
campaingnProducts.push(elegibleProducts);
|
|
1084
|
-
_o.label =
|
|
1085
|
-
case
|
|
1167
|
+
_o.label = 20;
|
|
1168
|
+
case 20:
|
|
1086
1169
|
elegibleCampaigns_1_1 = elegibleCampaigns_1.next();
|
|
1087
|
-
return [3 /*break*/,
|
|
1088
|
-
case
|
|
1089
|
-
case
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
return [3 /*break*/,
|
|
1093
|
-
case
|
|
1170
|
+
return [3 /*break*/, 11];
|
|
1171
|
+
case 21: return [3 /*break*/, 24];
|
|
1172
|
+
case 22:
|
|
1173
|
+
e_3_1 = _o.sent();
|
|
1174
|
+
e_3 = { error: e_3_1 };
|
|
1175
|
+
return [3 /*break*/, 24];
|
|
1176
|
+
case 23:
|
|
1094
1177
|
try {
|
|
1095
1178
|
if (elegibleCampaigns_1_1 && !elegibleCampaigns_1_1.done && (_l = elegibleCampaigns_1.return)) _l.call(elegibleCampaigns_1);
|
|
1096
1179
|
}
|
|
1097
|
-
finally { if (
|
|
1180
|
+
finally { if (e_3) throw e_3.error; }
|
|
1098
1181
|
return [7 /*endfinally*/];
|
|
1099
|
-
case
|
|
1182
|
+
case 24:
|
|
1100
1183
|
if (!campaingnProducts.length)
|
|
1101
1184
|
return [2 /*return*/, Object.assign(Object.assign({}, checkout), { lineItems: notGiftItems })];
|
|
1102
1185
|
gifts = this.giftToLineItems([].concat.apply([], __spreadArray([], __read(campaingnProducts))));
|
|
@@ -1130,7 +1213,7 @@
|
|
|
1130
1213
|
};
|
|
1131
1214
|
return CartService;
|
|
1132
1215
|
}());
|
|
1133
|
-
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: 'VariantRepository' }, { token: 'Buy2WinRepository' }], target: i0__namespace.ɵɵFactoryTarget.Injectable });
|
|
1216
|
+
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: 'CategoryRepository' }, { token: 'VariantRepository' }, { token: 'Buy2WinRepository' }], target: i0__namespace.ɵɵFactoryTarget.Injectable });
|
|
1134
1217
|
CartService.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0__namespace, type: CartService });
|
|
1135
1218
|
i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0__namespace, type: CartService, decorators: [{
|
|
1136
1219
|
type: i0.Injectable
|
|
@@ -1141,6 +1224,9 @@
|
|
|
1141
1224
|
}] }, { type: undefined, decorators: [{
|
|
1142
1225
|
type: i0.Inject,
|
|
1143
1226
|
args: ['ProductRepository']
|
|
1227
|
+
}] }, { type: undefined, decorators: [{
|
|
1228
|
+
type: i0.Inject,
|
|
1229
|
+
args: ['CategoryRepository']
|
|
1144
1230
|
}] }, { type: undefined, decorators: [{
|
|
1145
1231
|
type: i0.Inject,
|
|
1146
1232
|
args: ['VariantRepository']
|