@wtree/payload-ecommerce-coupon 3.77.9 → 3.78.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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createReferralProgramsCollection.d.ts","sourceRoot":"","sources":["../../src/collections/createReferralProgramsCollection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAEhD,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,UAAU,CAAC;AA0B7D,eAAO,MAAM,gCAAgC,GAC3C,cAAc,4BAA4B,KACzC,
|
|
1
|
+
{"version":3,"file":"createReferralProgramsCollection.d.ts","sourceRoot":"","sources":["../../src/collections/createReferralProgramsCollection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAEhD,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,UAAU,CAAC;AA0B7D,eAAO,MAAM,gCAAgC,GAC3C,cAAc,4BAA4B,KACzC,gBAgZF,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -478,11 +478,16 @@ const createReferralProgramsCollection = (pluginConfig) => {
|
|
|
478
478
|
let customerPercent = null;
|
|
479
479
|
let partnerAmount = null;
|
|
480
480
|
let customerAmount = null;
|
|
481
|
+
let splitWarning = null;
|
|
481
482
|
if (type === "percentage") {
|
|
482
483
|
const partnerPctInput = toNumber(r.partnerPercent) ?? toNumber(r.partnerSplit);
|
|
484
|
+
const customerPctInput = toNumber(r.customerPercent) ?? toNumber(r.customerSplit);
|
|
483
485
|
if (partnerPctInput == null || partnerPctInput < 0 || partnerPctInput > 100) throw new Error(`Commission rule ${index + 1}: Partner Split must be between 0 and 100`);
|
|
484
|
-
|
|
485
|
-
|
|
486
|
+
if (customerPctInput != null && (customerPctInput < 0 || customerPctInput > 100)) throw new Error(`Commission rule ${index + 1}: Customer percentage must be between 0 and 100`);
|
|
487
|
+
const customerPctComputed = customerPctInput != null ? customerPctInput : 100 - partnerPctInput;
|
|
488
|
+
const percentTotal = partnerPctInput + customerPctComputed;
|
|
489
|
+
if (percentTotal > 100) throw new Error(`Commission rule ${index + 1}: Partner percentage + Customer percentage cannot exceed 100`);
|
|
490
|
+
if (percentTotal > 50) splitWarning = `High total split configured: ${percentTotal}% (partner + customer).`;
|
|
486
491
|
partnerPercent = partnerPctInput;
|
|
487
492
|
customerPercent = customerPctComputed;
|
|
488
493
|
partnerSplit = partnerPctInput;
|
|
@@ -524,7 +529,8 @@ const createReferralProgramsCollection = (pluginConfig) => {
|
|
|
524
529
|
partnerAmount,
|
|
525
530
|
customerAmount,
|
|
526
531
|
partnerSplit,
|
|
527
|
-
customerSplit
|
|
532
|
+
customerSplit,
|
|
533
|
+
splitWarning
|
|
528
534
|
};
|
|
529
535
|
});
|
|
530
536
|
return data;
|
|
@@ -624,15 +630,6 @@ const createReferralProgramsCollection = (pluginConfig) => {
|
|
|
624
630
|
value
|
|
625
631
|
})),
|
|
626
632
|
defaultValue: allowedTotalCommissionTypes.includes("fixed") ? "fixed" : "percentage"
|
|
627
|
-
}, {
|
|
628
|
-
name: "value",
|
|
629
|
-
type: "number",
|
|
630
|
-
min: 0,
|
|
631
|
-
max: 100,
|
|
632
|
-
admin: {
|
|
633
|
-
condition: (_, siblingData) => siblingData?.type === "percentage",
|
|
634
|
-
description: "Total commission percentage for this rule (0-100). Partner/Customer percentages split this 100-based bucket."
|
|
635
|
-
}
|
|
636
633
|
}]
|
|
637
634
|
},
|
|
638
635
|
{
|
|
@@ -642,7 +639,7 @@ const createReferralProgramsCollection = (pluginConfig) => {
|
|
|
642
639
|
max: 100,
|
|
643
640
|
admin: {
|
|
644
641
|
condition: (_, siblingData) => siblingData?.totalCommission?.type === "percentage",
|
|
645
|
-
description: "Partner share in percent (0-100)
|
|
642
|
+
description: "Partner share in percent (0-100)"
|
|
646
643
|
}
|
|
647
644
|
},
|
|
648
645
|
{
|
|
@@ -651,17 +648,9 @@ const createReferralProgramsCollection = (pluginConfig) => {
|
|
|
651
648
|
min: 0,
|
|
652
649
|
max: 100,
|
|
653
650
|
admin: {
|
|
654
|
-
readOnly: true,
|
|
655
651
|
condition: (_, siblingData) => siblingData?.totalCommission?.type === "percentage",
|
|
656
|
-
description: "
|
|
657
|
-
}
|
|
658
|
-
hooks: { beforeValidate: [({ siblingData }) => {
|
|
659
|
-
if (!siblingData || siblingData.totalCommission?.type !== "percentage") return null;
|
|
660
|
-
const partner = toNumber(siblingData.partnerPercent) ?? toNumber(siblingData.partnerSplit) ?? 0;
|
|
661
|
-
if (partner < 0) return 100;
|
|
662
|
-
if (partner > 100) return 0;
|
|
663
|
-
return 100 - partner;
|
|
664
|
-
}] }
|
|
652
|
+
description: "Customer share percentage. (0-100). Partner + Customer cannot exceed 100."
|
|
653
|
+
}
|
|
665
654
|
},
|
|
666
655
|
{
|
|
667
656
|
name: "partnerAmount",
|
|
@@ -698,6 +687,16 @@ const createReferralProgramsCollection = (pluginConfig) => {
|
|
|
698
687
|
hidden: true,
|
|
699
688
|
description: "Canonical storage field. Percentage mode: percent. Fixed mode: amount in cents."
|
|
700
689
|
}
|
|
690
|
+
},
|
|
691
|
+
{
|
|
692
|
+
name: "splitWarning",
|
|
693
|
+
type: "text",
|
|
694
|
+
virtual: true,
|
|
695
|
+
admin: {
|
|
696
|
+
readOnly: true,
|
|
697
|
+
condition: (_, siblingData) => siblingData?.totalCommission?.type === "percentage",
|
|
698
|
+
description: "Non-blocking warning shown when partnerPercent + customerPercent is greater than 50%."
|
|
699
|
+
}
|
|
701
700
|
}
|
|
702
701
|
]
|
|
703
702
|
}
|
|
@@ -782,13 +781,25 @@ function calculateItemRewardByRule({ rule, itemTotal, quantity, maxAmount, allow
|
|
|
782
781
|
const allowedTypes = allowedCommissionTypesSet(allowedTotalCommissionTypes);
|
|
783
782
|
if (rule.totalCommission) {
|
|
784
783
|
if (!allowedTypes.has(rule.totalCommission.type)) return null;
|
|
784
|
+
const resolvedMaxAmount = typeof maxAmount === "number" && Number.isFinite(maxAmount) ? maxAmount : typeof rule.totalCommission.maxAmount === "number" && Number.isFinite(rule.totalCommission.maxAmount) ? rule.totalCommission.maxAmount : null;
|
|
785
785
|
if (rule.totalCommission.type === "fixed" && rule.totalCommission.value == null) {
|
|
786
|
-
const
|
|
787
|
-
const
|
|
788
|
-
if (
|
|
786
|
+
const partnerAmtPerUnit = typeof rule.partnerSplit === "number" ? rule.partnerSplit : null;
|
|
787
|
+
const customerAmtPerUnit = typeof rule.customerSplit === "number" ? rule.customerSplit : null;
|
|
788
|
+
if (partnerAmtPerUnit == null || customerAmtPerUnit == null) return null;
|
|
789
|
+
let partner = partnerAmtPerUnit * quantity;
|
|
790
|
+
let customer = customerAmtPerUnit * quantity;
|
|
791
|
+
if (resolvedMaxAmount != null) {
|
|
792
|
+
const maxPotForLine = resolvedMaxAmount * quantity;
|
|
793
|
+
const totalPot = partner + customer;
|
|
794
|
+
if (totalPot > maxPotForLine && totalPot > 0) {
|
|
795
|
+
const ratio = maxPotForLine / totalPot;
|
|
796
|
+
partner = Math.floor(partner * ratio);
|
|
797
|
+
customer = Math.floor(customer * ratio);
|
|
798
|
+
}
|
|
799
|
+
}
|
|
789
800
|
return {
|
|
790
|
-
partner
|
|
791
|
-
customer
|
|
801
|
+
partner,
|
|
802
|
+
customer
|
|
792
803
|
};
|
|
793
804
|
}
|
|
794
805
|
const splits = getRuleSplits(rule);
|
|
@@ -796,7 +807,6 @@ function calculateItemRewardByRule({ rule, itemTotal, quantity, maxAmount, allow
|
|
|
796
807
|
let totalPot = 0;
|
|
797
808
|
if (rule.totalCommission.type === "percentage") totalPot = itemTotal * rule.totalCommission.value / 100;
|
|
798
809
|
else totalPot = rule.totalCommission.value * quantity;
|
|
799
|
-
const resolvedMaxAmount = typeof maxAmount === "number" && Number.isFinite(maxAmount) ? maxAmount : typeof rule.totalCommission.maxAmount === "number" && Number.isFinite(rule.totalCommission.maxAmount) ? rule.totalCommission.maxAmount : null;
|
|
800
810
|
if (resolvedMaxAmount != null) {
|
|
801
811
|
const maxPotForLine = resolvedMaxAmount * quantity;
|
|
802
812
|
if (totalPot > maxPotForLine) totalPot = maxPotForLine;
|