@infrab4a/connect-angular 1.0.0-beta.18 → 1.0.0-beta.19
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.
|
@@ -573,23 +573,32 @@
|
|
|
573
573
|
this.defaultShop = defaultShop;
|
|
574
574
|
this.productRepository = productRepository;
|
|
575
575
|
this.cartSubject = new rxjs.Subject();
|
|
576
|
-
this.updateLineItemInCart = function (
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
576
|
+
this.updateLineItemInCart = function (li, quantity, checkout) { return __awaiter(_this, void 0, void 0, function () {
|
|
577
|
+
var lineItem;
|
|
578
|
+
var _this = this;
|
|
579
|
+
return __generator(this, function (_h) {
|
|
580
|
+
switch (_h.label) {
|
|
581
|
+
case 0: return [4 /*yield*/, li];
|
|
582
|
+
case 1:
|
|
583
|
+
lineItem = _h.sent();
|
|
584
|
+
return [2 /*return*/, (i2.isNil(checkout) ? this.checkoutService.getCheckout() : rxjs.of(checkout)).pipe(operators.concatMap(function (checkoutLoaded) {
|
|
585
|
+
var _a;
|
|
586
|
+
console.log('updateLineItemInCart1', checkoutLoaded);
|
|
587
|
+
var items = [];
|
|
588
|
+
var index = (_a = checkoutLoaded.lineItems) === null || _a === void 0 ? void 0 : _a.map(function (checkoutItem) { return checkoutItem.sku; }).indexOf(lineItem.sku);
|
|
589
|
+
if (index > -1) {
|
|
590
|
+
checkoutLoaded.lineItems[index].quantity += quantity;
|
|
591
|
+
checkoutLoaded.lineItems[index].pricePaid = lineItem.pricePaid;
|
|
592
|
+
}
|
|
593
|
+
else
|
|
594
|
+
checkoutLoaded.lineItems = items.concat(checkoutLoaded.lineItems ? checkoutLoaded.lineItems.concat([lineItem]) : [lineItem]);
|
|
595
|
+
return _this.checkoutService
|
|
596
|
+
.updateCheckoutLineItems(checkoutLoaded)
|
|
597
|
+
.pipe(operators.map(function (updatedCheckout) { return _this.generateCartObject(updatedCheckout.lineItems); }));
|
|
598
|
+
}))];
|
|
585
599
|
}
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
return _this.checkoutService
|
|
589
|
-
.updateCheckoutLineItems(checkoutLoaded)
|
|
590
|
-
.pipe(operators.map(function (updatedCheckout) { return _this.generateCartObject(updatedCheckout.lineItems); }));
|
|
591
|
-
}));
|
|
592
|
-
};
|
|
600
|
+
});
|
|
601
|
+
}); };
|
|
593
602
|
this.generateCartObject = function (items) {
|
|
594
603
|
var cart = {};
|
|
595
604
|
items === null || items === void 0 ? void 0 : items.forEach(function (item) {
|
|
@@ -682,14 +691,7 @@
|
|
|
682
691
|
lineItem: _this.buildLineItem({ checkout: checkout, item: item, quantity: quantity || 1 }),
|
|
683
692
|
}); }), operators.concatMap(function (_h) {
|
|
684
693
|
var checkout = _h.checkout, lineItem = _h.lineItem;
|
|
685
|
-
return
|
|
686
|
-
switch (_j.label) {
|
|
687
|
-
case 0:
|
|
688
|
-
_h = this.updateLineItemInCart;
|
|
689
|
-
return [4 /*yield*/, lineItem];
|
|
690
|
-
case 1: return [2 /*return*/, _h.apply(this, [_j.sent(), quantity || 1, checkout])];
|
|
691
|
-
}
|
|
692
|
-
}); });
|
|
694
|
+
return _this.updateLineItemInCart(lineItem, quantity || 1, checkout);
|
|
693
695
|
}), operators.tap(function (cart) { return _this.cartSubject.next(cart); }));
|
|
694
696
|
};
|
|
695
697
|
CartService.prototype.decreaseItem = function (item) {
|