@wtree/payload-ecommerce-coupon 3.77.8 → 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
|
@@ -436,9 +436,10 @@ const createReferralProgramsCollection = (pluginConfig) => {
|
|
|
436
436
|
return {
|
|
437
437
|
slug: collections.referralProgramsSlug,
|
|
438
438
|
admin: {
|
|
439
|
-
useAsTitle: "
|
|
439
|
+
useAsTitle: "name",
|
|
440
440
|
defaultColumns: [
|
|
441
441
|
"id",
|
|
442
|
+
"name",
|
|
442
443
|
"commissionRules",
|
|
443
444
|
"isActive"
|
|
444
445
|
],
|
|
@@ -477,11 +478,16 @@ const createReferralProgramsCollection = (pluginConfig) => {
|
|
|
477
478
|
let customerPercent = null;
|
|
478
479
|
let partnerAmount = null;
|
|
479
480
|
let customerAmount = null;
|
|
481
|
+
let splitWarning = null;
|
|
480
482
|
if (type === "percentage") {
|
|
481
483
|
const partnerPctInput = toNumber(r.partnerPercent) ?? toNumber(r.partnerSplit);
|
|
484
|
+
const customerPctInput = toNumber(r.customerPercent) ?? toNumber(r.customerSplit);
|
|
482
485
|
if (partnerPctInput == null || partnerPctInput < 0 || partnerPctInput > 100) throw new Error(`Commission rule ${index + 1}: Partner Split must be between 0 and 100`);
|
|
483
|
-
|
|
484
|
-
|
|
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).`;
|
|
485
491
|
partnerPercent = partnerPctInput;
|
|
486
492
|
customerPercent = customerPctComputed;
|
|
487
493
|
partnerSplit = partnerPctInput;
|
|
@@ -523,12 +529,19 @@ const createReferralProgramsCollection = (pluginConfig) => {
|
|
|
523
529
|
partnerAmount,
|
|
524
530
|
customerAmount,
|
|
525
531
|
partnerSplit,
|
|
526
|
-
customerSplit
|
|
532
|
+
customerSplit,
|
|
533
|
+
splitWarning
|
|
527
534
|
};
|
|
528
535
|
});
|
|
529
536
|
return data;
|
|
530
537
|
}] },
|
|
531
538
|
fields: [
|
|
539
|
+
{
|
|
540
|
+
name: "name",
|
|
541
|
+
type: "text",
|
|
542
|
+
required: true,
|
|
543
|
+
admin: { description: "Name of the referral program" }
|
|
544
|
+
},
|
|
532
545
|
{
|
|
533
546
|
name: "isActive",
|
|
534
547
|
type: "checkbox",
|
|
@@ -617,15 +630,6 @@ const createReferralProgramsCollection = (pluginConfig) => {
|
|
|
617
630
|
value
|
|
618
631
|
})),
|
|
619
632
|
defaultValue: allowedTotalCommissionTypes.includes("fixed") ? "fixed" : "percentage"
|
|
620
|
-
}, {
|
|
621
|
-
name: "value",
|
|
622
|
-
type: "number",
|
|
623
|
-
min: 0,
|
|
624
|
-
max: 100,
|
|
625
|
-
admin: {
|
|
626
|
-
condition: (_, siblingData) => siblingData?.type === "percentage",
|
|
627
|
-
description: "Total commission percentage for this rule (0-100). Partner/Customer percentages split this 100-based bucket."
|
|
628
|
-
}
|
|
629
633
|
}]
|
|
630
634
|
},
|
|
631
635
|
{
|
|
@@ -635,7 +639,7 @@ const createReferralProgramsCollection = (pluginConfig) => {
|
|
|
635
639
|
max: 100,
|
|
636
640
|
admin: {
|
|
637
641
|
condition: (_, siblingData) => siblingData?.totalCommission?.type === "percentage",
|
|
638
|
-
description: "Partner share in percent (0-100)
|
|
642
|
+
description: "Partner share in percent (0-100)"
|
|
639
643
|
}
|
|
640
644
|
},
|
|
641
645
|
{
|
|
@@ -644,17 +648,9 @@ const createReferralProgramsCollection = (pluginConfig) => {
|
|
|
644
648
|
min: 0,
|
|
645
649
|
max: 100,
|
|
646
650
|
admin: {
|
|
647
|
-
readOnly: true,
|
|
648
651
|
condition: (_, siblingData) => siblingData?.totalCommission?.type === "percentage",
|
|
649
|
-
description: "
|
|
650
|
-
}
|
|
651
|
-
hooks: { beforeValidate: [({ siblingData }) => {
|
|
652
|
-
if (!siblingData || siblingData.totalCommission?.type !== "percentage") return null;
|
|
653
|
-
const partner = toNumber(siblingData.partnerPercent) ?? toNumber(siblingData.partnerSplit) ?? 0;
|
|
654
|
-
if (partner < 0) return 100;
|
|
655
|
-
if (partner > 100) return 0;
|
|
656
|
-
return 100 - partner;
|
|
657
|
-
}] }
|
|
652
|
+
description: "Customer share percentage. (0-100). Partner + Customer cannot exceed 100."
|
|
653
|
+
}
|
|
658
654
|
},
|
|
659
655
|
{
|
|
660
656
|
name: "partnerAmount",
|
|
@@ -691,6 +687,16 @@ const createReferralProgramsCollection = (pluginConfig) => {
|
|
|
691
687
|
hidden: true,
|
|
692
688
|
description: "Canonical storage field. Percentage mode: percent. Fixed mode: amount in cents."
|
|
693
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
|
+
}
|
|
694
700
|
}
|
|
695
701
|
]
|
|
696
702
|
}
|
|
@@ -775,13 +781,25 @@ function calculateItemRewardByRule({ rule, itemTotal, quantity, maxAmount, allow
|
|
|
775
781
|
const allowedTypes = allowedCommissionTypesSet(allowedTotalCommissionTypes);
|
|
776
782
|
if (rule.totalCommission) {
|
|
777
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;
|
|
778
785
|
if (rule.totalCommission.type === "fixed" && rule.totalCommission.value == null) {
|
|
779
|
-
const
|
|
780
|
-
const
|
|
781
|
-
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
|
+
}
|
|
782
800
|
return {
|
|
783
|
-
partner
|
|
784
|
-
customer
|
|
801
|
+
partner,
|
|
802
|
+
customer
|
|
785
803
|
};
|
|
786
804
|
}
|
|
787
805
|
const splits = getRuleSplits(rule);
|
|
@@ -789,7 +807,6 @@ function calculateItemRewardByRule({ rule, itemTotal, quantity, maxAmount, allow
|
|
|
789
807
|
let totalPot = 0;
|
|
790
808
|
if (rule.totalCommission.type === "percentage") totalPot = itemTotal * rule.totalCommission.value / 100;
|
|
791
809
|
else totalPot = rule.totalCommission.value * quantity;
|
|
792
|
-
const resolvedMaxAmount = typeof maxAmount === "number" && Number.isFinite(maxAmount) ? maxAmount : typeof rule.totalCommission.maxAmount === "number" && Number.isFinite(rule.totalCommission.maxAmount) ? rule.totalCommission.maxAmount : null;
|
|
793
810
|
if (resolvedMaxAmount != null) {
|
|
794
811
|
const maxPotForLine = resolvedMaxAmount * quantity;
|
|
795
812
|
if (totalPot > maxPotForLine) totalPot = maxPotForLine;
|