@infrab4a/connect-angular 4.4.2-beta.2 → 4.4.3-beta.0
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 +1 -2
- package/esm2020/services/catalog/wishlist.service.mjs +5 -4
- package/esm2020/services/coupon.service.mjs +10 -37
- package/fesm2015/infrab4a-connect-angular.mjs +13 -34
- package/fesm2015/infrab4a-connect-angular.mjs.map +1 -1
- package/fesm2020/infrab4a-connect-angular.mjs +13 -40
- package/fesm2020/infrab4a-connect-angular.mjs.map +1 -1
- package/package.json +2 -2
- package/services/catalog/wishlist.service.d.ts +4 -2
- package/services/checkout.service.d.ts +1 -4
- package/services/coupon.service.d.ts +2 -6
|
@@ -1054,33 +1054,32 @@ class CouponService {
|
|
|
1054
1054
|
return of(discount);
|
|
1055
1055
|
}
|
|
1056
1056
|
async calcDiscountShopping(coupon, checkout) {
|
|
1057
|
-
let
|
|
1057
|
+
let discount = 0;
|
|
1058
1058
|
if (checkout.user.isSubscriber && coupon.discount.subscriber.value) {
|
|
1059
|
-
|
|
1059
|
+
discount = await this.calcDiscountByType(coupon.discount.subscriber.type, coupon.discount.subscriber.value, coupon.productsCategories, checkout);
|
|
1060
1060
|
}
|
|
1061
1061
|
else {
|
|
1062
|
-
|
|
1062
|
+
discount = await this.calcDiscountByType(coupon.discount.non_subscriber.type, coupon.discount.non_subscriber.value, coupon.productsCategories, checkout);
|
|
1063
1063
|
}
|
|
1064
|
-
return
|
|
1064
|
+
return discount;
|
|
1065
1065
|
}
|
|
1066
1066
|
async calcDiscountByType(type, value, categories, checkout) {
|
|
1067
1067
|
let discount = 0;
|
|
1068
|
-
let
|
|
1069
|
-
const subTotal = this.calcCheckoutSubtotal(
|
|
1068
|
+
let lineItensDiscount = await this.getLineItensEligebleForDiscount(categories, checkout);
|
|
1069
|
+
const subTotal = this.calcCheckoutSubtotal(lineItensDiscount, checkout.user, checkout.shop);
|
|
1070
1070
|
if (type == CouponTypes.ABSOLUTE) {
|
|
1071
1071
|
discount = value > subTotal ? subTotal : value;
|
|
1072
1072
|
}
|
|
1073
1073
|
else {
|
|
1074
1074
|
discount = subTotal * (value / 100);
|
|
1075
1075
|
}
|
|
1076
|
-
|
|
1077
|
-
return { discount, lineItems };
|
|
1076
|
+
return discount;
|
|
1078
1077
|
}
|
|
1079
1078
|
async hasMinSubTotal(coupon, checkout) {
|
|
1080
1079
|
if (!coupon.minSubTotalValue)
|
|
1081
1080
|
return true;
|
|
1082
1081
|
let lineItensDiscount = await this.getLineItensEligebleForDiscount(coupon.productsCategories, checkout);
|
|
1083
|
-
const subTotal = this.calcCheckoutSubtotal(lineItensDiscount, checkout.user);
|
|
1082
|
+
const subTotal = this.calcCheckoutSubtotal(lineItensDiscount, checkout.user, checkout.shop);
|
|
1084
1083
|
if (coupon.minSubTotalValue <= subTotal)
|
|
1085
1084
|
return true;
|
|
1086
1085
|
return false;
|
|
@@ -1148,7 +1147,7 @@ class CouponService {
|
|
|
1148
1147
|
}
|
|
1149
1148
|
return lineItensDiscount;
|
|
1150
1149
|
}
|
|
1151
|
-
calcCheckoutSubtotal(lineItens, user) {
|
|
1150
|
+
calcCheckoutSubtotal(lineItens, user, shop) {
|
|
1152
1151
|
return (lineItens?.reduce((acc, curr) => user?.isSubscriber && curr.price.subscriberPrice
|
|
1153
1152
|
? acc + curr.price?.subscriberPrice * curr.quantity
|
|
1154
1153
|
: acc + curr.pricePaid * curr.quantity, 0) || 0);
|
|
@@ -1186,32 +1185,6 @@ class CouponService {
|
|
|
1186
1185
|
}
|
|
1187
1186
|
return couponUseLimits;
|
|
1188
1187
|
}
|
|
1189
|
-
calcLineItenDiscount(type, lineItems, couponDiscount, subTotal) {
|
|
1190
|
-
let lineItemsDiscount = [];
|
|
1191
|
-
if (type === CouponTypes.ABSOLUTE) {
|
|
1192
|
-
const couponDiscountMax = couponDiscount > subTotal ? subTotal : couponDiscount;
|
|
1193
|
-
lineItemsDiscount = lineItems.map((item) => {
|
|
1194
|
-
const totalItemPercentage = item.pricePaid / subTotal;
|
|
1195
|
-
const discountItem = couponDiscountMax * totalItemPercentage;
|
|
1196
|
-
console.log(item.name, item.pricePaid, subTotal, 'absolute', couponDiscountMax, totalItemPercentage, discountItem);
|
|
1197
|
-
return {
|
|
1198
|
-
...item,
|
|
1199
|
-
discount: Number(discountItem.toFixed(2)),
|
|
1200
|
-
};
|
|
1201
|
-
});
|
|
1202
|
-
}
|
|
1203
|
-
else {
|
|
1204
|
-
lineItemsDiscount = lineItems.map((item) => {
|
|
1205
|
-
const discountItem = item.pricePaid * (couponDiscount / 100);
|
|
1206
|
-
console.log(item.name, item.pricePaid, 'percentage', couponDiscount, discountItem);
|
|
1207
|
-
return {
|
|
1208
|
-
...item,
|
|
1209
|
-
discount: Number(discountItem.toFixed(2)),
|
|
1210
|
-
};
|
|
1211
|
-
});
|
|
1212
|
-
}
|
|
1213
|
-
return lineItemsDiscount;
|
|
1214
|
-
}
|
|
1215
1188
|
}
|
|
1216
1189
|
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 });
|
|
1217
1190
|
CouponService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.1.0", ngImport: i0, type: CouponService, providedIn: 'root' });
|
|
@@ -1352,7 +1325,6 @@ class CartService {
|
|
|
1352
1325
|
weight: weight ?? product.weight,
|
|
1353
1326
|
quantity: (item.quantity || 0) + (quantity || 0),
|
|
1354
1327
|
pricePaid,
|
|
1355
|
-
discount: 0,
|
|
1356
1328
|
categories: product.categories ?? [],
|
|
1357
1329
|
isGift: isGift ?? null,
|
|
1358
1330
|
costPrice: product.costPrice ?? 0,
|
|
@@ -1891,7 +1863,7 @@ class WishlistService {
|
|
|
1891
1863
|
getCategoryService() {
|
|
1892
1864
|
return this.categoryService;
|
|
1893
1865
|
}
|
|
1894
|
-
async create({ personId, title, description, userFullName, userPhoto, theme, bannerUrl, }) {
|
|
1866
|
+
async create({ personId, title, description, published, userFullName, userPhoto, theme, bannerUrl, }) {
|
|
1895
1867
|
const data = {
|
|
1896
1868
|
slug: '',
|
|
1897
1869
|
name: title,
|
|
@@ -1906,7 +1878,7 @@ class WishlistService {
|
|
|
1906
1878
|
personName: userFullName,
|
|
1907
1879
|
personPhoto: userPhoto,
|
|
1908
1880
|
brandCategory: false,
|
|
1909
|
-
published
|
|
1881
|
+
published,
|
|
1910
1882
|
theme,
|
|
1911
1883
|
bannerUrl,
|
|
1912
1884
|
};
|
|
@@ -1914,11 +1886,12 @@ class WishlistService {
|
|
|
1914
1886
|
await this.wishlistRepository.update({ id: newWishlist.id, slug: newWishlist.id });
|
|
1915
1887
|
return Wishlist.toInstance({ ...newWishlist.toPlain(), slug: newWishlist.id });
|
|
1916
1888
|
}
|
|
1917
|
-
update({ id, title, description, userFullName, userPhoto, theme, bannerUrl, }) {
|
|
1889
|
+
update({ id, title, description, published, userFullName, userPhoto, theme, bannerUrl, }) {
|
|
1918
1890
|
const data = {
|
|
1919
1891
|
id,
|
|
1920
1892
|
name: title,
|
|
1921
1893
|
description,
|
|
1894
|
+
published,
|
|
1922
1895
|
metadata: {
|
|
1923
1896
|
title: `${userFullName} - ${title}`,
|
|
1924
1897
|
description: `${userFullName} - ${description}`,
|