@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/index.mjs CHANGED
@@ -87,7 +87,7 @@ const createCouponsCollection = (pluginConfig) => {
87
87
  type: "number",
88
88
  required: true,
89
89
  admin: {
90
- description: `If percentage, 10 means 10% (must be 0–100). If fixed, amount in ${defaultCurrency} with up to 2 decimal places (e.g. 10.99).`,
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
- * Scaling policy:
435
- * - Admin inputs normal currency values (e.g. 100 means $100).
436
- * - Internally, maxPartnerCommissionPerOrder, maxCustomerDiscountPerOrder, and
437
- * minOrderAmount are stored in x100 (integer cents) form to avoid floating-point
438
- * drift on monetary cap fields.
439
- * - beforeChange → multiply by 100 before persisting.
440
- * - afterRead → divide by 100 before returning to admin / calculation code.
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
- discountCents = Math.floor(cartCents * coupon.value / 100);
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;