@infrab4a/connect-angular 3.2.2-beta.5 → 3.2.2
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 +35 -199
- package/bundles/infrab4a-connect-angular.umd.js.map +1 -1
- package/esm2015/services/cart.service.js +12 -113
- package/esm2015/services/home-shop.service.js +25 -22
- package/fesm2015/infrab4a-connect-angular.js +32 -130
- package/fesm2015/infrab4a-connect-angular.js.map +1 -1
- package/package.json +2 -2
- package/services/cart.service.d.ts +2 -7
|
@@ -391,12 +391,11 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImpo
|
|
|
391
391
|
}] }]; } });
|
|
392
392
|
|
|
393
393
|
class CartService {
|
|
394
|
-
constructor(authService, checkoutService, defaultShop, productRepository
|
|
394
|
+
constructor(authService, checkoutService, defaultShop, productRepository) {
|
|
395
395
|
this.authService = authService;
|
|
396
396
|
this.checkoutService = checkoutService;
|
|
397
397
|
this.defaultShop = defaultShop;
|
|
398
398
|
this.productRepository = productRepository;
|
|
399
|
-
this.buy2WinRepository = buy2WinRepository;
|
|
400
399
|
this.cartSubject = new Subject();
|
|
401
400
|
this.updateLineItemInCart = (lineItem, quantity, checkout) => (isNil(checkout) ? this.checkoutService.getCheckout() : of(checkout)).pipe(concatMap((checkoutLoaded) => {
|
|
402
401
|
var _a;
|
|
@@ -408,10 +407,10 @@ class CartService {
|
|
|
408
407
|
}
|
|
409
408
|
else
|
|
410
409
|
checkoutLoaded.lineItems = items.concat(checkoutLoaded.lineItems ? checkoutLoaded.lineItems.concat([lineItem]) : [lineItem]);
|
|
411
|
-
return
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
410
|
+
return this.checkoutService
|
|
411
|
+
.updateCheckoutLineItems(checkoutLoaded)
|
|
412
|
+
.pipe(map((updatedCheckout) => this.generateCartObject(updatedCheckout.lineItems)));
|
|
413
|
+
}));
|
|
415
414
|
this.generateCartObject = (items) => {
|
|
416
415
|
const cart = {};
|
|
417
416
|
items === null || items === void 0 ? void 0 : items.forEach((item) => {
|
|
@@ -470,7 +469,7 @@ class CartService {
|
|
|
470
469
|
};
|
|
471
470
|
}
|
|
472
471
|
addItem(item, quantity = 1) {
|
|
473
|
-
return from(this.checkoutService.getCheckout()).pipe(concatMap((checkout) => __awaiter(this, void 0, void 0, function* () { return yield this.buildLineItem({ checkout, item, quantity: quantity || 1 }); })),
|
|
472
|
+
return from(this.checkoutService.getCheckout()).pipe(concatMap((checkout) => __awaiter(this, void 0, void 0, function* () { return yield this.buildLineItem({ checkout, item, quantity: quantity || 1 }); })), mergeMap(({ checkout, lineItem }) => this.updateLineItemInCart(lineItem, quantity || 1, checkout)), tap((cart) => this.cartSubject.next(cart)));
|
|
474
473
|
}
|
|
475
474
|
decreaseItem(item) {
|
|
476
475
|
return this.checkoutService.getCheckout().pipe(map((checkout) => {
|
|
@@ -502,12 +501,8 @@ class CartService {
|
|
|
502
501
|
updateUserCart(user) {
|
|
503
502
|
return this.checkoutService.getCheckout().pipe(concatMap((checkout) => this.checkoutService.updateCheckoutUser(Checkout.toInstance(Object.assign(Object.assign({}, checkout.toPlain()), { user })))), concatMap((checkout) => __awaiter(this, void 0, void 0, function* () {
|
|
504
503
|
var _a, _b;
|
|
505
|
-
return this.checkoutService
|
|
506
|
-
|
|
507
|
-
? yield Promise.all((_b = checkout.lineItems) === null || _b === void 0 ? void 0 : _b.map((item) => __awaiter(this, void 0, void 0, function* () { return (yield this.buildLineItem({ checkout, item })).lineItem; })))
|
|
508
|
-
: [] })))
|
|
509
|
-
.toPromise();
|
|
510
|
-
})), map((checkout) => this.generateCartObject(checkout.lineItems)), tap((cart) => this.cartSubject.next(cart)));
|
|
504
|
+
return this.checkoutService.updateCheckoutLineItems(Checkout.toInstance(Object.assign(Object.assign({}, checkout.toPlain()), { lineItems: ((_a = checkout.lineItems) === null || _a === void 0 ? void 0 : _a.length) ? yield Promise.all((_b = checkout.lineItems) === null || _b === void 0 ? void 0 : _b.map((item) => __awaiter(this, void 0, void 0, function* () { return (yield this.buildLineItem({ checkout, item })).lineItem; }))) : [] }))).toPromise();
|
|
505
|
+
})), map(checkout => this.generateCartObject(checkout.lineItems)), tap((cart) => this.cartSubject.next(cart)));
|
|
511
506
|
}
|
|
512
507
|
clearCart() {
|
|
513
508
|
return this.checkoutService.getCheckout().pipe(map((checkout) => {
|
|
@@ -518,101 +513,8 @@ class CartService {
|
|
|
518
513
|
buildCartFromCheckout(checkoutData) {
|
|
519
514
|
return this.checkoutService.getCheckout(checkoutData).pipe(map((checkout) => checkout.lineItems), concatMap((lineItems) => of(this.generateCartObject(lineItems))));
|
|
520
515
|
}
|
|
521
|
-
getBu2Win(checkout) {
|
|
522
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
523
|
-
const data = {
|
|
524
|
-
cartTotal: checkout.totalPrice,
|
|
525
|
-
categories: checkout.lineItems.map((item) => item.categories).reduce((acc, it) => [...acc, ...it], []),
|
|
526
|
-
shop: this.defaultShop,
|
|
527
|
-
};
|
|
528
|
-
let campaigns = yield this.buy2WinRepository
|
|
529
|
-
.find({
|
|
530
|
-
filters: { active: true, shop: this.defaultShop },
|
|
531
|
-
})
|
|
532
|
-
.then((data) => data.data);
|
|
533
|
-
const elegibleCampaigns = [];
|
|
534
|
-
campaigns.forEach((campaign) => {
|
|
535
|
-
if (campaign.cartValue > 0 && campaign.categories.length > 0) {
|
|
536
|
-
if (campaign.cartValue <= data.cartTotal &&
|
|
537
|
-
campaign.categories.filter((category) => { var _a; return (_a = data.categories) === null || _a === void 0 ? void 0 : _a.includes(category.id); }).length > 0)
|
|
538
|
-
elegibleCampaigns.push(campaign);
|
|
539
|
-
}
|
|
540
|
-
else if (campaign.cartValue > 0) {
|
|
541
|
-
if (campaign.cartValue <= data.cartTotal)
|
|
542
|
-
elegibleCampaigns.push(campaign);
|
|
543
|
-
}
|
|
544
|
-
else if (campaign.categories.length > 0) {
|
|
545
|
-
if (campaign.categories.filter((category) => { var _a; return (_a = data.categories) === null || _a === void 0 ? void 0 : _a.includes(category.id); }).length > 0)
|
|
546
|
-
elegibleCampaigns.push(campaign);
|
|
547
|
-
}
|
|
548
|
-
});
|
|
549
|
-
if (elegibleCampaigns.length < 1)
|
|
550
|
-
return;
|
|
551
|
-
const products = [];
|
|
552
|
-
for (const campaign of elegibleCampaigns) {
|
|
553
|
-
let elegibleProducts = [];
|
|
554
|
-
for (const product of campaign.products) {
|
|
555
|
-
const productData = yield this.productRepository.get({ sku: product });
|
|
556
|
-
if (!productData)
|
|
557
|
-
continue;
|
|
558
|
-
elegibleProducts.push(productData);
|
|
559
|
-
}
|
|
560
|
-
products.push(elegibleProducts);
|
|
561
|
-
elegibleProducts = [];
|
|
562
|
-
}
|
|
563
|
-
if (products.length < 1)
|
|
564
|
-
return;
|
|
565
|
-
const productArray = products.reduce((acc, curr) => acc.reduce((aAcc, aCurr) => aAcc + aCurr.price.price, 0) >
|
|
566
|
-
curr.reduce((cAcc, cCurr) => cAcc + cCurr.price.price, 0)
|
|
567
|
-
? acc
|
|
568
|
-
: curr);
|
|
569
|
-
productArray.map((p) => {
|
|
570
|
-
let id = '' + p.id;
|
|
571
|
-
delete p.id;
|
|
572
|
-
return Object.assign({ id }, p);
|
|
573
|
-
});
|
|
574
|
-
return productArray;
|
|
575
|
-
});
|
|
576
|
-
}
|
|
577
|
-
checkBuy2Win(checkout) {
|
|
578
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
579
|
-
const notGiftItems = checkout.lineItems.filter((item) => !item.isGift);
|
|
580
|
-
if (notGiftItems.length) {
|
|
581
|
-
const res = yield this.getBu2Win(checkout);
|
|
582
|
-
const giftItems = res.length ? this.productsToLineItems(res) : [];
|
|
583
|
-
checkout.lineItems = notGiftItems.concat(giftItems);
|
|
584
|
-
}
|
|
585
|
-
else {
|
|
586
|
-
this.clearCart();
|
|
587
|
-
}
|
|
588
|
-
return checkout;
|
|
589
|
-
});
|
|
590
|
-
}
|
|
591
|
-
productsToLineItems(items) {
|
|
592
|
-
return items.map((item) => {
|
|
593
|
-
var _a;
|
|
594
|
-
const { brand, categories, id, name, price, sku, slug, stock, weight, EAN } = item;
|
|
595
|
-
const image = ((_a = item === null || item === void 0 ? void 0 : item.miniatures) === null || _a === void 0 ? void 0 : _a.length) ? item.miniatures[0] : item.images[0];
|
|
596
|
-
return LineItem.toInstance({
|
|
597
|
-
brand,
|
|
598
|
-
categories,
|
|
599
|
-
id,
|
|
600
|
-
name,
|
|
601
|
-
price,
|
|
602
|
-
sku,
|
|
603
|
-
slug,
|
|
604
|
-
stock,
|
|
605
|
-
weight,
|
|
606
|
-
EAN,
|
|
607
|
-
image,
|
|
608
|
-
pricePaid: 0,
|
|
609
|
-
quantity: 1,
|
|
610
|
-
isGift: true,
|
|
611
|
-
});
|
|
612
|
-
});
|
|
613
|
-
}
|
|
614
516
|
}
|
|
615
|
-
CartService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: CartService, deps: [{ token: AuthService }, { token: CheckoutService }, { token: DEFAULT_SHOP }, { token: 'ProductRepository' }
|
|
517
|
+
CartService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: CartService, deps: [{ token: AuthService }, { token: CheckoutService }, { token: DEFAULT_SHOP }, { token: 'ProductRepository' }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
616
518
|
CartService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: CartService });
|
|
617
519
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImport: i0, type: CartService, decorators: [{
|
|
618
520
|
type: Injectable
|
|
@@ -622,9 +524,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.12", ngImpo
|
|
|
622
524
|
}] }, { type: undefined, decorators: [{
|
|
623
525
|
type: Inject,
|
|
624
526
|
args: ['ProductRepository']
|
|
625
|
-
}] }, { type: undefined, decorators: [{
|
|
626
|
-
type: Inject,
|
|
627
|
-
args: ['Buy2WinRepository']
|
|
628
527
|
}] }]; } });
|
|
629
528
|
|
|
630
529
|
class CheckoutSubscriptionService {
|
|
@@ -699,25 +598,28 @@ class HomeShopService {
|
|
|
699
598
|
this.homeRepository = homeRepository;
|
|
700
599
|
this.productRepository = productRepository;
|
|
701
600
|
this.defaultShop = defaultShop;
|
|
702
|
-
this.buildCategoryGroupWithRequiredData = (group) =>
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
'id',
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
601
|
+
this.buildCategoryGroupWithRequiredData = (group) => {
|
|
602
|
+
var _a, _b;
|
|
603
|
+
return ({
|
|
604
|
+
category: Category.toInstance(pick(((_a = group === null || group === void 0 ? void 0 : group.category) === null || _a === void 0 ? void 0 : _a.toPlain()) || {}, ['id', 'name', 'slug', 'conditions'])),
|
|
605
|
+
products: ((_b = group === null || group === void 0 ? void 0 : group.products) === null || _b === void 0 ? void 0 : _b.map((product) => Product.toInstance(pick((product === null || product === void 0 ? void 0 : product.toPlain()) || {}, [
|
|
606
|
+
'id',
|
|
607
|
+
'price',
|
|
608
|
+
'reviews',
|
|
609
|
+
'hasVariants',
|
|
610
|
+
'slug',
|
|
611
|
+
'sku',
|
|
612
|
+
'stock',
|
|
613
|
+
'costPrice',
|
|
614
|
+
'images',
|
|
615
|
+
'miniatures',
|
|
616
|
+
'name',
|
|
617
|
+
'weight',
|
|
618
|
+
'rate',
|
|
619
|
+
'type',
|
|
620
|
+
])))) || [],
|
|
621
|
+
});
|
|
622
|
+
};
|
|
721
623
|
}
|
|
722
624
|
get homeId() {
|
|
723
625
|
if (this.defaultShop === Shops.GLAMSHOP)
|
|
@@ -748,7 +650,7 @@ class HomeShopService {
|
|
|
748
650
|
}));
|
|
749
651
|
}
|
|
750
652
|
getMinValueForFreeShipping() {
|
|
751
|
-
return this.getHomeConfiguration().pipe(map(home => home.minValueForFreeShipping));
|
|
653
|
+
return this.getHomeConfiguration().pipe(map((home) => home.minValueForFreeShipping));
|
|
752
654
|
}
|
|
753
655
|
getDiscoverProducts() {
|
|
754
656
|
return this.getHomeConfiguration().pipe(concatMap((home) => from(this.categoryRepository.getCategoriesForHome(home.discoverCategories)).pipe(map((groups) => groups.map(this.buildCategoryGroupWithRequiredData)))));
|