@infrab4a/connect-angular 2.0.6-beta.10 → 2.0.6-beta.3
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 +63 -112
- package/bundles/infrab4a-connect-angular.umd.js.map +1 -1
- package/esm2015/services/checkout.service.js +2 -2
- package/esm2015/services/coupon.service.js +54 -68
- package/fesm2015/infrab4a-connect-angular.js +54 -68
- package/fesm2015/infrab4a-connect-angular.js.map +1 -1
- package/package.json +1 -1
- package/services/coupon.service.d.ts +1 -2
|
@@ -521,9 +521,10 @@
|
|
|
521
521
|
return [4 /*yield*/, this.hasProductCategories(coupon, checkout)];
|
|
522
522
|
case 3:
|
|
523
523
|
hasProductCategories = _d.sent();
|
|
524
|
+
console.log('hasProductCategories', hasProductCategories);
|
|
524
525
|
// Se não tem produtos elegíveis, retorna erro
|
|
525
526
|
if (!hasProductCategories)
|
|
526
|
-
|
|
527
|
+
return [2 /*return*/, rxjs.throwError('Seu carrinho não possui produtos elegíveis para desconto.')];
|
|
527
528
|
return [2 /*return*/, coupon];
|
|
528
529
|
}
|
|
529
530
|
});
|
|
@@ -539,69 +540,44 @@
|
|
|
539
540
|
return rxjs.of(discount);
|
|
540
541
|
};
|
|
541
542
|
CouponService.prototype.calcDiscountShopping = function (coupon, checkout) {
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
case 1:
|
|
555
|
-
{
|
|
556
|
-
discount = coupon.discount;
|
|
557
|
-
return [3 /*break*/, 4];
|
|
558
|
-
}
|
|
559
|
-
_e.label = 2;
|
|
560
|
-
case 2: return [4 /*yield*/, this.calcShoppingPercentageDiscount(coupon, checkout)];
|
|
561
|
-
case 3:
|
|
562
|
-
discount = _e.sent();
|
|
563
|
-
return [3 /*break*/, 4];
|
|
564
|
-
case 4: return [2 /*return*/, discount];
|
|
565
|
-
}
|
|
566
|
-
});
|
|
567
|
-
});
|
|
543
|
+
var discount = 0;
|
|
544
|
+
switch (coupon.type) {
|
|
545
|
+
case i2.CouponTypes.ABSOLUTE: {
|
|
546
|
+
discount = coupon.discount;
|
|
547
|
+
break;
|
|
548
|
+
}
|
|
549
|
+
case i2.CouponTypes.PERCENTAGE: {
|
|
550
|
+
discount = this.calcShoppingPercentageDiscount(coupon, checkout);
|
|
551
|
+
break;
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
return rxjs.of(discount);
|
|
568
555
|
};
|
|
569
556
|
CouponService.prototype.calcShoppingPercentageDiscount = function (coupon, checkout) {
|
|
570
557
|
var _a;
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
return [4 /*yield*/, this.getCouponCategoriesId(coupon)];
|
|
580
|
-
case 1:
|
|
581
|
-
couponCategories = _d.sent();
|
|
582
|
-
if (coupon.productsCategories && coupon.productsCategories.length) {
|
|
583
|
-
lineItensDiscount = (_a = checkout.lineItems) === null || _a === void 0 ? void 0 : _a.filter(function (i) {
|
|
584
|
-
var _a;
|
|
585
|
-
if ((_a = i.categories) === null || _a === void 0 ? void 0 : _a.length) {
|
|
586
|
-
return i.categories.some(function (c) { return couponCategories.some(function (cat) { return (cat.id == c || cat.firestoreId == c); }); });
|
|
587
|
-
}
|
|
588
|
-
return true;
|
|
589
|
-
});
|
|
590
|
-
}
|
|
591
|
-
else {
|
|
592
|
-
lineItensDiscount = checkout.lineItems;
|
|
593
|
-
}
|
|
594
|
-
subTotal = lineItensDiscount.reduce(function (acc, curr) {
|
|
595
|
-
var _a, _b, _c;
|
|
596
|
-
return ((_a = checkout.user) === null || _a === void 0 ? void 0 : _a.isSubscriber) && ((_b = curr.price[shop]) === null || _b === void 0 ? void 0 : _b.subscriberPrice)
|
|
597
|
-
? acc + ((_c = curr.price[shop]) === null || _c === void 0 ? void 0 : _c.subscriberPrice) * curr.quantity
|
|
598
|
-
: acc + curr.pricePaid * curr.quantity;
|
|
599
|
-
}, 0) || 0;
|
|
600
|
-
discount = subTotal * (coupon.discount / 100);
|
|
601
|
-
return [2 /*return*/, discount];
|
|
558
|
+
var discount = 0;
|
|
559
|
+
var shop = checkout.shop;
|
|
560
|
+
var lineItensDiscount = [];
|
|
561
|
+
if (coupon.productsCategories && coupon.productsCategories.length) {
|
|
562
|
+
lineItensDiscount = (_a = checkout.lineItems) === null || _a === void 0 ? void 0 : _a.filter(function (i) {
|
|
563
|
+
var _a;
|
|
564
|
+
if ((_a = i.categories) === null || _a === void 0 ? void 0 : _a.length) {
|
|
565
|
+
return i.categories.some(function (c) { return coupon.productsCategories.includes(c); });
|
|
602
566
|
}
|
|
567
|
+
return true;
|
|
603
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
|
CouponService.prototype.hasMinSubTotal = function (coupon, checkout) {
|
|
607
583
|
var _a;
|
|
@@ -621,32 +597,36 @@
|
|
|
621
597
|
CouponService.prototype.hasProductCategories = function (coupon, checkout) {
|
|
622
598
|
var _a;
|
|
623
599
|
return __awaiter(this, void 0, void 0, function () {
|
|
624
|
-
var
|
|
600
|
+
var hasCategories;
|
|
601
|
+
var _this = this;
|
|
625
602
|
return __generator(this, function (_d) {
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
603
|
+
if (coupon.productsCategories && coupon.productsCategories.length) {
|
|
604
|
+
hasCategories = (_a = checkout.lineItems) === null || _a === void 0 ? void 0 : _a.filter(function (i) {
|
|
605
|
+
var _a;
|
|
606
|
+
if ((_a = i.categories) === null || _a === void 0 ? void 0 : _a.length) {
|
|
607
|
+
return i.categories.some(function (c) { return __awaiter(_this, void 0, void 0, function () {
|
|
608
|
+
var categoria;
|
|
609
|
+
return __generator(this, function (_d) {
|
|
610
|
+
switch (_d.label) {
|
|
611
|
+
case 0: return [4 /*yield*/, this.categoryRepository.get({ id: c })];
|
|
612
|
+
case 1:
|
|
613
|
+
categoria = _d.sent();
|
|
614
|
+
console.log(categoria);
|
|
615
|
+
console.log(coupon.productsCategories.includes(categoria.id), coupon.productsCategories.includes(categoria.firestoreId), i.isGift);
|
|
616
|
+
console.log('validation', (coupon.productsCategories.includes(categoria.id) || coupon.productsCategories.includes(categoria.firestoreId)) && !i.isGift);
|
|
617
|
+
return [2 /*return*/, (coupon.productsCategories.includes(categoria.id) || coupon.productsCategories.includes(categoria.firestoreId)) && !i.isGift];
|
|
618
|
+
}
|
|
619
|
+
});
|
|
620
|
+
}); });
|
|
630
621
|
}
|
|
631
|
-
return
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
return true;
|
|
638
|
-
return i.categories.some(function (c) { return couponCategories.some(function (cat) { return (cat.id == c || cat.firestoreId == c); }); });
|
|
639
|
-
// return i.categories.some(async (c) => {
|
|
640
|
-
// console.log('some category c', c)
|
|
641
|
-
// const categoria: Category & { firestoreId?: string } = await this.categoryRepository.get({id: c})
|
|
642
|
-
// console.log(categoria)
|
|
643
|
-
// console.log(coupon.productsCategories.includes(categoria.id), coupon.productsCategories.includes(categoria.firestoreId), i.isGift)
|
|
644
|
-
// console.log('validation', (coupon.productsCategories.includes(categoria.id) || coupon.productsCategories.includes(categoria.firestoreId)) && !i.isGift)
|
|
645
|
-
// return (coupon.productsCategories.includes(categoria.id) || coupon.productsCategories.includes(categoria.firestoreId)) && !i.isGift
|
|
646
|
-
// })
|
|
647
|
-
});
|
|
648
|
-
return [2 /*return*/, hasCategories.length ? true : false];
|
|
622
|
+
return true;
|
|
623
|
+
});
|
|
624
|
+
return [2 /*return*/, hasCategories.length ? true : false];
|
|
625
|
+
}
|
|
626
|
+
else {
|
|
627
|
+
return [2 /*return*/, true];
|
|
649
628
|
}
|
|
629
|
+
return [2 /*return*/];
|
|
650
630
|
});
|
|
651
631
|
});
|
|
652
632
|
};
|
|
@@ -694,30 +674,6 @@
|
|
|
694
674
|
});
|
|
695
675
|
});
|
|
696
676
|
};
|
|
697
|
-
CouponService.prototype.getCouponCategoriesId = function (coupon) {
|
|
698
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
699
|
-
var couponCategories, index, c;
|
|
700
|
-
return __generator(this, function (_d) {
|
|
701
|
-
switch (_d.label) {
|
|
702
|
-
case 0:
|
|
703
|
-
couponCategories = [];
|
|
704
|
-
index = 0;
|
|
705
|
-
_d.label = 1;
|
|
706
|
-
case 1:
|
|
707
|
-
if (!(index < coupon.productsCategories.length)) return [3 /*break*/, 4];
|
|
708
|
-
return [4 /*yield*/, this.categoryRepository.get({ id: coupon.productsCategories[index] })];
|
|
709
|
-
case 2:
|
|
710
|
-
c = _d.sent();
|
|
711
|
-
couponCategories.push({ id: c.id, firestoreId: c.firestoreId });
|
|
712
|
-
_d.label = 3;
|
|
713
|
-
case 3:
|
|
714
|
-
index++;
|
|
715
|
-
return [3 /*break*/, 1];
|
|
716
|
-
case 4: return [2 /*return*/, couponCategories];
|
|
717
|
-
}
|
|
718
|
-
});
|
|
719
|
-
});
|
|
720
|
-
};
|
|
721
677
|
return CouponService;
|
|
722
678
|
}());
|
|
723
679
|
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: 'SubscriptionRepository' }, { token: 'CategoryRepository' }], target: i0__namespace.ɵɵFactoryTarget.Injectable });
|
|
@@ -776,12 +732,7 @@
|
|
|
776
732
|
};
|
|
777
733
|
CheckoutService.prototype.calcDiscount = function (coupon) {
|
|
778
734
|
var _this = this;
|
|
779
|
-
return this.getCheckout().pipe(operators.concatMap(function (checkout) { return
|
|
780
|
-
switch (_b.label) {
|
|
781
|
-
case 0: return [4 /*yield*/, this.couponService.calcDiscountShopping(coupon, checkout)];
|
|
782
|
-
case 1: return [2 /*return*/, _b.sent()];
|
|
783
|
-
}
|
|
784
|
-
}); }); }));
|
|
735
|
+
return this.getCheckout().pipe(operators.concatMap(function (checkout) { return _this.couponService.calcDiscountShopping(coupon, checkout).pipe(); }));
|
|
785
736
|
};
|
|
786
737
|
CheckoutService.prototype.checkCoupon = function (nickname, checkoutType) {
|
|
787
738
|
var _this = this;
|