rerobe-js-orm 2.7.27 → 2.7.29
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.
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
export default class ReRobeProductHelpers {
|
|
2
2
|
static calculateProductionFee(commission: number): number;
|
|
3
3
|
static calculateFulfillmentFee(commission: number): number;
|
|
4
|
+
static calculateSalePrice(productObj: CompleteProduct): string;
|
|
4
5
|
static isValidCommission(commission: any): boolean;
|
|
5
6
|
static commissionFixer(commisssion: any): string;
|
|
7
|
+
static isValidSalePrice(productObj: CompleteProduct): boolean;
|
|
6
8
|
static buildReRobeEarnings(arrayLike: CompleteProduct | CompleteProduct[]): number[];
|
|
7
|
-
static buildReRobeEarningsV2(arrayLike: CompleteProduct | CompleteProduct[]): number[];
|
|
9
|
+
static buildReRobeEarningsV2(arrayLike: CompleteProduct | CompleteProduct[], isCanonicalMerchant?: boolean): number[];
|
|
8
10
|
static materialCompJoinedString(materialComposition?: MaterialComposition): string;
|
|
9
11
|
static measurementsJoinedString(measurementsObj?: Measurements): string;
|
|
10
12
|
static sizeCommentPretty(sizeComment: string): string;
|
|
@@ -20,6 +20,24 @@ class ReRobeProductHelpers {
|
|
|
20
20
|
}
|
|
21
21
|
return 0;
|
|
22
22
|
}
|
|
23
|
+
static calculateSalePrice(productObj) {
|
|
24
|
+
const { discountType, discountValue, price, isOnSale } = productObj;
|
|
25
|
+
const dt = discountType || 'percentage';
|
|
26
|
+
const dv = discountValue || '0';
|
|
27
|
+
if (!price) {
|
|
28
|
+
return '';
|
|
29
|
+
}
|
|
30
|
+
if (!isOnSale || isOnSale === 'no') {
|
|
31
|
+
return '';
|
|
32
|
+
}
|
|
33
|
+
if (dt === 'percentage') {
|
|
34
|
+
return (Number(price) * (1 - Number(dv))).toFixed(2);
|
|
35
|
+
}
|
|
36
|
+
if (dt === 'amount') {
|
|
37
|
+
return (Number(price) - Number(dv)).toFixed(2);
|
|
38
|
+
}
|
|
39
|
+
return '';
|
|
40
|
+
}
|
|
23
41
|
static isValidCommission(commission) {
|
|
24
42
|
if (typeof commission === 'string' &&
|
|
25
43
|
!!commission &&
|
|
@@ -42,6 +60,14 @@ class ReRobeProductHelpers {
|
|
|
42
60
|
}
|
|
43
61
|
return String(Math.abs(Number(fix)));
|
|
44
62
|
}
|
|
63
|
+
static isValidSalePrice(productObj) {
|
|
64
|
+
const { salePrice } = productObj;
|
|
65
|
+
const calculatedSalePrice = this.calculateSalePrice(productObj);
|
|
66
|
+
if (salePrice !== calculatedSalePrice) {
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
return true;
|
|
70
|
+
}
|
|
45
71
|
static buildReRobeEarnings(arrayLike) {
|
|
46
72
|
const products = Array.isArray(arrayLike) ? arrayLike : [arrayLike];
|
|
47
73
|
return products.reduce((acc, cur) => {
|
|
@@ -55,17 +81,17 @@ class ReRobeProductHelpers {
|
|
|
55
81
|
return [inventoryValue, listingFeeEarnings, productionFeeEarnings, fulfillmentFeeEarnings];
|
|
56
82
|
}, [0, 0, 0, 0]);
|
|
57
83
|
}
|
|
58
|
-
static buildReRobeEarningsV2(arrayLike) {
|
|
84
|
+
static buildReRobeEarningsV2(arrayLike, isCanonicalMerchant) {
|
|
59
85
|
const products = Array.isArray(arrayLike) ? arrayLike : [arrayLike];
|
|
60
86
|
return products.reduce((acc, cur) => {
|
|
61
87
|
const commission = cur.reRobeCommission ? Number(this.commissionFixer(cur.reRobeCommission)) : 0.5;
|
|
62
88
|
const priceToUse = cur.isOnSale === 'yes' && cur.salePrice ? cur.salePrice : cur.price;
|
|
63
89
|
const listingPrice = Number.isNaN(priceToUse) ? 0 : Number(priceToUse);
|
|
64
|
-
const
|
|
65
|
-
const
|
|
66
|
-
const
|
|
67
|
-
const
|
|
68
|
-
return [
|
|
90
|
+
const priceSold = acc[0] + listingPrice;
|
|
91
|
+
const commissionFee = acc[1] + priceSold * commission;
|
|
92
|
+
const productionFee = acc[2] + (Boolean(isCanonicalMerchant) ? this.calculateProductionFee(commission) : 0);
|
|
93
|
+
const fulfillmentFee = acc[3] + (Boolean(isCanonicalMerchant) ? this.calculateFulfillmentFee(commission) : 0);
|
|
94
|
+
return [priceSold, commissionFee, productionFee, fulfillmentFee].map((v) => Number(Number(v).toFixed(2)));
|
|
69
95
|
}, [0, 0, 0, 0]);
|
|
70
96
|
}
|
|
71
97
|
static materialCompJoinedString(materialComposition = {}) {
|