Hi there,
I am trying to use Cart and Checkout Validation Function to ensure the order amount is at least $1,500 before customer can checkout. This is the example doc I was following - https://shopify.dev/docs/apps/checkout/validation/create-simple-validation-rules
I had to refactor some logic, but this is what I have so far:
// @TS -check
// Use JSDoc annotations for type safety
/**
- @typedef {import(“../generated/api”).RunInput} RunInput
- @typedef {import(“../generated/api”).FunctionRunResult} FunctionRunResult
*/
// The configured entrypoint for the ‘purchase.validation.run’ extension target
/**
- @Anonymous {RunInput} input
- @returns {FunctionRunResult}
*/
export function run(input) {
// The error
const error = {
localizedMessage: “Order amount must be at least $1,500”,
target: “cart”
};
// Parse the decimal (serialized as a string) into a float.
const subtotalAmount = parseFloat(input.cart.cost.subtotalAmount.amount);
const errors = ;
if (subtotalAmount < 1500.0) {
errors.push(error);
}
return { errors };
};
The issue I have is that this rule keeps validating when the add to cart button is clicked - https://bertram.d.pr/v/PChnK2
Is there a way where I can validate during checkout but not when customer is adding items to cart?
Possible I might be looking at this the wrong way, is there a better solution to achieve this without using a paid app?
Thank you for your help and time!