@infrab4a/connect-angular 2.0.6-beta.7 → 2.0.6-beta.8
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 +60 -35
- package/bundles/infrab4a-connect-angular.umd.js.map +1 -1
- package/esm2015/services/checkout.service.js +2 -2
- package/esm2015/services/coupon.service.js +41 -36
- package/fesm2015/infrab4a-connect-angular.js +41 -36
- package/fesm2015/infrab4a-connect-angular.js.map +1 -1
- package/package.json +1 -1
- package/services/checkout.service.d.ts +1 -1
- package/services/coupon.service.d.ts +1 -1
|
@@ -524,7 +524,7 @@
|
|
|
524
524
|
console.log('hasProductCategories', hasProductCategories);
|
|
525
525
|
// Se não tem produtos elegíveis, retorna erro
|
|
526
526
|
if (!hasProductCategories)
|
|
527
|
-
|
|
527
|
+
throw new InvalidCouponError('Seu carrinho não possui produtos elegíveis para desconto.');
|
|
528
528
|
return [2 /*return*/, coupon];
|
|
529
529
|
}
|
|
530
530
|
});
|
|
@@ -540,44 +540,69 @@
|
|
|
540
540
|
return rxjs.of(discount);
|
|
541
541
|
};
|
|
542
542
|
CouponService.prototype.calcDiscountShopping = function (coupon, checkout) {
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
543
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
544
|
+
var discount, _d;
|
|
545
|
+
return __generator(this, function (_e) {
|
|
546
|
+
switch (_e.label) {
|
|
547
|
+
case 0:
|
|
548
|
+
discount = 0;
|
|
549
|
+
_d = coupon.type;
|
|
550
|
+
switch (_d) {
|
|
551
|
+
case i2.CouponTypes.ABSOLUTE: return [3 /*break*/, 1];
|
|
552
|
+
case i2.CouponTypes.PERCENTAGE: return [3 /*break*/, 2];
|
|
553
|
+
}
|
|
554
|
+
return [3 /*break*/, 4];
|
|
555
|
+
case 1:
|
|
556
|
+
{
|
|
557
|
+
discount = coupon.discount;
|
|
558
|
+
return [3 /*break*/, 4];
|
|
559
|
+
}
|
|
560
|
+
_e.label = 2;
|
|
561
|
+
case 2: return [4 /*yield*/, this.calcShoppingPercentageDiscount(coupon, checkout)];
|
|
562
|
+
case 3:
|
|
563
|
+
discount = _e.sent();
|
|
564
|
+
return [3 /*break*/, 4];
|
|
565
|
+
case 4: return [2 /*return*/, rxjs.of(discount)];
|
|
566
|
+
}
|
|
567
|
+
});
|
|
568
|
+
});
|
|
555
569
|
};
|
|
556
570
|
CouponService.prototype.calcShoppingPercentageDiscount = function (coupon, checkout) {
|
|
557
571
|
var _a;
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
572
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
573
|
+
var discount, shop, lineItensDiscount, couponCategories, subTotal;
|
|
574
|
+
return __generator(this, function (_d) {
|
|
575
|
+
switch (_d.label) {
|
|
576
|
+
case 0:
|
|
577
|
+
discount = 0;
|
|
578
|
+
shop = checkout.shop;
|
|
579
|
+
lineItensDiscount = [];
|
|
580
|
+
return [4 /*yield*/, this.getCouponCategoriesId(coupon)];
|
|
581
|
+
case 1:
|
|
582
|
+
couponCategories = _d.sent();
|
|
583
|
+
if (coupon.productsCategories && coupon.productsCategories.length) {
|
|
584
|
+
lineItensDiscount = (_a = checkout.lineItems) === null || _a === void 0 ? void 0 : _a.filter(function (i) {
|
|
585
|
+
var _a;
|
|
586
|
+
if ((_a = i.categories) === null || _a === void 0 ? void 0 : _a.length) {
|
|
587
|
+
return i.categories.some(function (c) { return couponCategories.some(function (cat) { return (cat.id == c || cat.firestoreId == c); }); });
|
|
588
|
+
}
|
|
589
|
+
return true;
|
|
590
|
+
});
|
|
591
|
+
}
|
|
592
|
+
else {
|
|
593
|
+
lineItensDiscount = checkout.lineItems;
|
|
594
|
+
}
|
|
595
|
+
subTotal = lineItensDiscount.reduce(function (acc, curr) {
|
|
596
|
+
var _a, _b, _c;
|
|
597
|
+
return ((_a = checkout.user) === null || _a === void 0 ? void 0 : _a.isSubscriber) && ((_b = curr.price[shop]) === null || _b === void 0 ? void 0 : _b.subscriberPrice)
|
|
598
|
+
? acc + ((_c = curr.price[shop]) === null || _c === void 0 ? void 0 : _c.subscriberPrice) * curr.quantity
|
|
599
|
+
: acc + curr.pricePaid * curr.quantity;
|
|
600
|
+
}, 0) || 0;
|
|
601
|
+
discount = subTotal * (coupon.discount / 100);
|
|
602
|
+
return [2 /*return*/, discount];
|
|
566
603
|
}
|
|
567
|
-
return true;
|
|
568
604
|
});
|
|
569
|
-
}
|
|
570
|
-
else {
|
|
571
|
-
lineItensDiscount = checkout.lineItems;
|
|
572
|
-
}
|
|
573
|
-
var subTotal = lineItensDiscount.reduce(function (acc, curr) {
|
|
574
|
-
var _a, _b, _c;
|
|
575
|
-
return ((_a = checkout.user) === null || _a === void 0 ? void 0 : _a.isSubscriber) && ((_b = curr.price[shop]) === null || _b === void 0 ? void 0 : _b.subscriberPrice)
|
|
576
|
-
? acc + ((_c = curr.price[shop]) === null || _c === void 0 ? void 0 : _c.subscriberPrice) * curr.quantity
|
|
577
|
-
: acc + curr.pricePaid * curr.quantity;
|
|
578
|
-
}, 0) || 0;
|
|
579
|
-
discount = subTotal * (coupon.discount / 100);
|
|
580
|
-
return discount;
|
|
605
|
+
});
|
|
581
606
|
};
|
|
582
607
|
CouponService.prototype.hasMinSubTotal = function (coupon, checkout) {
|
|
583
608
|
var _a;
|
|
@@ -761,7 +786,7 @@
|
|
|
761
786
|
};
|
|
762
787
|
CheckoutService.prototype.calcDiscount = function (coupon) {
|
|
763
788
|
var _this = this;
|
|
764
|
-
return this.getCheckout().pipe(operators.concatMap(function (checkout) { return _this.couponService.calcDiscountShopping(coupon, checkout)
|
|
789
|
+
return this.getCheckout().pipe(operators.concatMap(function (checkout) { return _this.couponService.calcDiscountShopping(coupon, checkout); }));
|
|
765
790
|
};
|
|
766
791
|
CheckoutService.prototype.checkCoupon = function (nickname, checkoutType) {
|
|
767
792
|
var _this = this;
|