@infrab4a/connect-angular 1.0.0-beta.21 → 1.0.0-beta.23
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.
|
@@ -575,7 +575,6 @@
|
|
|
575
575
|
this.cartSubject = new rxjs.Subject();
|
|
576
576
|
this.updateLineItemInCart = function (lineItem, quantity, checkout) { return (i2.isNil(checkout) ? _this.checkoutService.getCheckout() : rxjs.of(checkout)).pipe(operators.concatMap(function (checkoutLoaded) {
|
|
577
577
|
var _a;
|
|
578
|
-
console.log('updateLineItemInCart1', checkoutLoaded);
|
|
579
578
|
var items = [];
|
|
580
579
|
var index = (_a = checkoutLoaded.lineItems) === null || _a === void 0 ? void 0 : _a.map(function (checkoutItem) { return checkoutItem.sku; }).indexOf(lineItem.sku);
|
|
581
580
|
if (index > -1) {
|
|
@@ -596,19 +595,17 @@
|
|
|
596
595
|
});
|
|
597
596
|
return cart;
|
|
598
597
|
};
|
|
599
|
-
this.buildLineItem = function (
|
|
600
|
-
var checkout =
|
|
598
|
+
this.buildLineItem = function (_g) {
|
|
599
|
+
var checkout = _g.checkout, item = _g.item, quantity = _g.quantity;
|
|
601
600
|
return __awaiter(_this, void 0, void 0, function () {
|
|
602
|
-
var _a, _b, _c, _d, _e, _f,
|
|
603
|
-
return __generator(this, function (
|
|
604
|
-
switch (
|
|
601
|
+
var _a, _b, _c, _d, _e, _f, product, image, id, name, EAN, brand, slug, stock, price, weight, categories, sku, isGift, pricePaid;
|
|
602
|
+
return __generator(this, function (_g) {
|
|
603
|
+
switch (_g.label) {
|
|
605
604
|
case 0: return [4 /*yield*/, this.productRepository
|
|
606
605
|
.find({ filters: { id: { operator: i2.Where.EQUALS, value: item.id } } })
|
|
607
606
|
.then((function (product) { return product.data.shift(); }))];
|
|
608
607
|
case 1:
|
|
609
|
-
product =
|
|
610
|
-
console.log('productRepository by id', product);
|
|
611
|
-
console.log('buildLineItem', checkout, item, quantity);
|
|
608
|
+
product = _g.sent();
|
|
612
609
|
item.quantity = (item === null || item === void 0 ? void 0 : item.quantity) || ((_b = (_a = checkout === null || checkout === void 0 ? void 0 : checkout.lineItems) === null || _a === void 0 ? void 0 : _a.find(function (lineItem) { return lineItem.sku === item.sku; })) === null || _b === void 0 ? void 0 : _b.quantity) || 0;
|
|
613
610
|
if (this.checkMaxStock(item, quantity || 0))
|
|
614
611
|
throw new Error('Desculpe! Temos apenas ' + ((_c = item.stock) === null || _c === void 0 ? void 0 : _c.quantity) + ' em estoque.');
|
|
@@ -620,29 +617,12 @@
|
|
|
620
617
|
shop: checkout.shop || this.defaultShop,
|
|
621
618
|
isSubscriber: (_e = checkout.user) === null || _e === void 0 ? void 0 : _e.isSubscriber,
|
|
622
619
|
});
|
|
623
|
-
console.log('LineItem.toInstance', JSON.stringify({
|
|
624
|
-
id: id,
|
|
625
|
-
name: name,
|
|
626
|
-
EAN: EAN,
|
|
627
|
-
brand: product.brand,
|
|
628
|
-
slug: slug,
|
|
629
|
-
sku: sku,
|
|
630
|
-
stock: stock,
|
|
631
|
-
price: price,
|
|
632
|
-
image: image,
|
|
633
|
-
weight: weight !== null && weight !== void 0 ? weight : product.weight,
|
|
634
|
-
quantity: (item.quantity || 0) + (quantity || 0),
|
|
635
|
-
pricePaid: pricePaid,
|
|
636
|
-
categories: (_f = product.categories) !== null && _f !== void 0 ? _f : [],
|
|
637
|
-
isGift: isGift,
|
|
638
|
-
costPrice: item === null || item === void 0 ? void 0 : item.costPrice
|
|
639
|
-
}));
|
|
640
620
|
return [2 /*return*/, {
|
|
641
621
|
checkout: checkout,
|
|
642
622
|
lineItem: i2.LineItem.toInstance({
|
|
643
623
|
id: id,
|
|
644
624
|
name: name,
|
|
645
|
-
EAN: EAN,
|
|
625
|
+
EAN: EAN !== null && EAN !== void 0 ? EAN : product.EAN,
|
|
646
626
|
brand: product.brand,
|
|
647
627
|
slug: slug,
|
|
648
628
|
sku: sku,
|
|
@@ -652,8 +632,8 @@
|
|
|
652
632
|
weight: weight !== null && weight !== void 0 ? weight : product.weight,
|
|
653
633
|
quantity: (item.quantity || 0) + (quantity || 0),
|
|
654
634
|
pricePaid: pricePaid,
|
|
655
|
-
categories: (
|
|
656
|
-
isGift: isGift,
|
|
635
|
+
categories: (_f = product.categories) !== null && _f !== void 0 ? _f : [],
|
|
636
|
+
isGift: isGift !== null && isGift !== void 0 ? isGift : null,
|
|
657
637
|
costPrice: item === null || item === void 0 ? void 0 : item.costPrice,
|
|
658
638
|
})
|
|
659
639
|
}];
|
|
@@ -661,8 +641,8 @@
|
|
|
661
641
|
});
|
|
662
642
|
});
|
|
663
643
|
};
|
|
664
|
-
this.getProductPrice = function (
|
|
665
|
-
var product =
|
|
644
|
+
this.getProductPrice = function (_g) {
|
|
645
|
+
var product = _g.product, shop = _g.shop, isSubscriber = _g.isSubscriber;
|
|
666
646
|
var info = product.getInfoByShop(shop);
|
|
667
647
|
if (product.isGift)
|
|
668
648
|
return 0;
|
|
@@ -679,14 +659,10 @@
|
|
|
679
659
|
var _this = this;
|
|
680
660
|
if (quantity === void 0) { quantity = 1; }
|
|
681
661
|
return rxjs.from(this.checkoutService.getCheckout())
|
|
682
|
-
.pipe(operators.concatMap(function (checkout) { return _this.buildLineItem({ checkout: checkout, item: item, quantity: quantity || 1 }); }), operators.mergeMap(function (
|
|
683
|
-
var checkout =
|
|
662
|
+
.pipe(operators.concatMap(function (checkout) { return _this.buildLineItem({ checkout: checkout, item: item, quantity: quantity || 1 }); }), operators.mergeMap(function (_g) {
|
|
663
|
+
var checkout = _g.checkout, lineItem = _g.lineItem;
|
|
684
664
|
return _this.updateLineItemInCart(lineItem, quantity || 1, checkout);
|
|
685
665
|
}), operators.tap(function (cart) { return _this.cartSubject.next(cart); }));
|
|
686
|
-
// .pipe(
|
|
687
|
-
// concatMap(({ checkout, lineItem }) => this.updateLineItemInCart(lineItem, quantity || 1, checkout)),
|
|
688
|
-
// tap((cart) => this.cartSubject.next(cart)),
|
|
689
|
-
// )
|
|
690
666
|
// return this.checkoutService.getCheckout().pipe(
|
|
691
667
|
// map( async(checkout) => ({
|
|
692
668
|
// checkout,
|
|
@@ -745,10 +721,10 @@
|
|
|
745
721
|
var _this = this;
|
|
746
722
|
return this.checkoutService.getCheckout().pipe(operators.concatMap(function (checkout) { return _this.checkoutService.updateCheckoutUser(i2.Checkout.toInstance(Object.assign(Object.assign({}, checkout.toPlain()), { user: user }))); }), operators.concatMap(function (checkout) {
|
|
747
723
|
var _a;
|
|
748
|
-
return _this.checkoutService.updateCheckoutLineItems(i2.Checkout.toInstance(Object.assign(Object.assign({}, checkout.toPlain()), { lineItems: ((_a = checkout.lineItems) === null || _a === void 0 ? void 0 : _a.map(function (item) { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (
|
|
749
|
-
switch (
|
|
724
|
+
return _this.checkoutService.updateCheckoutLineItems(i2.Checkout.toInstance(Object.assign(Object.assign({}, checkout.toPlain()), { lineItems: ((_a = checkout.lineItems) === null || _a === void 0 ? void 0 : _a.map(function (item) { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_g) {
|
|
725
|
+
switch (_g.label) {
|
|
750
726
|
case 0: return [4 /*yield*/, this.buildLineItem({ checkout: checkout, item: item })];
|
|
751
|
-
case 1: return [2 /*return*/,
|
|
727
|
+
case 1: return [2 /*return*/, _g.sent()];
|
|
752
728
|
}
|
|
753
729
|
}); }); })) || [] })));
|
|
754
730
|
}), operators.map(function (checkout) { return _this.generateCartObject(checkout.lineItems); }), operators.tap(function (cart) { return _this.cartSubject.next(cart); }));
|