Cart Validation Function not running in AJAX API in Production

davidmerrique
Shopify Partner
1 0 0

Hello. I have a function to limit the total items in the cart to 10.

 

When I run shopify app dev and use the function in my Development Theme, the cart/update endpoint properly returns a 422 response with the error message from the function when I try to add more than 10 items to my cart.

 

However, in Production, the cart/update endpoint doesn't display the message and allows more than 10.

When I'm in the actual checkout, I see the error message though.

 

Here's the function:

// @ts-check

/**
 * @typedef {import("../generated/api").RunInput} RunInput
 * @typedef {import("../generated/api").FunctionRunResult} FunctionRunResult
 */

/**
 * @param {RunInput} input
 * @returns {FunctionRunResult}
 */
export function run(input) {
	const errors = [];

	// If the total quantity is more than 10, we add an error to the cart
	if (input.cart.lines.reduce((acc, { quantity }) => acc + quantity, 0) > 10) {
		errors.push({
			localizedMessage: "Not possible to order more than 10 in total",
			target: "cart",
		});
	}

	return {
		errors,
	};
}

This is the payload I'm sending that I'm expecting to return a 422 error response:

{
	"line": "1",
	"quantity": "11",
	"sections": [
		"template--17476154130659__cart-items",
		"cart-icon-bubble",
		"cart-live-region-text",
		"template--17476154130659__cart-footer"
	],
	"sections_url": "/cart"
}
Replies 0 (0)