@wtree/payload-ecommerce-coupon 3.78.10 → 3.79.1

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.js CHANGED
@@ -901,11 +901,11 @@ function getItemCategoryIds(item) {
901
901
  function getItemTagIds(item) {
902
902
  return Array.isArray(item?.product?.tags) ? normalizeIds(item.product.tags) : [];
903
903
  }
904
- function selectBestRuleForItem({ rules, item, itemTotalCents, quantity, cartTotalCents, minOrderAmountCents, allowedTotalCommissionTypes }) {
904
+ function selectBestRuleForItem({ rules, item, itemTotalCents, quantity, cartTotalCents, allowedTotalCommissionTypes }) {
905
905
  const allowedTypes = allowedCommissionTypesSet(allowedTotalCommissionTypes);
906
906
  const eligibleRules = rules.filter((rule) => {
907
907
  if (!(rule?.totalCommission?.type ? allowedTypes.has(rule.totalCommission.type) : true)) return false;
908
- const resolvedMinCents = minOrderAmountCents != null && Number.isFinite(minOrderAmountCents) ? minOrderAmountCents : typeof rule?.minOrderAmount === "number" && Number.isFinite(rule.minOrderAmount) ? toCents(rule.minOrderAmount) : null;
908
+ const resolvedMinCents = typeof rule?.minOrderAmount === "number" && rule?.minOrderAmount ? toCents(rule.minOrderAmount) : null;
909
909
  if (resolvedMinCents != null) return cartTotalCents >= resolvedMinCents;
910
910
  return true;
911
911
  });
@@ -984,7 +984,6 @@ function calculateCommissionAndDiscount({ cartItems, program, currencyCode = "AE
984
984
  customerDiscount: 0
985
985
  };
986
986
  const cartTotalCents = toCents(cartTotal);
987
- const programMinOrderAmountCents = typeof program?.minOrderAmount === "number" && Number.isFinite(program.minOrderAmount) ? toCents(program.minOrderAmount) : null;
988
987
  let totalPartnerCents = 0;
989
988
  let totalCustomerCents = 0;
990
989
  for (const item of cartItems) {
@@ -997,6 +996,8 @@ function calculateCommissionAndDiscount({ cartItems, program, currencyCode = "AE
997
996
  });
998
997
  const quantity = item.quantity ?? 1;
999
998
  const itemTotalCents = toCents(itemPriceCurrency) * quantity;
999
+ const minOrderAmountCents = toCents(program?.minOrderAmount ?? 0);
1000
+ if (minOrderAmountCents && itemTotalCents < minOrderAmountCents) throw new payload.APIError("Item total must be greater than or equal to min order amount", 400);
1000
1001
  const bestMatch = selectBestRuleForItem({
1001
1002
  rules,
1002
1003
  item: {
@@ -1006,7 +1007,6 @@ function calculateCommissionAndDiscount({ cartItems, program, currencyCode = "AE
1006
1007
  itemTotalCents,
1007
1008
  quantity,
1008
1009
  cartTotalCents,
1009
- minOrderAmountCents: programMinOrderAmountCents,
1010
1010
  allowedTotalCommissionTypes
1011
1011
  });
1012
1012
  if (!bestMatch) continue;