@infrab4a/connect-angular 4.0.0-beta.21 → 4.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.
- package/esm2020/services/cart.service.mjs +21 -6
- package/esm2020/services/coupon.service.mjs +2 -1
- package/fesm2015/infrab4a-connect-angular.mjs +15 -8
- package/fesm2015/infrab4a-connect-angular.mjs.map +1 -1
- package/fesm2020/infrab4a-connect-angular.mjs +20 -4
- package/fesm2020/infrab4a-connect-angular.mjs.map +1 -1
- package/package.json +2 -2
- package/services/cart.service.d.ts +1 -0
|
@@ -5,7 +5,7 @@ import { getIdToken, authState, Auth, provideAuth, getAuth } from '@angular/fire
|
|
|
5
5
|
import { combineLatest, from, of, throwError, Subject, iif, forkJoin } from 'rxjs';
|
|
6
6
|
import { map, mergeMap, catchError, concatMap, tap } from 'rxjs/operators';
|
|
7
7
|
import * as i3 from '@infrab4a/connect';
|
|
8
|
-
import { Where, Shops, CheckoutTypes, CouponTypes, Exclusivities, isNil, NotFoundError, Checkout, pick, LineItem, CheckoutSubscription, Category, Product, RequiredArgumentError, add, Order, Authentication, AuthenticationFirebaseAuthService, Register, RegisterFirebaseAuthService, SignOut, RecoveryPassword, ProductsIndex, AxiosAdapter, UserBeautyProfileFirestoreRepository, Buy2WinFirestoreRepository, CategoryFirestoreRepository, CheckoutFirestoreRepository, CheckoutSubscriptionFirestoreRepository, CouponFirestoreRepository, CampaignHashtagFirestoreRepository, CampaignDashboardFirestoreRepository, SubscriptionEditionFirestoreRepository, HomeFirestoreRepository, LeadFirestoreRepository, LegacyOrderFirestoreRepository, ShopMenuFirestoreRepository, OrderFirestoreRepository, PaymentFirestoreRepository, ProductFirestoreRepository, ShopSettingsFirestoreRepository, SubscriptionPaymentFirestoreRepository, SubscriptionPlanFirestoreRepository, SubscriptionProductFirestoreRepository, SubscriptionFirestoreRepository, UserFirestoreRepository, UserAddressFirestoreRepository, UserPaymentMethodFirestoreRepository, ProductVariantFirestoreRepository, CategoryHasuraGraphQLRepository, ProductHasuraGraphQLRepository, CategoryFilterHasuraGraphQLRepository, VariantHasuraGraphQLRepository, FilterOptionHasuraGraphQLRepository, FilterHasuraGraphQLRepository } from '@infrab4a/connect';
|
|
8
|
+
import { Where, Shops, CheckoutTypes, CouponTypes, Exclusivities, isNil, NotFoundError, Checkout, pick, LineItem, RoundProductPricesHelper, CheckoutSubscription, Category, Product, RequiredArgumentError, add, Order, Authentication, AuthenticationFirebaseAuthService, Register, RegisterFirebaseAuthService, SignOut, RecoveryPassword, ProductsIndex, AxiosAdapter, UserBeautyProfileFirestoreRepository, Buy2WinFirestoreRepository, CategoryFirestoreRepository, CheckoutFirestoreRepository, CheckoutSubscriptionFirestoreRepository, CouponFirestoreRepository, CampaignHashtagFirestoreRepository, CampaignDashboardFirestoreRepository, SubscriptionEditionFirestoreRepository, HomeFirestoreRepository, LeadFirestoreRepository, LegacyOrderFirestoreRepository, ShopMenuFirestoreRepository, OrderFirestoreRepository, PaymentFirestoreRepository, ProductFirestoreRepository, ShopSettingsFirestoreRepository, SubscriptionPaymentFirestoreRepository, SubscriptionPlanFirestoreRepository, SubscriptionProductFirestoreRepository, SubscriptionFirestoreRepository, UserFirestoreRepository, UserAddressFirestoreRepository, UserPaymentMethodFirestoreRepository, ProductVariantFirestoreRepository, CategoryHasuraGraphQLRepository, ProductHasuraGraphQLRepository, CategoryFilterHasuraGraphQLRepository, VariantHasuraGraphQLRepository, FilterOptionHasuraGraphQLRepository, FilterHasuraGraphQLRepository } from '@infrab4a/connect';
|
|
9
9
|
import cookie from 'js-cookie';
|
|
10
10
|
import { CustomError } from 'ts-custom-error';
|
|
11
11
|
import * as i1$1 from '@angular/fire/firestore';
|
|
@@ -134,6 +134,7 @@ class CouponService {
|
|
|
134
134
|
filters: {
|
|
135
135
|
coupon: { id: coupon.id },
|
|
136
136
|
payment: { status: 'paid' },
|
|
137
|
+
...(coupon.influencerEmail ? { user: { email: userEmail } } : {}),
|
|
137
138
|
},
|
|
138
139
|
});
|
|
139
140
|
// orders que usuario ja fez com o cupom
|
|
@@ -378,6 +379,7 @@ class CartService {
|
|
|
378
379
|
shop: checkout.shop || this.defaultShop,
|
|
379
380
|
isSubscriber: checkout.user?.isSubscriber,
|
|
380
381
|
});
|
|
382
|
+
RoundProductPricesHelper.roundProductPrices(item);
|
|
381
383
|
return {
|
|
382
384
|
checkout,
|
|
383
385
|
lineItem: LineItem.toInstance({
|
|
@@ -388,7 +390,7 @@ class CartService {
|
|
|
388
390
|
slug: slug ?? product.slug,
|
|
389
391
|
sku: sku ?? product.sku,
|
|
390
392
|
stock,
|
|
391
|
-
price,
|
|
393
|
+
price: this.roundPrice(price),
|
|
392
394
|
image,
|
|
393
395
|
weight: weight ?? product.weight,
|
|
394
396
|
quantity: (item.quantity || 0) + (quantity || 0),
|
|
@@ -404,7 +406,9 @@ class CartService {
|
|
|
404
406
|
const info = product.price;
|
|
405
407
|
if (product.isGift)
|
|
406
408
|
return 0;
|
|
407
|
-
return isSubscriber && info.subscriberPrice > 0
|
|
409
|
+
return isSubscriber && info.subscriberPrice > 0
|
|
410
|
+
? Number(info.subscriberPrice.toFixed(2))
|
|
411
|
+
: Number(info.price.toFixed(2));
|
|
408
412
|
};
|
|
409
413
|
this.checkMaxStock = (item, quantity) => {
|
|
410
414
|
const maxStock = item.stock?.quantity || 0;
|
|
@@ -460,6 +464,15 @@ class CartService {
|
|
|
460
464
|
buildCartFromCheckout(checkoutData) {
|
|
461
465
|
return this.checkoutService.getCheckout(checkoutData).pipe(map((checkout) => checkout.lineItems), concatMap((lineItems) => of(this.generateCartObject(lineItems))));
|
|
462
466
|
}
|
|
467
|
+
roundPrice(productPrice) {
|
|
468
|
+
const { price, fullPrice, subscriberPrice } = productPrice;
|
|
469
|
+
return {
|
|
470
|
+
...productPrice,
|
|
471
|
+
price: Number(price.toFixed(2)),
|
|
472
|
+
fullPrice: Number(fullPrice.toFixed(2)),
|
|
473
|
+
...(subscriberPrice && { subscriberPrice: Number(subscriberPrice.toFixed(2)) }),
|
|
474
|
+
};
|
|
475
|
+
}
|
|
463
476
|
async getProductData(productId) {
|
|
464
477
|
let product;
|
|
465
478
|
let variant;
|
|
@@ -469,7 +482,10 @@ class CartService {
|
|
|
469
482
|
catch (error) {
|
|
470
483
|
if (!(error instanceof NotFoundError))
|
|
471
484
|
throw error;
|
|
472
|
-
|
|
485
|
+
const { data: variants } = await this.variantRepository.find({ filters: { id: productId } });
|
|
486
|
+
variant = variants.shift();
|
|
487
|
+
if (!variant)
|
|
488
|
+
throw error;
|
|
473
489
|
product = await this.productRepository.get({ id: variant.productId });
|
|
474
490
|
}
|
|
475
491
|
return {
|