@wtree/payload-ecommerce-coupon 3.79.3 → 3.79.4
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/dist/collections/createReferralProgramsCollection.d.ts +7 -9
- package/dist/collections/createReferralProgramsCollection.d.ts.map +1 -1
- package/dist/index.js +11 -11
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +11 -11
- package/dist/index.mjs.map +1 -1
- package/dist/utilities/calculateValues.d.ts.map +1 -1
- package/package.json +2 -1
package/dist/index.mjs
CHANGED
|
@@ -87,7 +87,7 @@ const createCouponsCollection = (pluginConfig) => {
|
|
|
87
87
|
type: "number",
|
|
88
88
|
required: true,
|
|
89
89
|
admin: {
|
|
90
|
-
description: `
|
|
90
|
+
description: `Percentage: use 10 for 10%, or a decimal between 0 and 1 for a fraction of the cart (0.1 = 10%, 0.01 = 1%). Values from 1 upward are percent points (1 = 1%, 100 = 100%). Fixed: amount in ${defaultCurrency} (e.g. 10.99).`,
|
|
91
91
|
step: .01
|
|
92
92
|
}
|
|
93
93
|
},
|
|
@@ -431,15 +431,13 @@ function toNumber(value) {
|
|
|
431
431
|
return typeof value === "number" && Number.isFinite(value) ? value : null;
|
|
432
432
|
}
|
|
433
433
|
/**
|
|
434
|
-
*
|
|
435
|
-
* - Admin
|
|
436
|
-
* -
|
|
437
|
-
* minOrderAmount are
|
|
438
|
-
*
|
|
439
|
-
* -
|
|
440
|
-
*
|
|
441
|
-
* - partnerAmount / customerAmount per-rule fixed amounts are NOT scaled here;
|
|
442
|
-
* they represent per-item fixed currency amounts and are stored as-is.
|
|
434
|
+
* Monetary policy:
|
|
435
|
+
* - Admin enters normal currency (e.g. 100 means AED 100).
|
|
436
|
+
* - Top-level caps and min order (maxPartnerCommissionPerOrder,
|
|
437
|
+
* maxCustomerDiscountPerOrder, minOrderAmount) are persisted as normal currency;
|
|
438
|
+
* calculateValues converts to integer cents internally via toCents().
|
|
439
|
+
* - Per-rule fixed amounts (partnerAmount / customerAmount) map to partnerSplit /
|
|
440
|
+
* customerSplit and are stored as-is in major units.
|
|
443
441
|
*/
|
|
444
442
|
const createReferralProgramsCollection = (pluginConfig) => {
|
|
445
443
|
const { collections, access, adminGroups, referralConfig, integration } = pluginConfig;
|
|
@@ -770,7 +768,9 @@ function calculateCouponDiscount({ coupon, cartTotal }) {
|
|
|
770
768
|
const cartCents = toCents(cartTotal);
|
|
771
769
|
let discountCents = 0;
|
|
772
770
|
if (coupon.type === "percentage") {
|
|
773
|
-
|
|
771
|
+
const v = coupon.value;
|
|
772
|
+
if (typeof v === "number" && v > 0 && v < 1) discountCents = Math.floor(cartCents * v);
|
|
773
|
+
else discountCents = Math.floor(cartCents * v / 100);
|
|
774
774
|
if (coupon.maxDiscountAmount != null) {
|
|
775
775
|
const maxCents = toCents(coupon.maxDiscountAmount);
|
|
776
776
|
if (discountCents > maxCents) discountCents = maxCents;
|