@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
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
import { type CollectionConfig } from 'payload';
|
|
2
2
|
import type { SanitizedCouponPluginOptions } from '../types';
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
5
|
-
* - Admin
|
|
6
|
-
* -
|
|
7
|
-
* minOrderAmount are
|
|
8
|
-
*
|
|
9
|
-
* -
|
|
10
|
-
*
|
|
11
|
-
* - partnerAmount / customerAmount per-rule fixed amounts are NOT scaled here;
|
|
12
|
-
* they represent per-item fixed currency amounts and are stored as-is.
|
|
4
|
+
* Monetary policy:
|
|
5
|
+
* - Admin enters normal currency (e.g. 100 means AED 100).
|
|
6
|
+
* - Top-level caps and min order (maxPartnerCommissionPerOrder,
|
|
7
|
+
* maxCustomerDiscountPerOrder, minOrderAmount) are persisted as normal currency;
|
|
8
|
+
* calculateValues converts to integer cents internally via toCents().
|
|
9
|
+
* - Per-rule fixed amounts (partnerAmount / customerAmount) map to partnerSplit /
|
|
10
|
+
* customerSplit and are stored as-is in major units.
|
|
13
11
|
*/
|
|
14
12
|
export declare const createReferralProgramsCollection: (pluginConfig: SanitizedCouponPluginOptions) => CollectionConfig;
|
|
15
13
|
//# sourceMappingURL=createReferralProgramsCollection.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createReferralProgramsCollection.d.ts","sourceRoot":"","sources":["../../src/collections/createReferralProgramsCollection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,KAAK,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAEzD,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,UAAU,CAAA;AAsB5D
|
|
1
|
+
{"version":3,"file":"createReferralProgramsCollection.d.ts","sourceRoot":"","sources":["../../src/collections/createReferralProgramsCollection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,KAAK,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAEzD,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,UAAU,CAAA;AAsB5D;;;;;;;;GAQG;AAEH,eAAO,MAAM,gCAAgC,GAC3C,cAAc,4BAA4B,KACzC,gBA2aF,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -88,7 +88,7 @@ const createCouponsCollection = (pluginConfig) => {
|
|
|
88
88
|
type: "number",
|
|
89
89
|
required: true,
|
|
90
90
|
admin: {
|
|
91
|
-
description: `
|
|
91
|
+
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).`,
|
|
92
92
|
step: .01
|
|
93
93
|
}
|
|
94
94
|
},
|
|
@@ -432,15 +432,13 @@ function toNumber(value) {
|
|
|
432
432
|
return typeof value === "number" && Number.isFinite(value) ? value : null;
|
|
433
433
|
}
|
|
434
434
|
/**
|
|
435
|
-
*
|
|
436
|
-
* - Admin
|
|
437
|
-
* -
|
|
438
|
-
* minOrderAmount are
|
|
439
|
-
*
|
|
440
|
-
* -
|
|
441
|
-
*
|
|
442
|
-
* - partnerAmount / customerAmount per-rule fixed amounts are NOT scaled here;
|
|
443
|
-
* they represent per-item fixed currency amounts and are stored as-is.
|
|
435
|
+
* Monetary policy:
|
|
436
|
+
* - Admin enters normal currency (e.g. 100 means AED 100).
|
|
437
|
+
* - Top-level caps and min order (maxPartnerCommissionPerOrder,
|
|
438
|
+
* maxCustomerDiscountPerOrder, minOrderAmount) are persisted as normal currency;
|
|
439
|
+
* calculateValues converts to integer cents internally via toCents().
|
|
440
|
+
* - Per-rule fixed amounts (partnerAmount / customerAmount) map to partnerSplit /
|
|
441
|
+
* customerSplit and are stored as-is in major units.
|
|
444
442
|
*/
|
|
445
443
|
const createReferralProgramsCollection = (pluginConfig) => {
|
|
446
444
|
const { collections, access, adminGroups, referralConfig, integration } = pluginConfig;
|
|
@@ -771,7 +769,9 @@ function calculateCouponDiscount({ coupon, cartTotal }) {
|
|
|
771
769
|
const cartCents = toCents(cartTotal);
|
|
772
770
|
let discountCents = 0;
|
|
773
771
|
if (coupon.type === "percentage") {
|
|
774
|
-
|
|
772
|
+
const v = coupon.value;
|
|
773
|
+
if (typeof v === "number" && v > 0 && v < 1) discountCents = Math.floor(cartCents * v);
|
|
774
|
+
else discountCents = Math.floor(cartCents * v / 100);
|
|
775
775
|
if (coupon.maxDiscountAmount != null) {
|
|
776
776
|
const maxCents = toCents(coupon.maxDiscountAmount);
|
|
777
777
|
if (discountCents > maxCents) discountCents = maxCents;
|