@infrab4a/connect-angular 4.17.3-beta.2 → 4.17.3-beta.20
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/angular-connect.module.mjs +2 -4
- package/esm2020/services/cart.service.mjs +47 -225
- package/esm2020/services/checkout.service.mjs +70 -15
- package/esm2020/services/coupon.service.mjs +46 -58
- package/esm2020/services/index.mjs +1 -2
- package/fesm2015/infrab4a-connect-angular.mjs +527 -751
- package/fesm2015/infrab4a-connect-angular.mjs.map +1 -1
- package/fesm2020/infrab4a-connect-angular.mjs +389 -612
- package/fesm2020/infrab4a-connect-angular.mjs.map +1 -1
- package/package.json +2 -2
- package/services/cart.service.d.ts +2 -19
- package/services/checkout.service.d.ts +16 -9
- package/services/coupon.service.d.ts +1 -7
- package/services/index.d.ts +0 -1
- package/esm2020/services/shipping.service.mjs +0 -96
- package/esm2020/services/types/shipping-methods.type.mjs +0 -2
- package/services/shipping.service.d.ts +0 -19
- package/services/types/shipping-methods.type.d.ts +0 -12
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
import * as i0 from '@angular/core';
|
|
2
2
|
import { NgModule, InjectionToken, PLATFORM_ID, Injectable, Inject } from '@angular/core';
|
|
3
|
-
import * as i1$
|
|
3
|
+
import * as i1$4 from '@angular/fire/app';
|
|
4
4
|
import { FirebaseApp, provideFirebaseApp, getApp, initializeApp } from '@angular/fire/app';
|
|
5
5
|
import * as i2 from '@angular/fire/storage';
|
|
6
6
|
import { Storage, provideStorage, getStorage } from '@angular/fire/storage';
|
|
7
|
-
import * as i1$
|
|
8
|
-
import { ProductsIndex, AxiosAdapter, Authentication, AuthenticationFirebaseAuthService, Register, RegisterFirebaseAuthService, SignOut, RecoveryPassword, ConnectFirestoreService, UserBeautyProfileFirestoreRepository, Buy2WinFirestoreRepository, CategoryFirestoreRepository, CheckoutFirestoreRepository, CheckoutSubscriptionFirestoreRepository, CouponFirestoreRepository, CampaignHashtagFirestoreRepository, CampaignDashboardFirestoreRepository, SubscriptionEditionFirestoreRepository, HomeFirestoreRepository, LeadFirestoreRepository, LegacyOrderFirestoreRepository, ShopMenuFirestoreRepository, OrderFirestoreRepository, PaymentFirestoreRepository, ProductFirestoreRepository, ShopSettingsFirestoreRepository, SubscriptionPaymentFirestoreRepository, SubscriptionPlanFirestoreRepository, SubscriptionProductFirestoreRepository, SubscriptionFirestoreRepository, UserFirestoreRepository, UserAddressFirestoreRepository, UserPaymentMethodFirestoreRepository, SubscriptionMaterializationFirestoreRepository, SubscriptionSummaryFirestoreRepository, ProductVariantFirestoreRepository, OrderBlockedFirestoreRepository, LogFirestoreRepository, SequenceFirestoreRepository, CategoryHasuraGraphQLRepository, ProductHasuraGraphQLRepository, CategoryFilterHasuraGraphQLRepository, ProductReviewsHasuraGraphQLRepository, VariantHasuraGraphQLRepository, ProductStockNotificationHasuraGraphQLRepository, FilterOptionHasuraGraphQLRepository, FilterHasuraGraphQLRepository, CategoryCollectionChildrenHasuraGraphQLRepository, CategoryProductHasuraGraphQLRepository, WishlistHasuraGraphQLRepository, ProductsVertexSearch, VertexAxiosAdapter,
|
|
7
|
+
import * as i1$3 from '@infrab4a/connect';
|
|
8
|
+
import { ProductsIndex, AxiosAdapter, Authentication, AuthenticationFirebaseAuthService, Register, RegisterFirebaseAuthService, SignOut, RecoveryPassword, ConnectFirestoreService, UserBeautyProfileFirestoreRepository, Buy2WinFirestoreRepository, CategoryFirestoreRepository, CheckoutFirestoreRepository, CheckoutSubscriptionFirestoreRepository, CouponFirestoreRepository, CampaignHashtagFirestoreRepository, CampaignDashboardFirestoreRepository, SubscriptionEditionFirestoreRepository, HomeFirestoreRepository, LeadFirestoreRepository, LegacyOrderFirestoreRepository, ShopMenuFirestoreRepository, OrderFirestoreRepository, PaymentFirestoreRepository, ProductFirestoreRepository, ShopSettingsFirestoreRepository, SubscriptionPaymentFirestoreRepository, SubscriptionPlanFirestoreRepository, SubscriptionProductFirestoreRepository, SubscriptionFirestoreRepository, UserFirestoreRepository, UserAddressFirestoreRepository, UserPaymentMethodFirestoreRepository, SubscriptionMaterializationFirestoreRepository, SubscriptionSummaryFirestoreRepository, ProductVariantFirestoreRepository, OrderBlockedFirestoreRepository, LogFirestoreRepository, SequenceFirestoreRepository, CategoryHasuraGraphQLRepository, ProductHasuraGraphQLRepository, CategoryFilterHasuraGraphQLRepository, ProductReviewsHasuraGraphQLRepository, VariantHasuraGraphQLRepository, ProductStockNotificationHasuraGraphQLRepository, FilterOptionHasuraGraphQLRepository, FilterHasuraGraphQLRepository, CategoryCollectionChildrenHasuraGraphQLRepository, CategoryProductHasuraGraphQLRepository, WishlistHasuraGraphQLRepository, ProductsVertexSearch, VertexAxiosAdapter, isNil, NotFoundError, Checkout, pick, LineItem, Where, set, InvalidArgumentError, RoundProductPricesHelper, isEmpty, Shops, Category, PersonTypes, WishlistLogType, Wishlist, CheckoutTypes, CouponTypes, Exclusivities, OrderStatus, CheckoutSubscription, Product, RequiredArgumentError, add, Order, UpdateUserImage, FirebaseFileUploaderService } from '@infrab4a/connect';
|
|
9
9
|
import * as i1 from '@angular/fire/auth';
|
|
10
10
|
import { Auth, provideAuth, getAuth, getIdToken, authState } from '@angular/fire/auth';
|
|
11
11
|
import { isPlatformBrowser, isPlatformServer } from '@angular/common';
|
|
12
12
|
import * as i1$1 from '@angular/fire/firestore';
|
|
13
13
|
import { Firestore, provideFirestore, initializeFirestore, memoryLocalCache, docSnapshots, doc } from '@angular/fire/firestore';
|
|
14
14
|
import cookie from 'js-cookie';
|
|
15
|
-
import { of, from, combineLatest, throwError, Subject,
|
|
15
|
+
import { of, from, combineLatest, throwError, Subject, forkJoin } from 'rxjs';
|
|
16
16
|
import { map, mergeMap, catchError, concatMap, tap } from 'rxjs/operators';
|
|
17
17
|
import { __awaiter, __decorate, __metadata } from 'tslib';
|
|
18
|
-
import * as
|
|
18
|
+
import * as i1$2 from '@angular/common/http';
|
|
19
19
|
import { Type } from 'class-transformer';
|
|
20
20
|
|
|
21
21
|
const ES_CONFIG = 'ES_CONFIG';
|
|
@@ -1084,312 +1084,17 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImpor
|
|
|
1084
1084
|
}] }];
|
|
1085
1085
|
} });
|
|
1086
1086
|
|
|
1087
|
-
class CouponService {
|
|
1088
|
-
constructor(couponRepository, defaultShop, orderRepository, categoryRepository) {
|
|
1089
|
-
this.couponRepository = couponRepository;
|
|
1090
|
-
this.defaultShop = defaultShop;
|
|
1091
|
-
this.orderRepository = orderRepository;
|
|
1092
|
-
this.categoryRepository = categoryRepository;
|
|
1093
|
-
this.emailIsFromCollaborator = (userEmail) => !!(userEmail === null || userEmail === void 0 ? void 0 : userEmail.match(/@b4a.com.br/g));
|
|
1094
|
-
}
|
|
1095
|
-
checkCoupon(nickname, checkoutType, checkout, plan) {
|
|
1096
|
-
return from(this.couponRepository
|
|
1097
|
-
.find({
|
|
1098
|
-
filters: {
|
|
1099
|
-
nickname: { operator: Where.EQUALS, value: nickname },
|
|
1100
|
-
active: { operator: Where.EQUALS, value: true },
|
|
1101
|
-
},
|
|
1102
|
-
})
|
|
1103
|
-
.then((result) => result.data[0])).pipe(concatMap((coupon) => this.couponValidation(coupon, checkoutType)), concatMap((couponValid) => this.couponRulesValidation(couponValid, checkoutType, checkout, plan)), map((couponValidated) => couponValidated));
|
|
1104
|
-
}
|
|
1105
|
-
couponValidation(coupon, checkoutType) {
|
|
1106
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1107
|
-
if (!coupon)
|
|
1108
|
-
throw 'Cupom inválido.';
|
|
1109
|
-
if ((coupon === null || coupon === void 0 ? void 0 : coupon.beginAt) && (coupon === null || coupon === void 0 ? void 0 : coupon.beginAt.getTime()) > new Date().getTime())
|
|
1110
|
-
throw 'Cupom inválido.';
|
|
1111
|
-
if ((coupon === null || coupon === void 0 ? void 0 : coupon.expiresIn) && (coupon === null || coupon === void 0 ? void 0 : coupon.expiresIn.getTime()) < new Date().getTime())
|
|
1112
|
-
throw 'Cupom expirado.';
|
|
1113
|
-
const isInShop = coupon.shopAvailability === Shops.ALL || coupon.shopAvailability === this.defaultShop;
|
|
1114
|
-
if (!isInShop)
|
|
1115
|
-
throw 'Cupom inválido para loja.';
|
|
1116
|
-
const isCheckoutType = coupon.checkoutType === CheckoutTypes.ALL || coupon.checkoutType === checkoutType;
|
|
1117
|
-
if (!isCheckoutType)
|
|
1118
|
-
throw 'Cupom inválido. Erro de checkout.';
|
|
1119
|
-
return coupon;
|
|
1120
|
-
});
|
|
1121
|
-
}
|
|
1122
|
-
couponRulesValidation(coupon, checkoutType, checkout, plan) {
|
|
1123
|
-
var _a;
|
|
1124
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1125
|
-
if (checkoutType == CheckoutTypes.SUBSCRIPTION) {
|
|
1126
|
-
if (coupon.plan && coupon.plan.toUpperCase() !== plan.toUpperCase())
|
|
1127
|
-
throw 'Cupom inválido para sua assinatura.';
|
|
1128
|
-
return coupon;
|
|
1129
|
-
}
|
|
1130
|
-
const validUser = this.coupomUserValidation(coupon, checkout === null || checkout === void 0 ? void 0 : checkout.user);
|
|
1131
|
-
if (!validUser)
|
|
1132
|
-
throw 'Usuário não elegível.';
|
|
1133
|
-
const couponUseLimits = this.getCouponUseLimits(coupon, checkoutType, checkout.user);
|
|
1134
|
-
if (couponUseLimits.firstOrder) {
|
|
1135
|
-
const ordersUser = yield this.getOrdersFromUser(checkout.user.email.toLocaleLowerCase());
|
|
1136
|
-
if (couponUseLimits.firstOrder && ordersUser.length >= 1)
|
|
1137
|
-
throw 'Limite de uso atingido';
|
|
1138
|
-
}
|
|
1139
|
-
if (!couponUseLimits.unlimited || couponUseLimits.limitedPerUser) {
|
|
1140
|
-
const ordersCoupon = yield this.getOrdersWithCoupon(coupon);
|
|
1141
|
-
if (!couponUseLimits.unlimited && couponUseLimits.total && ordersCoupon.length >= couponUseLimits.total)
|
|
1142
|
-
throw 'Limite de uso atingido.';
|
|
1143
|
-
if (couponUseLimits.limitedPerUser) {
|
|
1144
|
-
const ordersWithUser = this.countOrdersWithUser(ordersCoupon, checkout.user.email);
|
|
1145
|
-
if (ordersWithUser > 0)
|
|
1146
|
-
throw 'Limite de uso por usuário atingido.';
|
|
1147
|
-
}
|
|
1148
|
-
}
|
|
1149
|
-
const hasProductCategories = yield this.hasProductCategories(coupon, checkout);
|
|
1150
|
-
if (!hasProductCategories)
|
|
1151
|
-
throw 'Seu carrinho não possui produtos elegíveis para desconto.';
|
|
1152
|
-
const hasMinSubTotal = yield this.hasMinSubTotal(coupon, checkout);
|
|
1153
|
-
if (!hasMinSubTotal) {
|
|
1154
|
-
if ((_a = coupon.productsCategories) === null || _a === void 0 ? void 0 : _a.length) {
|
|
1155
|
-
throw `Valor mínimo de ${Intl.NumberFormat('pt-BR', { style: 'currency', currency: 'BRL' }).format(coupon.minSubTotalValue)} não atingido na(s) categoria(s) elegíveis para o desconto.`;
|
|
1156
|
-
}
|
|
1157
|
-
throw `Valor mínimo de ${Intl.NumberFormat('pt-BR', { style: 'currency', currency: 'BRL' }).format(coupon.minSubTotalValue)} não atingido.`;
|
|
1158
|
-
}
|
|
1159
|
-
return coupon;
|
|
1160
|
-
});
|
|
1161
|
-
}
|
|
1162
|
-
calcDiscountSubscription(coupon, checkout) {
|
|
1163
|
-
let discount = 0;
|
|
1164
|
-
if (coupon.discount.subscription.type == CouponTypes.ABSOLUTE)
|
|
1165
|
-
discount = coupon.discount.subscription.value;
|
|
1166
|
-
else
|
|
1167
|
-
discount = checkout.subscriptionPlan.recurrencePrice * (coupon.discount.subscription.value / 100);
|
|
1168
|
-
return of(discount);
|
|
1169
|
-
}
|
|
1170
|
-
calcDiscountShopping(coupon, checkout) {
|
|
1171
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1172
|
-
let discountInfo = null;
|
|
1173
|
-
if (checkout.user.isSubscriber && coupon.discount.subscriber.value) {
|
|
1174
|
-
discountInfo = yield this.calcDiscountByType(coupon.discount.subscriber.type, coupon.discount.subscriber.value, coupon.productsCategories, checkout);
|
|
1175
|
-
}
|
|
1176
|
-
else {
|
|
1177
|
-
discountInfo = yield this.calcDiscountByType(coupon.discount.non_subscriber.type, coupon.discount.non_subscriber.value, coupon.productsCategories, checkout);
|
|
1178
|
-
}
|
|
1179
|
-
return { discount: discountInfo.discount, lineItems: discountInfo.lineItems };
|
|
1180
|
-
});
|
|
1181
|
-
}
|
|
1182
|
-
calcDiscountByType(type, value, categories, checkout) {
|
|
1183
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1184
|
-
let discount = 0;
|
|
1185
|
-
if (type == CouponTypes.SHIPPING) {
|
|
1186
|
-
const subTotal = checkout.shipping.ShippingPrice;
|
|
1187
|
-
const discount = +(subTotal * ((value > 100 ? 100 : value) / 100)).toFixed(2);
|
|
1188
|
-
return { discount, lineItems: checkout.lineItems };
|
|
1189
|
-
}
|
|
1190
|
-
const lineItensElegibleForDiscount = yield this.getLineItensEligebleForDiscount(categories, checkout);
|
|
1191
|
-
const subTotal = this.calcCheckoutSubtotal(lineItensElegibleForDiscount, checkout.user);
|
|
1192
|
-
if (type == CouponTypes.ABSOLUTE) {
|
|
1193
|
-
discount = value > subTotal ? subTotal : value;
|
|
1194
|
-
}
|
|
1195
|
-
else {
|
|
1196
|
-
discount = +(subTotal * ((value > 100 ? 100 : value) / 100)).toFixed(2);
|
|
1197
|
-
}
|
|
1198
|
-
const lineItems = this.calcLineItenDiscount(type, lineItensElegibleForDiscount, value, subTotal);
|
|
1199
|
-
return { discount, lineItems };
|
|
1200
|
-
});
|
|
1201
|
-
}
|
|
1202
|
-
hasMinSubTotal(coupon, checkout) {
|
|
1203
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1204
|
-
if (!coupon.minSubTotalValue)
|
|
1205
|
-
return true;
|
|
1206
|
-
const lineItensDiscount = yield this.getLineItensEligebleForDiscount(coupon.productsCategories, checkout);
|
|
1207
|
-
const subTotal = this.calcCheckoutSubtotal(lineItensDiscount, checkout.user);
|
|
1208
|
-
if (coupon.minSubTotalValue <= subTotal)
|
|
1209
|
-
return true;
|
|
1210
|
-
return false;
|
|
1211
|
-
});
|
|
1212
|
-
}
|
|
1213
|
-
hasProductCategories(coupon, checkout) {
|
|
1214
|
-
var _a, _b;
|
|
1215
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1216
|
-
if (!coupon.productsCategories || !((_a = coupon.productsCategories) === null || _a === void 0 ? void 0 : _a.length)) {
|
|
1217
|
-
return true;
|
|
1218
|
-
}
|
|
1219
|
-
const couponCategories = yield this.getCouponCategoriesId(coupon.productsCategories);
|
|
1220
|
-
const hasCategories = (_b = checkout.lineItems) === null || _b === void 0 ? void 0 : _b.filter((item) => {
|
|
1221
|
-
var _a;
|
|
1222
|
-
if (item.isGift)
|
|
1223
|
-
return false;
|
|
1224
|
-
if (!item.categories || !((_a = item.categories) === null || _a === void 0 ? void 0 : _a.length))
|
|
1225
|
-
return true;
|
|
1226
|
-
return item.categories.some((c) => couponCategories.some((cat) => cat == c));
|
|
1227
|
-
});
|
|
1228
|
-
return hasCategories.length ? true : false;
|
|
1229
|
-
});
|
|
1230
|
-
}
|
|
1231
|
-
coupomUserValidation(coupon, user) {
|
|
1232
|
-
if (!user || coupon.exclusivityType.includes(Exclusivities.ALL_USERS))
|
|
1233
|
-
return true;
|
|
1234
|
-
let userTypes = [];
|
|
1235
|
-
if (coupon.exclusivityType.includes(Exclusivities.COLLABORATORS) &&
|
|
1236
|
-
this.emailIsFromCollaborator(user.email.toLocaleLowerCase()))
|
|
1237
|
-
userTypes.push(Exclusivities.COLLABORATORS);
|
|
1238
|
-
if (coupon.exclusivityType.includes(Exclusivities.SPECIFIC_USER) &&
|
|
1239
|
-
coupon.userExclusiveEmail.includes(user.email.toLocaleLowerCase()))
|
|
1240
|
-
userTypes.push(Exclusivities.SPECIFIC_USER);
|
|
1241
|
-
if (coupon.exclusivityType.includes(Exclusivities.ACTIVE_SUBSCRIBER) &&
|
|
1242
|
-
user.isSubscriber &&
|
|
1243
|
-
user.subscriptionPlan != '')
|
|
1244
|
-
userTypes.push(Exclusivities.ACTIVE_SUBSCRIBER);
|
|
1245
|
-
if (user.isSubscriber &&
|
|
1246
|
-
user.subscriptionPlan == '' &&
|
|
1247
|
-
coupon.exclusivityType.includes(Exclusivities.INACTIVE_SUBSCRIBER))
|
|
1248
|
-
userTypes.push(Exclusivities.INACTIVE_SUBSCRIBER);
|
|
1249
|
-
if (coupon.exclusivityType.includes(Exclusivities.NON_SUBSCRIBER) && !user.isSubscriber)
|
|
1250
|
-
userTypes.push(Exclusivities.NON_SUBSCRIBER);
|
|
1251
|
-
return coupon.exclusivityType.some((r) => userTypes.includes(r));
|
|
1252
|
-
}
|
|
1253
|
-
getCouponCategoriesId(productsCategories) {
|
|
1254
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1255
|
-
const couponCategories = [];
|
|
1256
|
-
for (let index = 0; index < productsCategories.length; index++) {
|
|
1257
|
-
const category = yield this.categoryRepository.get({
|
|
1258
|
-
id: productsCategories[index],
|
|
1259
|
-
});
|
|
1260
|
-
if (category) {
|
|
1261
|
-
const children = yield this.categoryRepository.getChildren(parseInt(productsCategories[index]));
|
|
1262
|
-
couponCategories.push(category.id, ...children.map((c) => c.id.toString()));
|
|
1263
|
-
}
|
|
1264
|
-
}
|
|
1265
|
-
return [...new Set(couponCategories)];
|
|
1266
|
-
});
|
|
1267
|
-
}
|
|
1268
|
-
getLineItensEligebleForDiscount(productsCategories, checkout) {
|
|
1269
|
-
var _a;
|
|
1270
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1271
|
-
let lineItensDiscount = [];
|
|
1272
|
-
const couponCategories = yield this.getCouponCategoriesId(productsCategories);
|
|
1273
|
-
if (productsCategories && productsCategories.length) {
|
|
1274
|
-
lineItensDiscount = (_a = checkout.lineItems) === null || _a === void 0 ? void 0 : _a.filter((item) => {
|
|
1275
|
-
var _a;
|
|
1276
|
-
if (item.isGift)
|
|
1277
|
-
return false;
|
|
1278
|
-
if ((_a = item.categories) === null || _a === void 0 ? void 0 : _a.length) {
|
|
1279
|
-
return item.categories.some((c) => couponCategories.some((cat) => cat == c));
|
|
1280
|
-
}
|
|
1281
|
-
return true;
|
|
1282
|
-
});
|
|
1283
|
-
}
|
|
1284
|
-
else {
|
|
1285
|
-
lineItensDiscount = checkout.lineItems.filter((item) => !item.isGift);
|
|
1286
|
-
}
|
|
1287
|
-
return lineItensDiscount;
|
|
1288
|
-
});
|
|
1289
|
-
}
|
|
1290
|
-
calcCheckoutSubtotal(lineItens, user) {
|
|
1291
|
-
return ((lineItens === null || lineItens === void 0 ? void 0 : lineItens.filter((item) => !item.isGift).reduce((acc, curr) => {
|
|
1292
|
-
var _a;
|
|
1293
|
-
return (user === null || user === void 0 ? void 0 : user.isSubscriber) && curr.price.subscriberPrice
|
|
1294
|
-
? acc + ((_a = curr.price) === null || _a === void 0 ? void 0 : _a.subscriberPrice) * curr.quantity
|
|
1295
|
-
: acc + curr.pricePaid * curr.quantity;
|
|
1296
|
-
}, 0)) || 0);
|
|
1297
|
-
}
|
|
1298
|
-
getOrdersWithCoupon(coupon) {
|
|
1299
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1300
|
-
return yield this.orderRepository
|
|
1301
|
-
.find({
|
|
1302
|
-
filters: {
|
|
1303
|
-
coupon: { id: coupon.id },
|
|
1304
|
-
status: { operator: Where.NOTEQUALS, value: OrderStatus.CANCELADO },
|
|
1305
|
-
},
|
|
1306
|
-
})
|
|
1307
|
-
.then((result) => result.data);
|
|
1308
|
-
});
|
|
1309
|
-
}
|
|
1310
|
-
getOrdersFromUser(email) {
|
|
1311
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1312
|
-
return yield this.orderRepository
|
|
1313
|
-
.find({
|
|
1314
|
-
filters: {
|
|
1315
|
-
user: { email: { operator: Where.EQUALS, value: email } },
|
|
1316
|
-
status: { operator: Where.NOTEQUALS, value: OrderStatus.CANCELADO },
|
|
1317
|
-
},
|
|
1318
|
-
})
|
|
1319
|
-
.then((result) => result.data);
|
|
1320
|
-
});
|
|
1321
|
-
}
|
|
1322
|
-
countOrdersWithUser(orders, email) {
|
|
1323
|
-
return orders.filter((o) => o.user.email == email).length;
|
|
1324
|
-
}
|
|
1325
|
-
getCouponUseLimits(coupon, checkoutType, user) {
|
|
1326
|
-
let couponUseLimits;
|
|
1327
|
-
if (checkoutType == CheckoutTypes.ECOMMERCE || checkoutType == CheckoutTypes.ALL) {
|
|
1328
|
-
if (coupon.exclusivityType.length === 1 &&
|
|
1329
|
-
(coupon.exclusivityType.at(0) === Exclusivities.SPECIFIC_USER ||
|
|
1330
|
-
coupon.exclusivityType.at(0) === Exclusivities.COLLABORATORS))
|
|
1331
|
-
couponUseLimits = coupon.useLimits.non_subscriber;
|
|
1332
|
-
else
|
|
1333
|
-
couponUseLimits = user && user.isSubscriber ? coupon.useLimits.subscriber : coupon.useLimits.non_subscriber;
|
|
1334
|
-
}
|
|
1335
|
-
else {
|
|
1336
|
-
couponUseLimits = coupon.useLimits.subscription;
|
|
1337
|
-
}
|
|
1338
|
-
return couponUseLimits;
|
|
1339
|
-
}
|
|
1340
|
-
calcLineItenDiscount(type, lineItems, couponDiscount, subTotal) {
|
|
1341
|
-
let lineItemsDiscount = [];
|
|
1342
|
-
if (type === CouponTypes.ABSOLUTE) {
|
|
1343
|
-
const couponDiscountMax = couponDiscount > subTotal ? subTotal : couponDiscount;
|
|
1344
|
-
lineItemsDiscount = lineItems.map((item) => {
|
|
1345
|
-
if (item.isGift)
|
|
1346
|
-
return item;
|
|
1347
|
-
const totalItemPercentage = item.pricePaid / subTotal;
|
|
1348
|
-
const discountItem = couponDiscountMax * totalItemPercentage;
|
|
1349
|
-
return Object.assign(Object.assign({}, item), { discount: Number(discountItem.toFixed(2)) });
|
|
1350
|
-
});
|
|
1351
|
-
}
|
|
1352
|
-
else {
|
|
1353
|
-
lineItemsDiscount = lineItems.map((item) => {
|
|
1354
|
-
if (item.isGift)
|
|
1355
|
-
return item;
|
|
1356
|
-
const discountItem = item.pricePaid * (couponDiscount / 100);
|
|
1357
|
-
return Object.assign(Object.assign({}, item), { discount: Number(discountItem.toFixed(2)) });
|
|
1358
|
-
});
|
|
1359
|
-
}
|
|
1360
|
-
return lineItemsDiscount;
|
|
1361
|
-
}
|
|
1362
|
-
}
|
|
1363
|
-
CouponService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CouponService, deps: [{ token: 'CouponRepository' }, { token: DEFAULT_SHOP }, { token: 'OrderRepository' }, { token: 'CategoryRepository' }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
1364
|
-
CouponService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CouponService, providedIn: 'root' });
|
|
1365
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CouponService, decorators: [{
|
|
1366
|
-
type: Injectable,
|
|
1367
|
-
args: [{
|
|
1368
|
-
providedIn: 'root',
|
|
1369
|
-
}]
|
|
1370
|
-
}], ctorParameters: function () {
|
|
1371
|
-
return [{ type: undefined, decorators: [{
|
|
1372
|
-
type: Inject,
|
|
1373
|
-
args: ['CouponRepository']
|
|
1374
|
-
}] }, { type: i1$2.Shops, decorators: [{
|
|
1375
|
-
type: Inject,
|
|
1376
|
-
args: [DEFAULT_SHOP]
|
|
1377
|
-
}] }, { type: undefined, decorators: [{
|
|
1378
|
-
type: Inject,
|
|
1379
|
-
args: ['OrderRepository']
|
|
1380
|
-
}] }, { type: undefined, decorators: [{
|
|
1381
|
-
type: Inject,
|
|
1382
|
-
args: ['CategoryRepository']
|
|
1383
|
-
}] }];
|
|
1384
|
-
} });
|
|
1385
|
-
|
|
1386
1087
|
class CheckoutService {
|
|
1387
|
-
constructor(
|
|
1388
|
-
this.couponService = couponService;
|
|
1088
|
+
constructor(checkoutRepository, userRepository, defaultShop, dataPersistence, firebaseOptions, http) {
|
|
1389
1089
|
this.checkoutRepository = checkoutRepository;
|
|
1390
1090
|
this.userRepository = userRepository;
|
|
1391
1091
|
this.defaultShop = defaultShop;
|
|
1392
1092
|
this.dataPersistence = dataPersistence;
|
|
1093
|
+
this.firebaseOptions = firebaseOptions;
|
|
1094
|
+
this.http = http;
|
|
1095
|
+
this.checkoutUrl = null;
|
|
1096
|
+
this.checkoutUrl = `https://southamerica-east1-${this.firebaseOptions.projectId}.cloudfunctions.net`;
|
|
1097
|
+
// this.checkoutUrl = `http://docker.for.localhost:5001/b4astage-cb80a/southamerica-east1`
|
|
1393
1098
|
}
|
|
1394
1099
|
getCheckout(checkoutData) {
|
|
1395
1100
|
return this.dataPersistence
|
|
@@ -1408,11 +1113,56 @@ class CheckoutService {
|
|
|
1408
1113
|
clearCheckoutFromSession() {
|
|
1409
1114
|
return this.dataPersistence.remove('checkoutId');
|
|
1410
1115
|
}
|
|
1411
|
-
|
|
1412
|
-
return this.getCheckout().pipe(concatMap((checkout) =>
|
|
1116
|
+
resetCheckoutValues() {
|
|
1117
|
+
return this.getCheckout().pipe(concatMap((checkout) => this.http.post(`${this.checkoutUrl}/checkoutResetValues`, {
|
|
1118
|
+
checkoutId: checkout.id,
|
|
1119
|
+
})), concatMap(() => this.getCheckout()));
|
|
1120
|
+
}
|
|
1121
|
+
applyCouponDiscount(nickname, checkoutType) {
|
|
1122
|
+
return this.getCheckout().pipe(concatMap((checkout) => this.http.post(`${this.checkoutUrl}/checkoutApplyDiscount`, {
|
|
1123
|
+
checkoutId: checkout.id,
|
|
1124
|
+
coupon: nickname,
|
|
1125
|
+
checkoutType,
|
|
1126
|
+
})), concatMap(() => this.getCheckout()), map((checkout) => checkout.coupon));
|
|
1127
|
+
}
|
|
1128
|
+
removeCouponDiscount() {
|
|
1129
|
+
return this.getCheckout().pipe(concatMap((checkout) => this.http.post(`${this.checkoutUrl}/checkoutRemoveDiscount`, {
|
|
1130
|
+
checkoutId: checkout.id,
|
|
1131
|
+
})), concatMap(() => this.getCheckout()));
|
|
1132
|
+
}
|
|
1133
|
+
validateStockProducts() {
|
|
1134
|
+
return this.getCheckout().pipe(concatMap((checkout) => this.http.post(`${this.checkoutUrl}/checkoutValidateProductStock`, {
|
|
1135
|
+
checkoutId: checkout.id,
|
|
1136
|
+
})));
|
|
1413
1137
|
}
|
|
1414
|
-
|
|
1415
|
-
return this.getCheckout().pipe(concatMap((checkout) =>
|
|
1138
|
+
selectShippingAddress(address) {
|
|
1139
|
+
return this.getCheckout().pipe(concatMap((checkout) => {
|
|
1140
|
+
return this.checkoutRepository.update(Checkout.toInstance({ id: checkout.id, shippingAddress: address, billingAddress: address }));
|
|
1141
|
+
}));
|
|
1142
|
+
}
|
|
1143
|
+
getAvailableShippingForProduct(productShipping) {
|
|
1144
|
+
return this.http.post(`${this.checkoutUrl}/checkoutGetAvailableShipping`, {
|
|
1145
|
+
checkoutId: null,
|
|
1146
|
+
productShipping,
|
|
1147
|
+
});
|
|
1148
|
+
}
|
|
1149
|
+
getAvailableShippingForCheckout() {
|
|
1150
|
+
return this.getCheckout().pipe(concatMap((checkout) => this.http.post(`${this.checkoutUrl}/checkoutGetAvailableShipping`, {
|
|
1151
|
+
checkoutId: checkout.id,
|
|
1152
|
+
productShipping: null,
|
|
1153
|
+
})));
|
|
1154
|
+
}
|
|
1155
|
+
selectShipping(option) {
|
|
1156
|
+
return this.getCheckout().pipe(concatMap((checkout) => this.http.post(`${this.checkoutUrl}/checkoutSelectShipping`, {
|
|
1157
|
+
checkoutId: checkout.id,
|
|
1158
|
+
shippingOption: option,
|
|
1159
|
+
})), concatMap(() => this.getCheckout()));
|
|
1160
|
+
}
|
|
1161
|
+
createOrder(checkoutPayload, paymentProvider, applicationVersion) {
|
|
1162
|
+
return this.http.post(`${this.checkoutUrl}/checkout`, {
|
|
1163
|
+
data: Object.assign(Object.assign({}, checkoutPayload), { applicationVersion,
|
|
1164
|
+
paymentProvider }),
|
|
1165
|
+
});
|
|
1416
1166
|
}
|
|
1417
1167
|
createCheckout(checkoutData) {
|
|
1418
1168
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -1422,117 +1172,68 @@ class CheckoutService {
|
|
|
1422
1172
|
});
|
|
1423
1173
|
}
|
|
1424
1174
|
}
|
|
1425
|
-
CheckoutService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CheckoutService, deps: [{ token:
|
|
1175
|
+
CheckoutService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CheckoutService, deps: [{ token: 'CheckoutRepository' }, { token: 'UserRepository' }, { token: DEFAULT_SHOP }, { token: PERSISTENCE_PROVIDER }, { token: FIREBASE_OPTIONS }, { token: i1$2.HttpClient }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
1426
1176
|
CheckoutService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CheckoutService });
|
|
1427
1177
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CheckoutService, decorators: [{
|
|
1428
1178
|
type: Injectable
|
|
1429
1179
|
}], ctorParameters: function () {
|
|
1430
|
-
return [{ type:
|
|
1180
|
+
return [{ type: undefined, decorators: [{
|
|
1431
1181
|
type: Inject,
|
|
1432
1182
|
args: ['CheckoutRepository']
|
|
1433
1183
|
}] }, { type: undefined, decorators: [{
|
|
1434
1184
|
type: Inject,
|
|
1435
1185
|
args: ['UserRepository']
|
|
1436
|
-
}] }, { type: i1$
|
|
1186
|
+
}] }, { type: i1$3.Shops, decorators: [{
|
|
1437
1187
|
type: Inject,
|
|
1438
1188
|
args: [DEFAULT_SHOP]
|
|
1439
1189
|
}] }, { type: undefined, decorators: [{
|
|
1440
1190
|
type: Inject,
|
|
1441
1191
|
args: [PERSISTENCE_PROVIDER]
|
|
1442
|
-
}] }
|
|
1192
|
+
}] }, { type: undefined, decorators: [{
|
|
1193
|
+
type: Inject,
|
|
1194
|
+
args: [FIREBASE_OPTIONS]
|
|
1195
|
+
}] }, { type: i1$2.HttpClient }];
|
|
1443
1196
|
} });
|
|
1444
1197
|
|
|
1445
1198
|
class CartService {
|
|
1446
|
-
constructor(authService, checkoutService, defaultShop, firebaseOptions,
|
|
1199
|
+
constructor(authService, checkoutService, defaultShop, firebaseOptions,
|
|
1200
|
+
// @Inject('ProductRepository') private readonly productRepository: ProductRepository,
|
|
1201
|
+
// @Inject('CategoryRepository') private readonly categoryRepository: CategoryRepository,
|
|
1202
|
+
// @Inject('VariantRepository') private readonly variantRepository: VariantRepository,
|
|
1203
|
+
// @Inject('Buy2WinRepository') private readonly buy2WinRepository: Buy2WinFirestoreRepository,
|
|
1204
|
+
http) {
|
|
1447
1205
|
this.authService = authService;
|
|
1448
1206
|
this.checkoutService = checkoutService;
|
|
1449
1207
|
this.defaultShop = defaultShop;
|
|
1450
1208
|
this.firebaseOptions = firebaseOptions;
|
|
1451
|
-
this.productRepository = productRepository;
|
|
1452
|
-
this.categoryRepository = categoryRepository;
|
|
1453
|
-
this.variantRepository = variantRepository;
|
|
1454
|
-
this.buy2WinRepository = buy2WinRepository;
|
|
1455
1209
|
this.http = http;
|
|
1456
1210
|
this.cartSubject = new Subject();
|
|
1457
1211
|
this.checkoutUrl = null;
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1212
|
+
// private updateLineItemInCart = (lineItem: LineItem, quantity: number, checkout?: Checkout): Observable<Cart> =>
|
|
1213
|
+
// (isNil(checkout) ? this.checkoutService.getCheckout() : of(checkout)).pipe(
|
|
1214
|
+
// concatMap((checkoutLoaded) => {
|
|
1215
|
+
// const items: LineItem[] = []
|
|
1216
|
+
// const index = checkoutLoaded.lineItems?.map((checkoutItem) => checkoutItem.id).indexOf(lineItem.id)
|
|
1217
|
+
// const isGift = checkoutLoaded.lineItems?.[index]?.isGift
|
|
1218
|
+
// if (index > -1) {
|
|
1219
|
+
// checkoutLoaded.lineItems[index].quantity += quantity
|
|
1220
|
+
// checkoutLoaded.lineItems[index].pricePaid = isGift ? 0 : lineItem.pricePaid
|
|
1221
|
+
// checkoutLoaded.lineItems[index].price = lineItem.price
|
|
1222
|
+
// } else
|
|
1223
|
+
// checkoutLoaded.lineItems = items.concat(
|
|
1224
|
+
// checkoutLoaded.lineItems ? checkoutLoaded.lineItems.concat([lineItem]) : [lineItem],
|
|
1225
|
+
// )
|
|
1226
|
+
// return this.checkoutService
|
|
1227
|
+
// .updateCheckoutLineItems(checkoutLoaded)
|
|
1228
|
+
// .pipe(map((updatedCheckout) => this.generateCartObject(updatedCheckout.lineItems)))
|
|
1229
|
+
// }),
|
|
1230
|
+
// )
|
|
1474
1231
|
this.generateCartObject = (items) => (items === null || items === void 0 ? void 0 : items.reduce((cart, item) => {
|
|
1475
1232
|
var _a;
|
|
1476
1233
|
return (Object.assign(Object.assign({}, cart), { [item.id]: LineItem.toInstance(Object.assign(Object.assign({}, (cart[item.id] || item)), { quantity: (((_a = cart[item.id]) === null || _a === void 0 ? void 0 : _a.quantity) || 0) + (item.quantity ? item.quantity : 1) })) }));
|
|
1477
1234
|
}, {})) || {};
|
|
1478
|
-
this.
|
|
1479
|
-
|
|
1480
|
-
const product = yield this.getProductData(item.id);
|
|
1481
|
-
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((lineItem) => lineItem.id === item.id)) === null || _b === void 0 ? void 0 : _b.quantity) || 0;
|
|
1482
|
-
if (this.checkMaxStock(product.stock.quantity, item.quantity || 0, quantity || 0))
|
|
1483
|
-
throw new Error('Desculpe! Temos apenas ' + ((_c = product.stock) === null || _c === void 0 ? void 0 : _c.quantity) + ' em estoque.');
|
|
1484
|
-
const image = item.image || ((_d = item.images) === null || _d === void 0 ? void 0 : _d.shift());
|
|
1485
|
-
const { id, name, EAN, slug, weight, sku, type } = item;
|
|
1486
|
-
const isGift = (item === null || item === void 0 ? void 0 : item.isGift) || null;
|
|
1487
|
-
const pricePaid = isGift
|
|
1488
|
-
? 0
|
|
1489
|
-
: this.getProductPrice({
|
|
1490
|
-
product: LineItem.toInstance(product),
|
|
1491
|
-
shop: checkout.shop || this.defaultShop,
|
|
1492
|
-
isSubscriber: (_e = checkout.user) === null || _e === void 0 ? void 0 : _e.isSubscriber,
|
|
1493
|
-
});
|
|
1494
|
-
RoundProductPricesHelper.roundProductPrices(item);
|
|
1495
|
-
RoundProductPricesHelper.roundProductPrices(product);
|
|
1496
|
-
return {
|
|
1497
|
-
checkout,
|
|
1498
|
-
lineItem: LineItem.toInstance({
|
|
1499
|
-
id,
|
|
1500
|
-
name: name !== null && name !== void 0 ? name : product.name,
|
|
1501
|
-
EAN: EAN !== null && EAN !== void 0 ? EAN : product.EAN,
|
|
1502
|
-
brand: product.brand,
|
|
1503
|
-
slug: slug !== null && slug !== void 0 ? slug : product.slug,
|
|
1504
|
-
sku: sku !== null && sku !== void 0 ? sku : product.sku,
|
|
1505
|
-
stock: product.stock,
|
|
1506
|
-
price: this.roundPrice(product.price),
|
|
1507
|
-
image,
|
|
1508
|
-
weight: weight !== null && weight !== void 0 ? weight : product.weight,
|
|
1509
|
-
quantity: (item.quantity || 0) + (quantity || 0),
|
|
1510
|
-
pricePaid,
|
|
1511
|
-
discount: 0,
|
|
1512
|
-
categories: product.categories || ((_f = product.category) === null || _f === void 0 ? void 0 : _f.id) ? [(_g = product.category) === null || _g === void 0 ? void 0 : _g.id, ...product.categories] : [],
|
|
1513
|
-
category: product.category,
|
|
1514
|
-
isGift: isGift !== null && isGift !== void 0 ? isGift : null,
|
|
1515
|
-
costPrice: isGift ? 0 : (_h = product.costPrice) !== null && _h !== void 0 ? _h : 0,
|
|
1516
|
-
type,
|
|
1517
|
-
label: product.label,
|
|
1518
|
-
}),
|
|
1519
|
-
};
|
|
1520
|
-
});
|
|
1521
|
-
this.getProductPrice = ({ product, isSubscriber, }) => {
|
|
1522
|
-
const info = product.price;
|
|
1523
|
-
if (product.isGift)
|
|
1524
|
-
return 0;
|
|
1525
|
-
return isSubscriber && info.subscriberPrice > 0
|
|
1526
|
-
? Number(info.subscriberPrice.toFixed(2))
|
|
1527
|
-
: Number(info.price.toFixed(2));
|
|
1528
|
-
};
|
|
1529
|
-
this.checkMaxStock = (currentStock, currentItemQtd, quantityToAdd) => {
|
|
1530
|
-
const maxStock = currentStock || 0;
|
|
1531
|
-
const currentItemAmount = currentItemQtd || 0;
|
|
1532
|
-
return currentItemAmount + quantityToAdd > maxStock;
|
|
1533
|
-
};
|
|
1534
|
-
// this.checkoutUrl = `https://southamerica-east1-${this.firebaseOptions.projectId}.cloudfunctions.net`
|
|
1535
|
-
this.checkoutUrl = `http://docker.for.localhost:5001/b4astage-cb80a/southamerica-east1`;
|
|
1235
|
+
this.checkoutUrl = `https://southamerica-east1-${this.firebaseOptions.projectId}.cloudfunctions.net`;
|
|
1236
|
+
// this.checkoutUrl = `http://docker.for.localhost:5001/b4astage-cb80a/southamerica-east1`
|
|
1536
1237
|
}
|
|
1537
1238
|
addItem(item, quantity = 1) {
|
|
1538
1239
|
return this.checkoutService.getCheckout().pipe(concatMap((checkout) => {
|
|
@@ -1597,7 +1298,6 @@ class CartService {
|
|
|
1597
1298
|
return this.checkoutService.updateCheckoutUser(Checkout.toInstance(Object.assign(Object.assign({}, checkout.toPlain()), { user })));
|
|
1598
1299
|
}), concatMap((checkout) => {
|
|
1599
1300
|
console.log('getCheckout User', checkout);
|
|
1600
|
-
this.user = user;
|
|
1601
1301
|
return this.http.post(`${this.checkoutUrl}/checkoutUpdateUserCart`, {
|
|
1602
1302
|
checkoutId: checkout.id,
|
|
1603
1303
|
});
|
|
@@ -1633,166 +1333,43 @@ class CartService {
|
|
|
1633
1333
|
this.buildCartFromCheckout(checkout).subscribe((cart) => this.cartSubject.next(cart));
|
|
1634
1334
|
return this.cartSubject;
|
|
1635
1335
|
}
|
|
1636
|
-
/**
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
getVariantPriceDiscount(item) {
|
|
1640
|
-
|
|
1641
|
-
|
|
1336
|
+
// /**
|
|
1337
|
+
// * @deprecated The method should not be used
|
|
1338
|
+
// */
|
|
1339
|
+
// getVariantPriceDiscount(item: LineItem): Observable<number> {
|
|
1340
|
+
// return this.authService.getUser().pipe(
|
|
1341
|
+
// concatMap((user) =>
|
|
1342
|
+
// iif(
|
|
1343
|
+
// () => user.isSubscriber && !!item.price.subscriberPrice,
|
|
1344
|
+
// of(item.price.subscriberPrice),
|
|
1345
|
+
// of(item.price.price),
|
|
1346
|
+
// ),
|
|
1347
|
+
// ),
|
|
1348
|
+
// catchError(() => of(item.price.price)),
|
|
1349
|
+
// )
|
|
1350
|
+
// }
|
|
1642
1351
|
clearCart() {
|
|
1643
1352
|
return this.checkoutService.getCheckout().pipe(map((checkout) => {
|
|
1644
1353
|
this.checkoutService.clearCheckoutFromSession();
|
|
1645
1354
|
return checkout;
|
|
1646
|
-
}), concatMap((oldCheckout) => this.buildCartFromCheckout(oldCheckout)), tap((cart) => this.cartSubject.next(cart)));
|
|
1647
|
-
}
|
|
1648
|
-
buildCartFromCheckout(checkoutData) {
|
|
1649
|
-
return this.checkoutService.getCheckout(checkoutData).pipe(map((checkout) => checkout.lineItems), concatMap((lineItems) => of(this.generateCartObject(lineItems))));
|
|
1650
|
-
}
|
|
1651
|
-
roundPrice(productPrice) {
|
|
1652
|
-
const { price, fullPrice, subscriberPrice } = productPrice;
|
|
1653
|
-
return Object.assign(Object.assign(Object.assign({}, productPrice), { price: Number(price.toFixed(2)), fullPrice: Number(fullPrice.toFixed(2)) }), (subscriberPrice && { subscriberPrice: Number(subscriberPrice.toFixed(2)) }));
|
|
1654
|
-
}
|
|
1655
|
-
getProductData(productId) {
|
|
1656
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1657
|
-
let product;
|
|
1658
|
-
let variant;
|
|
1659
|
-
try {
|
|
1660
|
-
product = yield this.productRepository.get({ id: productId });
|
|
1661
|
-
}
|
|
1662
|
-
catch (error) {
|
|
1663
|
-
if (!(error instanceof NotFoundError))
|
|
1664
|
-
throw error;
|
|
1665
|
-
const { data: variants } = yield this.variantRepository.find({ filters: { id: productId } });
|
|
1666
|
-
variant = variants.shift();
|
|
1667
|
-
if (!variant)
|
|
1668
|
-
throw error;
|
|
1669
|
-
product = yield this.productRepository.get({ id: variant.productId });
|
|
1670
|
-
}
|
|
1671
|
-
return Object.assign(Object.assign({}, product.toPlain()), (variant && Object.assign({}, variant.toPlain())));
|
|
1672
|
-
});
|
|
1673
|
-
}
|
|
1674
|
-
getGifts() {
|
|
1675
|
-
return this.checkoutService.getCheckout().pipe(mergeMap((checkout) => __awaiter(this, void 0, void 0, function* () {
|
|
1676
|
-
const notGiftItems = checkout.lineItems ? checkout.lineItems.filter((item) => !item.isGift) : [];
|
|
1677
|
-
if (!notGiftItems.length)
|
|
1678
|
-
return Object.assign(Object.assign({}, checkout), { lineItems: [] });
|
|
1679
|
-
const campaigns = yield this.buy2WinRepository
|
|
1680
|
-
.find({
|
|
1681
|
-
filters: {
|
|
1682
|
-
active: { operator: Where.EQUALS, value: true },
|
|
1683
|
-
},
|
|
1684
|
-
})
|
|
1685
|
-
.then((data) => data.data.filter((campaign) => campaign.shop === Shops.ALL || campaign.shop === this.defaultShop));
|
|
1686
|
-
if (!campaigns.length)
|
|
1687
|
-
return Object.assign(Object.assign({}, checkout), { lineItems: notGiftItems });
|
|
1688
|
-
const elegibleCampaigns = [];
|
|
1689
|
-
for (const campaign of campaigns) {
|
|
1690
|
-
const today = new Date().getTime();
|
|
1691
|
-
if (!(campaign.startDate.getTime() <= today) && !(campaign.endDate.getTime() >= today))
|
|
1692
|
-
continue;
|
|
1693
|
-
if (campaign.activeCategory) {
|
|
1694
|
-
const categoriesCampaing = campaign.categories.map((c) => c.id.toString());
|
|
1695
|
-
const categoriesCampaingFullTree = [];
|
|
1696
|
-
for (const id of categoriesCampaing) {
|
|
1697
|
-
const children = yield this.categoryRepository.getChildren(parseInt(id));
|
|
1698
|
-
categoriesCampaingFullTree.push(id, ...children.map((c) => c.id.toString()));
|
|
1699
|
-
}
|
|
1700
|
-
const categoriesCampaingTree = [...new Set(categoriesCampaingFullTree)];
|
|
1701
|
-
const filterProductsCategories = notGiftItems.filter((l) => {
|
|
1702
|
-
var _a;
|
|
1703
|
-
if (!l.categories || !((_a = l.categories) === null || _a === void 0 ? void 0 : _a.length))
|
|
1704
|
-
return true;
|
|
1705
|
-
return l.categories.some((c) => categoriesCampaingTree.some((cat) => cat == c));
|
|
1706
|
-
});
|
|
1707
|
-
if (filterProductsCategories.length) {
|
|
1708
|
-
const cartValuelWithCategories = filterProductsCategories.reduce((a, b) => a + b.pricePaid * b.quantity, 0);
|
|
1709
|
-
const cartItensQuantityWithCategories = filterProductsCategories.reduce((a, b) => a + b.quantity, 0);
|
|
1710
|
-
const hasMinValue = campaign.cartValueMin && cartValuelWithCategories >= campaign.cartValueMin;
|
|
1711
|
-
const hasMinQuantity = campaign.cartItensQuantityMin && cartItensQuantityWithCategories >= campaign.cartItensQuantityMin;
|
|
1712
|
-
if (hasMinQuantity || hasMinValue)
|
|
1713
|
-
elegibleCampaigns.push(campaign);
|
|
1714
|
-
}
|
|
1715
|
-
}
|
|
1716
|
-
else {
|
|
1717
|
-
const cartTotal = notGiftItems.reduce((a, b) => a + b.pricePaid * b.quantity, 0);
|
|
1718
|
-
const cartItensQuantity = notGiftItems.reduce((a, b) => a + b.quantity, 0);
|
|
1719
|
-
const hasMinValue = campaign.cartValue && campaign.cartValue > 0 && campaign.cartValue <= cartTotal;
|
|
1720
|
-
const hasMinQuantity = campaign.cartItensQuantityMin && cartItensQuantity >= campaign.cartItensQuantityMin;
|
|
1721
|
-
if (hasMinQuantity || hasMinValue)
|
|
1722
|
-
elegibleCampaigns.push(campaign);
|
|
1723
|
-
}
|
|
1724
|
-
}
|
|
1725
|
-
if (!elegibleCampaigns.length)
|
|
1726
|
-
return Object.assign(Object.assign({}, checkout), { lineItems: notGiftItems });
|
|
1727
|
-
const campaingnProducts = [];
|
|
1728
|
-
for (const campaign of elegibleCampaigns) {
|
|
1729
|
-
let elegibleProducts = [];
|
|
1730
|
-
for (const product of campaign.products) {
|
|
1731
|
-
const { data: productData } = yield this.productRepository.find({ filters: { sku: product } });
|
|
1732
|
-
if (!productData.length)
|
|
1733
|
-
continue;
|
|
1734
|
-
const gift = productData.shift();
|
|
1735
|
-
if (gift.stock.quantity < 1)
|
|
1736
|
-
continue;
|
|
1737
|
-
elegibleProducts.push(gift);
|
|
1738
|
-
}
|
|
1739
|
-
campaingnProducts.push(elegibleProducts);
|
|
1740
|
-
}
|
|
1741
|
-
if (!campaingnProducts.length)
|
|
1742
|
-
return Object.assign(Object.assign({}, checkout), { lineItems: notGiftItems });
|
|
1743
|
-
const gifts = this.giftToLineItems([].concat(...campaingnProducts));
|
|
1744
|
-
return Object.assign(Object.assign({}, checkout), { lineItems: notGiftItems.concat(gifts) });
|
|
1745
|
-
})), concatMap((checkout) => this.checkoutService.updateCheckoutLineItems(checkout)), map((checkout) => this.generateCartObject(checkout.lineItems)), tap((cart) => this.cartSubject.next(cart)));
|
|
1746
|
-
}
|
|
1747
|
-
giftToLineItems(items) {
|
|
1748
|
-
return items.map((item) => {
|
|
1749
|
-
var _a;
|
|
1750
|
-
const { brand, categories, category, id, name, price, sku, slug, stock, weight, EAN } = item;
|
|
1751
|
-
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];
|
|
1752
|
-
return LineItem.toInstance({
|
|
1753
|
-
brand,
|
|
1754
|
-
categories,
|
|
1755
|
-
category,
|
|
1756
|
-
id: id.toString(),
|
|
1757
|
-
name,
|
|
1758
|
-
price,
|
|
1759
|
-
sku,
|
|
1760
|
-
slug,
|
|
1761
|
-
stock,
|
|
1762
|
-
weight,
|
|
1763
|
-
EAN,
|
|
1764
|
-
image,
|
|
1765
|
-
pricePaid: 0,
|
|
1766
|
-
quantity: 1,
|
|
1767
|
-
isGift: true,
|
|
1768
|
-
});
|
|
1769
|
-
});
|
|
1355
|
+
}), concatMap((oldCheckout) => this.buildCartFromCheckout(oldCheckout)), tap((cart) => this.cartSubject.next(cart)));
|
|
1356
|
+
}
|
|
1357
|
+
buildCartFromCheckout(checkoutData) {
|
|
1358
|
+
return this.checkoutService.getCheckout(checkoutData).pipe(map((checkout) => checkout.lineItems), concatMap((lineItems) => of(this.generateCartObject(lineItems))));
|
|
1770
1359
|
}
|
|
1771
1360
|
}
|
|
1772
|
-
CartService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CartService, deps: [{ token: AuthService }, { token: CheckoutService }, { token: DEFAULT_SHOP }, { token: FIREBASE_OPTIONS }, { token:
|
|
1361
|
+
CartService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CartService, deps: [{ token: AuthService }, { token: CheckoutService }, { token: DEFAULT_SHOP }, { token: FIREBASE_OPTIONS }, { token: i1$2.HttpClient }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
1773
1362
|
CartService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CartService });
|
|
1774
1363
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CartService, decorators: [{
|
|
1775
1364
|
type: Injectable
|
|
1776
1365
|
}], ctorParameters: function () {
|
|
1777
|
-
return [{ type: AuthService }, { type: CheckoutService }, { type: i1$
|
|
1366
|
+
return [{ type: AuthService }, { type: CheckoutService }, { type: i1$3.Shops, decorators: [{
|
|
1778
1367
|
type: Inject,
|
|
1779
1368
|
args: [DEFAULT_SHOP]
|
|
1780
1369
|
}] }, { type: undefined, decorators: [{
|
|
1781
1370
|
type: Inject,
|
|
1782
1371
|
args: [FIREBASE_OPTIONS]
|
|
1783
|
-
}] }, { type:
|
|
1784
|
-
type: Inject,
|
|
1785
|
-
args: ['ProductRepository']
|
|
1786
|
-
}] }, { type: undefined, decorators: [{
|
|
1787
|
-
type: Inject,
|
|
1788
|
-
args: ['CategoryRepository']
|
|
1789
|
-
}] }, { type: undefined, decorators: [{
|
|
1790
|
-
type: Inject,
|
|
1791
|
-
args: ['VariantRepository']
|
|
1792
|
-
}] }, { type: i1$2.Buy2WinFirestoreRepository, decorators: [{
|
|
1793
|
-
type: Inject,
|
|
1794
|
-
args: ['Buy2WinRepository']
|
|
1795
|
-
}] }, { type: i3.HttpClient }];
|
|
1372
|
+
}] }, { type: i1$2.HttpClient }];
|
|
1796
1373
|
} });
|
|
1797
1374
|
|
|
1798
1375
|
class NewCategoryStructureAdapter {
|
|
@@ -2133,7 +1710,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImpor
|
|
|
2133
1710
|
}] }, { type: undefined, decorators: [{
|
|
2134
1711
|
type: Inject,
|
|
2135
1712
|
args: [CATEGORY_STRUCTURE]
|
|
2136
|
-
}] }, { type: i1$
|
|
1713
|
+
}] }, { type: i1$3.Shops, decorators: [{
|
|
2137
1714
|
type: Inject,
|
|
2138
1715
|
args: [DEFAULT_SHOP]
|
|
2139
1716
|
}] }, { type: undefined, decorators: [{
|
|
@@ -2188,7 +1765,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImpor
|
|
|
2188
1765
|
}] }, { type: undefined, decorators: [{
|
|
2189
1766
|
type: Inject,
|
|
2190
1767
|
args: [CATEGORY_STRUCTURE]
|
|
2191
|
-
}] }, { type: i1$
|
|
1768
|
+
}] }, { type: i1$3.Shops, decorators: [{
|
|
2192
1769
|
type: Inject,
|
|
2193
1770
|
args: [DEFAULT_SHOP]
|
|
2194
1771
|
}] }];
|
|
@@ -2300,160 +1877,449 @@ class WishlistService {
|
|
|
2300
1877
|
return this.wishlistRepository.update(data);
|
|
2301
1878
|
});
|
|
2302
1879
|
}
|
|
2303
|
-
delete(wishlistId) {
|
|
1880
|
+
delete(wishlistId) {
|
|
1881
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1882
|
+
const wishlist = yield this.findById(wishlistId);
|
|
1883
|
+
yield this.createWishlistLog(WishlistLogType.DELETE, wishlist);
|
|
1884
|
+
return this.wishlistRepository.delete({ id: wishlistId });
|
|
1885
|
+
});
|
|
1886
|
+
}
|
|
1887
|
+
getWishlistBySlug(slug) {
|
|
1888
|
+
const [id] = slug.split('-');
|
|
1889
|
+
if (+id)
|
|
1890
|
+
return this.wishlistRepository.get({ id });
|
|
1891
|
+
return this.wishlistRepository.getWishlistBySlug(slug);
|
|
1892
|
+
}
|
|
1893
|
+
getWishlistsByPerson(personId) {
|
|
1894
|
+
return this.wishlistRepository.getWishlistByPerson(personId);
|
|
1895
|
+
}
|
|
1896
|
+
addProduct(wishlistId, productId) {
|
|
1897
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1898
|
+
const wishlist = yield this.wishlistRepository.get({ id: wishlistId });
|
|
1899
|
+
const hasProduct = wishlist.products.some((p) => p == productId);
|
|
1900
|
+
const wishlistData = yield this.findById(wishlistId);
|
|
1901
|
+
const productData = yield this.findProductById(productId);
|
|
1902
|
+
yield this.createWishlistLog(WishlistLogType.ADD_PRODUCT, wishlistData, productData);
|
|
1903
|
+
if (!hasProduct) {
|
|
1904
|
+
wishlist.products = [...wishlist.products, productId];
|
|
1905
|
+
yield this.wishlistRepository.addProduct(wishlistId, productId);
|
|
1906
|
+
}
|
|
1907
|
+
return wishlist;
|
|
1908
|
+
});
|
|
1909
|
+
}
|
|
1910
|
+
removeProduct(wishlistId, productId) {
|
|
1911
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1912
|
+
const wishlist = yield this.wishlistRepository.get({ id: wishlistId });
|
|
1913
|
+
const productIndex = wishlist.products.findIndex((p) => p == productId);
|
|
1914
|
+
if (productIndex != -1) {
|
|
1915
|
+
wishlist.products.splice(productIndex, 1);
|
|
1916
|
+
const wishlistData = yield this.findById(wishlistId);
|
|
1917
|
+
const productData = yield this.findProductById(productId);
|
|
1918
|
+
yield this.createWishlistLog(WishlistLogType.REMOVE_PRODUCT, wishlistData, productData);
|
|
1919
|
+
yield this.wishlistRepository.removeProduct(wishlistId, productId);
|
|
1920
|
+
}
|
|
1921
|
+
return wishlist;
|
|
1922
|
+
});
|
|
1923
|
+
}
|
|
1924
|
+
findById(id) {
|
|
1925
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1926
|
+
return this.wishlistRepository
|
|
1927
|
+
.find({
|
|
1928
|
+
fields: ['id', 'name', 'description', 'personId', 'personIsSubscriber', 'personType', 'personName'],
|
|
1929
|
+
filters: {
|
|
1930
|
+
id,
|
|
1931
|
+
},
|
|
1932
|
+
})
|
|
1933
|
+
.then((res) => res.data.at(0));
|
|
1934
|
+
});
|
|
1935
|
+
}
|
|
1936
|
+
findProductById(id) {
|
|
1937
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1938
|
+
return this.productRepository
|
|
1939
|
+
.find({
|
|
1940
|
+
fields: ['id', 'sku', 'EAN', 'name', 'brand'],
|
|
1941
|
+
filters: {
|
|
1942
|
+
id,
|
|
1943
|
+
},
|
|
1944
|
+
})
|
|
1945
|
+
.then((res) => res.data.at(0));
|
|
1946
|
+
});
|
|
1947
|
+
}
|
|
1948
|
+
createWishlistLog(type, wishlist, product) {
|
|
1949
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1950
|
+
switch (type) {
|
|
1951
|
+
case WishlistLogType.CREATE:
|
|
1952
|
+
case WishlistLogType.UPDATE:
|
|
1953
|
+
case WishlistLogType.DELETE:
|
|
1954
|
+
yield this.logRepository.create({
|
|
1955
|
+
collection: 'wishlist',
|
|
1956
|
+
date: new Date(),
|
|
1957
|
+
operation: WishlistLogType.CREATE ? 'CREATE' : WishlistLogType.UPDATE ? 'UPDATE' : 'DELETE',
|
|
1958
|
+
documentId: wishlist.id,
|
|
1959
|
+
document: {
|
|
1960
|
+
id: wishlist.id,
|
|
1961
|
+
shop: this.shop,
|
|
1962
|
+
name: wishlist.name,
|
|
1963
|
+
description: wishlist.description,
|
|
1964
|
+
published: wishlist.published,
|
|
1965
|
+
type: type,
|
|
1966
|
+
personType: wishlist.personType,
|
|
1967
|
+
personId: wishlist.personId,
|
|
1968
|
+
personName: wishlist.personName,
|
|
1969
|
+
personIsSubscriber: wishlist.personIsSubscriber,
|
|
1970
|
+
},
|
|
1971
|
+
});
|
|
1972
|
+
break;
|
|
1973
|
+
case WishlistLogType.ADD_PRODUCT:
|
|
1974
|
+
case WishlistLogType.REMOVE_PRODUCT:
|
|
1975
|
+
yield this.logRepository.create({
|
|
1976
|
+
collection: 'wishlist',
|
|
1977
|
+
date: new Date(),
|
|
1978
|
+
operation: 'UPDATE',
|
|
1979
|
+
documentId: wishlist.id,
|
|
1980
|
+
document: {
|
|
1981
|
+
id: wishlist.id,
|
|
1982
|
+
shop: this.shop,
|
|
1983
|
+
name: wishlist.name,
|
|
1984
|
+
description: wishlist.description,
|
|
1985
|
+
published: wishlist.published,
|
|
1986
|
+
type: type,
|
|
1987
|
+
personType: wishlist.personType,
|
|
1988
|
+
personId: wishlist.personId,
|
|
1989
|
+
personName: wishlist.personName,
|
|
1990
|
+
personIsSubscriber: wishlist.personIsSubscriber,
|
|
1991
|
+
productId: product.id,
|
|
1992
|
+
productEAN: product.EAN,
|
|
1993
|
+
productSKU: product.sku,
|
|
1994
|
+
productName: product.name,
|
|
1995
|
+
productBrand: product.brand,
|
|
1996
|
+
},
|
|
1997
|
+
});
|
|
1998
|
+
break;
|
|
1999
|
+
default:
|
|
2000
|
+
break;
|
|
2001
|
+
}
|
|
2002
|
+
});
|
|
2003
|
+
}
|
|
2004
|
+
}
|
|
2005
|
+
WishlistService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: WishlistService, deps: [{ token: 'WishlistRepository' }, { token: DEFAULT_SHOP }, { token: 'ProductRepository' }, { token: 'CategoryFilterRepository' }, { token: 'CategoryRepository' }, { token: 'ProductStockNotificationRepository' }, { token: 'ProductSearch' }, { token: 'LogRepository' }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
2006
|
+
WishlistService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: WishlistService });
|
|
2007
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: WishlistService, decorators: [{
|
|
2008
|
+
type: Injectable
|
|
2009
|
+
}], ctorParameters: function () {
|
|
2010
|
+
return [{ type: undefined, decorators: [{
|
|
2011
|
+
type: Inject,
|
|
2012
|
+
args: ['WishlistRepository']
|
|
2013
|
+
}] }, { type: i1$3.Shops, decorators: [{
|
|
2014
|
+
type: Inject,
|
|
2015
|
+
args: [DEFAULT_SHOP]
|
|
2016
|
+
}] }, { type: undefined, decorators: [{
|
|
2017
|
+
type: Inject,
|
|
2018
|
+
args: ['ProductRepository']
|
|
2019
|
+
}] }, { type: undefined, decorators: [{
|
|
2020
|
+
type: Inject,
|
|
2021
|
+
args: ['CategoryFilterRepository']
|
|
2022
|
+
}] }, { type: undefined, decorators: [{
|
|
2023
|
+
type: Inject,
|
|
2024
|
+
args: ['CategoryRepository']
|
|
2025
|
+
}] }, { type: undefined, decorators: [{
|
|
2026
|
+
type: Inject,
|
|
2027
|
+
args: ['ProductStockNotificationRepository']
|
|
2028
|
+
}] }, { type: undefined, decorators: [{
|
|
2029
|
+
type: Inject,
|
|
2030
|
+
args: ['ProductSearch']
|
|
2031
|
+
}] }, { type: undefined, decorators: [{
|
|
2032
|
+
type: Inject,
|
|
2033
|
+
args: ['LogRepository']
|
|
2034
|
+
}] }];
|
|
2035
|
+
} });
|
|
2036
|
+
|
|
2037
|
+
class CouponService {
|
|
2038
|
+
constructor(couponRepository, defaultShop, orderRepository, categoryRepository) {
|
|
2039
|
+
this.couponRepository = couponRepository;
|
|
2040
|
+
this.defaultShop = defaultShop;
|
|
2041
|
+
this.orderRepository = orderRepository;
|
|
2042
|
+
this.categoryRepository = categoryRepository;
|
|
2043
|
+
this.emailIsFromCollaborator = (userEmail) => !!(userEmail === null || userEmail === void 0 ? void 0 : userEmail.match(/@b4a.com.br/g));
|
|
2044
|
+
}
|
|
2045
|
+
checkCoupon(nickname, checkoutType, checkout, plan) {
|
|
2046
|
+
return from(this.couponRepository
|
|
2047
|
+
.find({
|
|
2048
|
+
filters: {
|
|
2049
|
+
nickname: { operator: Where.EQUALS, value: nickname },
|
|
2050
|
+
active: { operator: Where.EQUALS, value: true },
|
|
2051
|
+
},
|
|
2052
|
+
})
|
|
2053
|
+
.then((result) => result.data[0])).pipe(concatMap((coupon) => this.couponValidation(coupon, checkoutType)), concatMap((couponValid) => this.couponRulesValidation(couponValid, checkoutType, checkout, plan)), map((couponValidated) => couponValidated));
|
|
2054
|
+
}
|
|
2055
|
+
couponValidation(coupon, checkoutType) {
|
|
2056
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
2057
|
+
if (!coupon)
|
|
2058
|
+
throw 'Cupom inválido.';
|
|
2059
|
+
if ((coupon === null || coupon === void 0 ? void 0 : coupon.beginAt) && (coupon === null || coupon === void 0 ? void 0 : coupon.beginAt.getTime()) > new Date().getTime())
|
|
2060
|
+
throw 'Cupom inválido.';
|
|
2061
|
+
if ((coupon === null || coupon === void 0 ? void 0 : coupon.expiresIn) && (coupon === null || coupon === void 0 ? void 0 : coupon.expiresIn).getTime() < new Date().getTime())
|
|
2062
|
+
throw 'Cupom expirado.';
|
|
2063
|
+
const isInShop = coupon.shopAvailability === Shops.ALL || coupon.shopAvailability === this.defaultShop;
|
|
2064
|
+
if (!isInShop)
|
|
2065
|
+
throw 'Cupom inválido para loja.';
|
|
2066
|
+
const isCheckoutType = coupon.checkoutType === CheckoutTypes.ALL || coupon.checkoutType === checkoutType;
|
|
2067
|
+
if (!isCheckoutType)
|
|
2068
|
+
throw 'Cupom inválido. Erro de checkout.';
|
|
2069
|
+
return coupon;
|
|
2070
|
+
});
|
|
2071
|
+
}
|
|
2072
|
+
couponRulesValidation(coupon, checkoutType, checkout, plan) {
|
|
2073
|
+
var _a;
|
|
2074
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
2075
|
+
if (checkoutType == CheckoutTypes.SUBSCRIPTION) {
|
|
2076
|
+
if (coupon.plan && coupon.plan.toUpperCase() !== plan.toUpperCase())
|
|
2077
|
+
throw 'Cupom inválido para sua assinatura.';
|
|
2078
|
+
return coupon;
|
|
2079
|
+
}
|
|
2080
|
+
const validUser = this.coupomUserValidation(coupon, checkout === null || checkout === void 0 ? void 0 : checkout.user);
|
|
2081
|
+
if (!validUser)
|
|
2082
|
+
throw 'Usuário não elegível.';
|
|
2083
|
+
const couponUseLimits = this.getCouponUseLimits(coupon, checkoutType, checkout.user);
|
|
2084
|
+
if (couponUseLimits.firstOrder) {
|
|
2085
|
+
const ordersUser = yield this.getOrdersFromUser(checkout.user.email.toLocaleLowerCase());
|
|
2086
|
+
if (couponUseLimits.firstOrder && ordersUser.length >= 1)
|
|
2087
|
+
throw 'Limite de uso atingido';
|
|
2088
|
+
}
|
|
2089
|
+
if (!couponUseLimits.unlimited || couponUseLimits.limitedPerUser) {
|
|
2090
|
+
const ordersCoupon = yield this.getOrdersWithCoupon(coupon);
|
|
2091
|
+
if (!couponUseLimits.unlimited && couponUseLimits.total && ordersCoupon.length >= couponUseLimits.total)
|
|
2092
|
+
throw 'Limite de uso atingido.';
|
|
2093
|
+
if (couponUseLimits.limitedPerUser) {
|
|
2094
|
+
const ordersWithUser = this.countOrdersWithUser(ordersCoupon, checkout.user.email);
|
|
2095
|
+
if (ordersWithUser > 0)
|
|
2096
|
+
throw 'Limite de uso por usuário atingido.';
|
|
2097
|
+
}
|
|
2098
|
+
}
|
|
2099
|
+
const hasProductCategories = yield this.hasProductCategories(coupon, checkout);
|
|
2100
|
+
if (!hasProductCategories)
|
|
2101
|
+
throw 'Seu carrinho não possui produtos elegíveis para desconto.';
|
|
2102
|
+
const hasMinSubTotal = yield this.hasMinSubTotal(coupon, checkout);
|
|
2103
|
+
if (!hasMinSubTotal) {
|
|
2104
|
+
if ((_a = coupon.productsCategories) === null || _a === void 0 ? void 0 : _a.length) {
|
|
2105
|
+
throw `Valor mínimo de ${Intl.NumberFormat('pt-BR', { style: 'currency', currency: 'BRL' }).format(coupon.minSubTotalValue)} não atingido na(s) categoria(s) elegíveis para o desconto.`;
|
|
2106
|
+
}
|
|
2107
|
+
throw `Valor mínimo de ${Intl.NumberFormat('pt-BR', { style: 'currency', currency: 'BRL' }).format(coupon.minSubTotalValue)} não atingido.`;
|
|
2108
|
+
}
|
|
2109
|
+
return coupon;
|
|
2110
|
+
});
|
|
2111
|
+
}
|
|
2112
|
+
calcDiscountSubscription(coupon, checkout) {
|
|
2113
|
+
let discount = 0;
|
|
2114
|
+
if (coupon.discount.subscription.type == CouponTypes.ABSOLUTE)
|
|
2115
|
+
discount = coupon.discount.subscription.value;
|
|
2116
|
+
else
|
|
2117
|
+
discount = checkout.subscriptionPlan.recurrencePrice * (coupon.discount.subscription.value / 100);
|
|
2118
|
+
return of(discount);
|
|
2119
|
+
}
|
|
2120
|
+
// public async calcDiscountShopping(
|
|
2121
|
+
// coupon: Coupon,
|
|
2122
|
+
// checkout: Partial<Checkout>,
|
|
2123
|
+
// ): Promise<{ discount: number; lineItems: LineItem[] }> {
|
|
2124
|
+
// let discountInfo: { discount: number; lineItems: LineItem[] } = null
|
|
2125
|
+
// if (checkout.user.isSubscriber && coupon.discount.subscriber.value) {
|
|
2126
|
+
// discountInfo = await this.calcDiscountByType(
|
|
2127
|
+
// coupon.discount.subscriber.type,
|
|
2128
|
+
// coupon.discount.subscriber.value,
|
|
2129
|
+
// coupon.productsCategories,
|
|
2130
|
+
// checkout,
|
|
2131
|
+
// )
|
|
2132
|
+
// } else {
|
|
2133
|
+
// discountInfo = await this.calcDiscountByType(
|
|
2134
|
+
// coupon.discount.non_subscriber.type,
|
|
2135
|
+
// coupon.discount.non_subscriber.value,
|
|
2136
|
+
// coupon.productsCategories,
|
|
2137
|
+
// checkout,
|
|
2138
|
+
// )
|
|
2139
|
+
// }
|
|
2140
|
+
// return { discount: discountInfo.discount, lineItems: discountInfo.lineItems }
|
|
2141
|
+
// }
|
|
2142
|
+
// private async calcDiscountByType(
|
|
2143
|
+
// type: CouponTypes,
|
|
2144
|
+
// value: number,
|
|
2145
|
+
// categories: string[],
|
|
2146
|
+
// checkout: Partial<Checkout>,
|
|
2147
|
+
// ): Promise<{ discount: number; lineItems: LineItem[] }> {
|
|
2148
|
+
// let discount = 0
|
|
2149
|
+
// if (type == CouponTypes.SHIPPING) {
|
|
2150
|
+
// const subTotal = checkout.shipping.ShippingPrice
|
|
2151
|
+
// const discount = +(subTotal * ((value > 100 ? 100 : value) / 100)).toFixed(2)
|
|
2152
|
+
// return { discount, lineItems: checkout.lineItems }
|
|
2153
|
+
// }
|
|
2154
|
+
// const lineItensElegibleForDiscount = await this.getLineItensEligebleForDiscount(categories, checkout)
|
|
2155
|
+
// const subTotal = this.calcCheckoutSubtotal(lineItensElegibleForDiscount, checkout.user)
|
|
2156
|
+
// if (type == CouponTypes.ABSOLUTE) {
|
|
2157
|
+
// discount = value > subTotal ? subTotal : value
|
|
2158
|
+
// } else {
|
|
2159
|
+
// discount = +(subTotal * ((value > 100 ? 100 : value) / 100)).toFixed(2)
|
|
2160
|
+
// }
|
|
2161
|
+
// const lineItems = this.calcLineItenDiscount(type, lineItensElegibleForDiscount, value, subTotal)
|
|
2162
|
+
// return { discount, lineItems }
|
|
2163
|
+
// }
|
|
2164
|
+
hasMinSubTotal(coupon, checkout) {
|
|
2165
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
2166
|
+
if (!coupon.minSubTotalValue)
|
|
2167
|
+
return true;
|
|
2168
|
+
const lineItensDiscount = yield this.getLineItensEligebleForDiscount(coupon.productsCategories, checkout);
|
|
2169
|
+
const subTotal = this.calcCheckoutSubtotal(lineItensDiscount, checkout.user);
|
|
2170
|
+
if (coupon.minSubTotalValue <= subTotal)
|
|
2171
|
+
return true;
|
|
2172
|
+
return false;
|
|
2173
|
+
});
|
|
2174
|
+
}
|
|
2175
|
+
hasProductCategories(coupon, checkout) {
|
|
2176
|
+
var _a, _b;
|
|
2304
2177
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2305
|
-
|
|
2306
|
-
|
|
2307
|
-
|
|
2178
|
+
if (!coupon.productsCategories || !((_a = coupon.productsCategories) === null || _a === void 0 ? void 0 : _a.length)) {
|
|
2179
|
+
return true;
|
|
2180
|
+
}
|
|
2181
|
+
const couponCategories = yield this.getCouponCategoriesId(coupon.productsCategories);
|
|
2182
|
+
const hasCategories = (_b = checkout.lineItems) === null || _b === void 0 ? void 0 : _b.filter((item) => {
|
|
2183
|
+
var _a;
|
|
2184
|
+
if (item.isGift)
|
|
2185
|
+
return false;
|
|
2186
|
+
if (!item.categories || !((_a = item.categories) === null || _a === void 0 ? void 0 : _a.length))
|
|
2187
|
+
return true;
|
|
2188
|
+
return item.categories.some((c) => couponCategories.some((cat) => cat == c));
|
|
2189
|
+
});
|
|
2190
|
+
return hasCategories.length ? true : false;
|
|
2308
2191
|
});
|
|
2309
2192
|
}
|
|
2310
|
-
|
|
2311
|
-
|
|
2312
|
-
|
|
2313
|
-
|
|
2314
|
-
|
|
2315
|
-
|
|
2316
|
-
|
|
2317
|
-
|
|
2193
|
+
coupomUserValidation(coupon, user) {
|
|
2194
|
+
if (!user || coupon.exclusivityType.includes(Exclusivities.ALL_USERS))
|
|
2195
|
+
return true;
|
|
2196
|
+
let userTypes = [];
|
|
2197
|
+
if (coupon.exclusivityType.includes(Exclusivities.COLLABORATORS) &&
|
|
2198
|
+
this.emailIsFromCollaborator(user.email.toLocaleLowerCase()))
|
|
2199
|
+
userTypes.push(Exclusivities.COLLABORATORS);
|
|
2200
|
+
if (coupon.exclusivityType.includes(Exclusivities.SPECIFIC_USER) &&
|
|
2201
|
+
coupon.userExclusiveEmail.includes(user.email.toLocaleLowerCase()))
|
|
2202
|
+
userTypes.push(Exclusivities.SPECIFIC_USER);
|
|
2203
|
+
if (coupon.exclusivityType.includes(Exclusivities.ACTIVE_SUBSCRIBER) &&
|
|
2204
|
+
user.isSubscriber &&
|
|
2205
|
+
user.subscriptionPlan != '')
|
|
2206
|
+
userTypes.push(Exclusivities.ACTIVE_SUBSCRIBER);
|
|
2207
|
+
if (user.isSubscriber &&
|
|
2208
|
+
user.subscriptionPlan == '' &&
|
|
2209
|
+
coupon.exclusivityType.includes(Exclusivities.INACTIVE_SUBSCRIBER))
|
|
2210
|
+
userTypes.push(Exclusivities.INACTIVE_SUBSCRIBER);
|
|
2211
|
+
if (coupon.exclusivityType.includes(Exclusivities.NON_SUBSCRIBER) && !user.isSubscriber)
|
|
2212
|
+
userTypes.push(Exclusivities.NON_SUBSCRIBER);
|
|
2213
|
+
return coupon.exclusivityType.some((r) => userTypes.includes(r));
|
|
2318
2214
|
}
|
|
2319
|
-
|
|
2215
|
+
getCouponCategoriesId(productsCategories) {
|
|
2320
2216
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2321
|
-
const
|
|
2322
|
-
|
|
2323
|
-
|
|
2324
|
-
|
|
2325
|
-
|
|
2326
|
-
|
|
2327
|
-
|
|
2328
|
-
|
|
2217
|
+
const couponCategories = [];
|
|
2218
|
+
for (let index = 0; index < productsCategories.length; index++) {
|
|
2219
|
+
const category = yield this.categoryRepository.get({
|
|
2220
|
+
id: productsCategories[index],
|
|
2221
|
+
});
|
|
2222
|
+
if (category) {
|
|
2223
|
+
const children = yield this.categoryRepository.getChildren(parseInt(productsCategories[index]));
|
|
2224
|
+
couponCategories.push(category.id, ...children.map((c) => c.id.toString()));
|
|
2225
|
+
}
|
|
2329
2226
|
}
|
|
2330
|
-
return
|
|
2227
|
+
return [...new Set(couponCategories)];
|
|
2331
2228
|
});
|
|
2332
2229
|
}
|
|
2333
|
-
|
|
2230
|
+
getLineItensEligebleForDiscount(productsCategories, checkout) {
|
|
2231
|
+
var _a;
|
|
2334
2232
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2335
|
-
|
|
2336
|
-
const
|
|
2337
|
-
if (
|
|
2338
|
-
|
|
2339
|
-
|
|
2340
|
-
|
|
2341
|
-
|
|
2342
|
-
|
|
2233
|
+
let lineItensDiscount = [];
|
|
2234
|
+
const couponCategories = yield this.getCouponCategoriesId(productsCategories);
|
|
2235
|
+
if (productsCategories && productsCategories.length) {
|
|
2236
|
+
lineItensDiscount = (_a = checkout.lineItems) === null || _a === void 0 ? void 0 : _a.filter((item) => {
|
|
2237
|
+
var _a;
|
|
2238
|
+
if (item.isGift)
|
|
2239
|
+
return false;
|
|
2240
|
+
if ((_a = item.categories) === null || _a === void 0 ? void 0 : _a.length) {
|
|
2241
|
+
return item.categories.some((c) => couponCategories.some((cat) => cat == c));
|
|
2242
|
+
}
|
|
2243
|
+
return true;
|
|
2244
|
+
});
|
|
2343
2245
|
}
|
|
2344
|
-
|
|
2246
|
+
else {
|
|
2247
|
+
lineItensDiscount = checkout.lineItems.filter((item) => !item.isGift);
|
|
2248
|
+
}
|
|
2249
|
+
return lineItensDiscount;
|
|
2345
2250
|
});
|
|
2346
2251
|
}
|
|
2347
|
-
|
|
2252
|
+
calcCheckoutSubtotal(lineItens, user) {
|
|
2253
|
+
return ((lineItens === null || lineItens === void 0 ? void 0 : lineItens.filter((item) => !item.isGift).reduce((acc, curr) => {
|
|
2254
|
+
var _a;
|
|
2255
|
+
return (user === null || user === void 0 ? void 0 : user.isSubscriber) && curr.price.subscriberPrice
|
|
2256
|
+
? acc + ((_a = curr.price) === null || _a === void 0 ? void 0 : _a.subscriberPrice) * curr.quantity
|
|
2257
|
+
: acc + curr.pricePaid * curr.quantity;
|
|
2258
|
+
}, 0)) || 0);
|
|
2259
|
+
}
|
|
2260
|
+
getOrdersWithCoupon(coupon) {
|
|
2348
2261
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2349
|
-
return this.
|
|
2262
|
+
return yield this.orderRepository
|
|
2350
2263
|
.find({
|
|
2351
|
-
fields: ['id', 'name', 'description', 'personId', 'personIsSubscriber', 'personType', 'personName'],
|
|
2352
2264
|
filters: {
|
|
2353
|
-
id,
|
|
2265
|
+
coupon: { id: coupon.id },
|
|
2266
|
+
status: { operator: Where.NOTEQUALS, value: OrderStatus.CANCELADO },
|
|
2354
2267
|
},
|
|
2355
2268
|
})
|
|
2356
|
-
.then((
|
|
2269
|
+
.then((result) => result.data);
|
|
2357
2270
|
});
|
|
2358
2271
|
}
|
|
2359
|
-
|
|
2272
|
+
getOrdersFromUser(email) {
|
|
2360
2273
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2361
|
-
return this.
|
|
2274
|
+
return yield this.orderRepository
|
|
2362
2275
|
.find({
|
|
2363
|
-
fields: ['id', 'sku', 'EAN', 'name', 'brand'],
|
|
2364
2276
|
filters: {
|
|
2365
|
-
|
|
2277
|
+
user: { email: { operator: Where.EQUALS, value: email } },
|
|
2278
|
+
status: { operator: Where.NOTEQUALS, value: OrderStatus.CANCELADO },
|
|
2366
2279
|
},
|
|
2367
2280
|
})
|
|
2368
|
-
.then((
|
|
2281
|
+
.then((result) => result.data);
|
|
2369
2282
|
});
|
|
2370
2283
|
}
|
|
2371
|
-
|
|
2372
|
-
return
|
|
2373
|
-
|
|
2374
|
-
|
|
2375
|
-
|
|
2376
|
-
|
|
2377
|
-
|
|
2378
|
-
|
|
2379
|
-
|
|
2380
|
-
|
|
2381
|
-
|
|
2382
|
-
|
|
2383
|
-
|
|
2384
|
-
|
|
2385
|
-
|
|
2386
|
-
|
|
2387
|
-
|
|
2388
|
-
type: type,
|
|
2389
|
-
personType: wishlist.personType,
|
|
2390
|
-
personId: wishlist.personId,
|
|
2391
|
-
personName: wishlist.personName,
|
|
2392
|
-
personIsSubscriber: wishlist.personIsSubscriber,
|
|
2393
|
-
},
|
|
2394
|
-
});
|
|
2395
|
-
break;
|
|
2396
|
-
case WishlistLogType.ADD_PRODUCT:
|
|
2397
|
-
case WishlistLogType.REMOVE_PRODUCT:
|
|
2398
|
-
yield this.logRepository.create({
|
|
2399
|
-
collection: 'wishlist',
|
|
2400
|
-
date: new Date(),
|
|
2401
|
-
operation: 'UPDATE',
|
|
2402
|
-
documentId: wishlist.id,
|
|
2403
|
-
document: {
|
|
2404
|
-
id: wishlist.id,
|
|
2405
|
-
shop: this.shop,
|
|
2406
|
-
name: wishlist.name,
|
|
2407
|
-
description: wishlist.description,
|
|
2408
|
-
published: wishlist.published,
|
|
2409
|
-
type: type,
|
|
2410
|
-
personType: wishlist.personType,
|
|
2411
|
-
personId: wishlist.personId,
|
|
2412
|
-
personName: wishlist.personName,
|
|
2413
|
-
personIsSubscriber: wishlist.personIsSubscriber,
|
|
2414
|
-
productId: product.id,
|
|
2415
|
-
productEAN: product.EAN,
|
|
2416
|
-
productSKU: product.sku,
|
|
2417
|
-
productName: product.name,
|
|
2418
|
-
productBrand: product.brand,
|
|
2419
|
-
},
|
|
2420
|
-
});
|
|
2421
|
-
break;
|
|
2422
|
-
default:
|
|
2423
|
-
break;
|
|
2424
|
-
}
|
|
2425
|
-
});
|
|
2284
|
+
countOrdersWithUser(orders, email) {
|
|
2285
|
+
return orders.filter((o) => o.user.email == email).length;
|
|
2286
|
+
}
|
|
2287
|
+
getCouponUseLimits(coupon, checkoutType, user) {
|
|
2288
|
+
let couponUseLimits;
|
|
2289
|
+
if (checkoutType == CheckoutTypes.ECOMMERCE || checkoutType == CheckoutTypes.ALL) {
|
|
2290
|
+
if (coupon.exclusivityType.length === 1 &&
|
|
2291
|
+
(coupon.exclusivityType.at(0) === Exclusivities.SPECIFIC_USER ||
|
|
2292
|
+
coupon.exclusivityType.at(0) === Exclusivities.COLLABORATORS))
|
|
2293
|
+
couponUseLimits = coupon.useLimits.non_subscriber;
|
|
2294
|
+
else
|
|
2295
|
+
couponUseLimits = user && user.isSubscriber ? coupon.useLimits.subscriber : coupon.useLimits.non_subscriber;
|
|
2296
|
+
}
|
|
2297
|
+
else {
|
|
2298
|
+
couponUseLimits = coupon.useLimits.subscription;
|
|
2299
|
+
}
|
|
2300
|
+
return couponUseLimits;
|
|
2426
2301
|
}
|
|
2427
2302
|
}
|
|
2428
|
-
|
|
2429
|
-
|
|
2430
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type:
|
|
2431
|
-
type: Injectable
|
|
2303
|
+
CouponService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CouponService, deps: [{ token: 'CouponRepository' }, { token: DEFAULT_SHOP }, { token: 'OrderRepository' }, { token: 'CategoryRepository' }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
2304
|
+
CouponService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CouponService, providedIn: 'root' });
|
|
2305
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CouponService, decorators: [{
|
|
2306
|
+
type: Injectable,
|
|
2307
|
+
args: [{
|
|
2308
|
+
providedIn: 'root',
|
|
2309
|
+
}]
|
|
2432
2310
|
}], ctorParameters: function () {
|
|
2433
2311
|
return [{ type: undefined, decorators: [{
|
|
2434
2312
|
type: Inject,
|
|
2435
|
-
args: ['
|
|
2436
|
-
}] }, { type: i1$
|
|
2313
|
+
args: ['CouponRepository']
|
|
2314
|
+
}] }, { type: i1$3.Shops, decorators: [{
|
|
2437
2315
|
type: Inject,
|
|
2438
2316
|
args: [DEFAULT_SHOP]
|
|
2439
2317
|
}] }, { type: undefined, decorators: [{
|
|
2440
2318
|
type: Inject,
|
|
2441
|
-
args: ['
|
|
2442
|
-
}] }, { type: undefined, decorators: [{
|
|
2443
|
-
type: Inject,
|
|
2444
|
-
args: ['CategoryFilterRepository']
|
|
2319
|
+
args: ['OrderRepository']
|
|
2445
2320
|
}] }, { type: undefined, decorators: [{
|
|
2446
2321
|
type: Inject,
|
|
2447
2322
|
args: ['CategoryRepository']
|
|
2448
|
-
}] }, { type: undefined, decorators: [{
|
|
2449
|
-
type: Inject,
|
|
2450
|
-
args: ['ProductStockNotificationRepository']
|
|
2451
|
-
}] }, { type: undefined, decorators: [{
|
|
2452
|
-
type: Inject,
|
|
2453
|
-
args: ['ProductSearch']
|
|
2454
|
-
}] }, { type: undefined, decorators: [{
|
|
2455
|
-
type: Inject,
|
|
2456
|
-
args: ['LogRepository']
|
|
2457
2323
|
}] }];
|
|
2458
2324
|
} });
|
|
2459
2325
|
|
|
@@ -2633,7 +2499,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImpor
|
|
|
2633
2499
|
}] }, { type: undefined, decorators: [{
|
|
2634
2500
|
type: Inject,
|
|
2635
2501
|
args: ['ProductRepository']
|
|
2636
|
-
}] }, { type: i1$
|
|
2502
|
+
}] }, { type: i1$3.Shops, decorators: [{
|
|
2637
2503
|
type: Inject,
|
|
2638
2504
|
args: [DEFAULT_SHOP]
|
|
2639
2505
|
}] }];
|
|
@@ -2657,100 +2523,12 @@ OrderService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version
|
|
|
2657
2523
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: OrderService, decorators: [{
|
|
2658
2524
|
type: Injectable
|
|
2659
2525
|
}], ctorParameters: function () {
|
|
2660
|
-
return [{ type: i1$1.Firestore }, { type: i1$
|
|
2526
|
+
return [{ type: i1$1.Firestore }, { type: i1$3.OrderFirestoreRepository, decorators: [{
|
|
2661
2527
|
type: Inject,
|
|
2662
2528
|
args: ['OrderRepository']
|
|
2663
2529
|
}] }];
|
|
2664
2530
|
} });
|
|
2665
2531
|
|
|
2666
|
-
class ShippingService {
|
|
2667
|
-
constructor(http, apiUrl, homeService) {
|
|
2668
|
-
this.http = http;
|
|
2669
|
-
this.apiUrl = apiUrl;
|
|
2670
|
-
this.homeService = homeService;
|
|
2671
|
-
}
|
|
2672
|
-
getShippingMethods(shop, zip, weightGrams, totalPrice, personId, subscriptionPlan) {
|
|
2673
|
-
return combineLatest([
|
|
2674
|
-
this.homeService.getHomeData(),
|
|
2675
|
-
this.http.get(`${this.apiUrl}open/checkshippingcompany?personId=${personId}&postalCode=${zip}&weightGrams=${weightGrams}`),
|
|
2676
|
-
]).pipe(map(([datas, shippingMethodsResponse]) => {
|
|
2677
|
-
let shippingMethods = shippingMethodsResponse.result;
|
|
2678
|
-
if (!shippingMethods.length)
|
|
2679
|
-
return [];
|
|
2680
|
-
shippingMethods = shippingMethods.map((shippingMethod) => {
|
|
2681
|
-
if (shippingMethod.ShippingCompanyName == 'Same Day EG')
|
|
2682
|
-
shippingMethod.ShippingCompanyName = 'Same Day';
|
|
2683
|
-
return shippingMethod;
|
|
2684
|
-
});
|
|
2685
|
-
const datasSameDayNotAvaliable = datas.sameDayNotAvaliable;
|
|
2686
|
-
if (this.isHolidays(datasSameDayNotAvaliable)) {
|
|
2687
|
-
shippingMethods = shippingMethods.filter((method) => method.serviceName !== 'Same Day');
|
|
2688
|
-
}
|
|
2689
|
-
if (totalPrice >= 200) {
|
|
2690
|
-
shippingMethods = shippingMethods.map((s) => {
|
|
2691
|
-
if (s.serviceName !== 'Same Day')
|
|
2692
|
-
return Object.assign(Object.assign({}, s), { totalPrice: 0 });
|
|
2693
|
-
else
|
|
2694
|
-
return s;
|
|
2695
|
-
});
|
|
2696
|
-
}
|
|
2697
|
-
if (shop == Shops.GLAMSHOP)
|
|
2698
|
-
return shippingMethods;
|
|
2699
|
-
if (this.isFreeShippingBySubscription(shop, subscriptionPlan)) {
|
|
2700
|
-
shippingMethods = shippingMethods.map((s) => {
|
|
2701
|
-
if (s.serviceName == 'Same Day')
|
|
2702
|
-
return Object.assign(Object.assign({}, s), { totalPrice: s.totalPrice / 2 });
|
|
2703
|
-
else
|
|
2704
|
-
return Object.assign(Object.assign({}, s), { totalPrice: 0 });
|
|
2705
|
-
});
|
|
2706
|
-
}
|
|
2707
|
-
if (this.isHalfShippingBySubscription(shop, subscriptionPlan)) {
|
|
2708
|
-
shippingMethods = shippingMethods.map((s) => {
|
|
2709
|
-
return Object.assign(Object.assign({}, s), { totalPrice: s.totalPrice / 2 });
|
|
2710
|
-
});
|
|
2711
|
-
}
|
|
2712
|
-
return shippingMethods;
|
|
2713
|
-
}));
|
|
2714
|
-
}
|
|
2715
|
-
isFreeShippingBySubscription(shop, subscriptionPlan) {
|
|
2716
|
-
if (!subscriptionPlan)
|
|
2717
|
-
return false;
|
|
2718
|
-
if (shop == Shops.MENSMARKET && subscriptionPlan == 'SELECT')
|
|
2719
|
-
return true;
|
|
2720
|
-
return false;
|
|
2721
|
-
}
|
|
2722
|
-
isHalfShippingBySubscription(shop, subscriptionPlan) {
|
|
2723
|
-
if (!subscriptionPlan)
|
|
2724
|
-
return false;
|
|
2725
|
-
if (shop == Shops.MENSMARKET && subscriptionPlan == 'PRIME') {
|
|
2726
|
-
return true;
|
|
2727
|
-
}
|
|
2728
|
-
return false;
|
|
2729
|
-
}
|
|
2730
|
-
isHolidays(datas) {
|
|
2731
|
-
const today = new Date();
|
|
2732
|
-
for (const key in datas) {
|
|
2733
|
-
let start = new Date(`${today.getFullYear()}-${datas[key].beginDate}`);
|
|
2734
|
-
let end = new Date(`${today.getFullYear()}-${datas[key].endDate}`);
|
|
2735
|
-
if (start > end)
|
|
2736
|
-
end = new Date(`${today.getFullYear() + 1}-${datas[key].endDate}`);
|
|
2737
|
-
if (today >= start && today <= end)
|
|
2738
|
-
return true;
|
|
2739
|
-
}
|
|
2740
|
-
return false;
|
|
2741
|
-
}
|
|
2742
|
-
}
|
|
2743
|
-
ShippingService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: ShippingService, deps: [{ token: i3.HttpClient }, { token: BACKEND_URL }, { token: HomeShopService }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
2744
|
-
ShippingService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: ShippingService });
|
|
2745
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: ShippingService, decorators: [{
|
|
2746
|
-
type: Injectable
|
|
2747
|
-
}], ctorParameters: function () {
|
|
2748
|
-
return [{ type: i3.HttpClient }, { type: undefined, decorators: [{
|
|
2749
|
-
type: Inject,
|
|
2750
|
-
args: [BACKEND_URL]
|
|
2751
|
-
}] }, { type: HomeShopService }];
|
|
2752
|
-
} });
|
|
2753
|
-
|
|
2754
2532
|
class AngularConnectModule {
|
|
2755
2533
|
static initializeApp(defaultShop, options, nameOrConfig) {
|
|
2756
2534
|
return {
|
|
@@ -2776,7 +2554,7 @@ class AngularConnectModule {
|
|
|
2776
2554
|
}
|
|
2777
2555
|
}
|
|
2778
2556
|
AngularConnectModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: AngularConnectModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
|
|
2779
|
-
AngularConnectModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.1.0", ngImport: i0, type: AngularConnectModule, imports: [i1$
|
|
2557
|
+
AngularConnectModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.1.0", ngImport: i0, type: AngularConnectModule, imports: [i1$4.FirebaseAppModule, i2.StorageModule, AngularElasticSeachModule,
|
|
2780
2558
|
AngularVertexSeachModule,
|
|
2781
2559
|
AngularFirebaseAuthModule,
|
|
2782
2560
|
AngularFirestoreModule,
|
|
@@ -2791,7 +2569,6 @@ AngularConnectModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", ve
|
|
|
2791
2569
|
CouponService,
|
|
2792
2570
|
HomeShopService,
|
|
2793
2571
|
OrderService,
|
|
2794
|
-
ShippingService,
|
|
2795
2572
|
WishlistService,
|
|
2796
2573
|
{
|
|
2797
2574
|
provide: UpdateUserImage,
|
|
@@ -2856,7 +2633,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImpor
|
|
|
2856
2633
|
CouponService,
|
|
2857
2634
|
HomeShopService,
|
|
2858
2635
|
OrderService,
|
|
2859
|
-
ShippingService,
|
|
2860
2636
|
WishlistService,
|
|
2861
2637
|
{
|
|
2862
2638
|
provide: UpdateUserImage,
|
|
@@ -2884,5 +2660,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.0", ngImpor
|
|
|
2884
2660
|
* Generated bundle index. Do not edit.
|
|
2885
2661
|
*/
|
|
2886
2662
|
|
|
2887
|
-
export { AngularConnectModule, AngularFirebaseAuthModule, AngularFirestoreModule, AngularHasuraGraphQLModule, AuthService, CartService, CatalogService, CategoryService, CategoryWithTree, CheckoutService, CheckoutSubscriptionService, CookieDataPersistence, CouponService, HomeShopService, NewCategoryStructureAdapter, OldCategoryStructureAdapter, OrderService, ProductSorts,
|
|
2663
|
+
export { AngularConnectModule, AngularFirebaseAuthModule, AngularFirestoreModule, AngularHasuraGraphQLModule, AuthService, CartService, CatalogService, CategoryService, CategoryWithTree, CheckoutService, CheckoutSubscriptionService, CookieDataPersistence, CouponService, HomeShopService, NewCategoryStructureAdapter, OldCategoryStructureAdapter, OrderService, ProductSorts, UtilHelper, WishlistService };
|
|
2888
2664
|
//# sourceMappingURL=infrab4a-connect-angular.mjs.map
|