Trace the validation Function, then answer.
// extensions/wholesale-minimum/src/cart_validations_generate_run.js
//
// Input query (cart_validations_generate_run.graphql):
//
// query CartValidationsGenerateRunInput {
// cart {
// buyerIdentity {
// customer { hasAnyTag(tags: ["wholesale"]) }
// }
// lines {
// quantity
// merchandise {
// __typename
// ... on ProductVariant {
// product {
// title
// metafield(namespace: "wholesale", key: "min_qty") { value }
// }
// }
// }
// }
// }
// }
export function cartValidationsGenerateRun(input) {
const errors = [];
const isWholesale =
input.cart.buyerIdentity?.customer?.hasAnyTag ?? false;
if (isWholesale) {
for (const line of input.cart.lines) {
if (line.merchandise.__typename !== "ProductVariant") continue;
const product = line.merchandise.product;
if (!product.metafield) continue;
const minQty = parseInt(product.metafield.value, 10);
if (line.quantity < minQty) {
errors.push({
message: `${product.title}: wholesale minimum is ${minQty} bags`,
target: "$.cart",
});
}
}
}
return {
operations: [{ validationAdd: { errors } }],
};
}