Hi there,
I’m new to Shopify app development and hoping to get help.
I’m currently working on a Custom App with a Theme app extension( App embeds) for B2B store. In my liquid file under block folder, I use the following code to render the customer’s company location name and its metafield:
{{ customer.current_location.name }}
{{ customer.current_location.metafields.custom.on_hold }}
The values render successfully, but when the location is switched from the the page as you see in the screenshot below, the previously selected location remains displayed, and the newly selected one is not reflected.
I bet the previous one is cached.
I also added Cart & Checkout Validation Function for the server-side validation under the same app. When I turn off “Checkout rule for cart-checkout-validation” from admin page > Settings>Checkout>Checkout rules, this issue doesn’t happen, so I wonder if my Cart & Checkout Validation Function is causing this issue.
This is the code in run.ts
import type {
RunInput,
FunctionRunResult,
FunctionError
} from "../generated/api";
const onHoldMessage = "This location is currently on hold and unable to place orders. Please contact support for assistance.";
export function run(input: RunInput): FunctionRunResult {
const errors: FunctionError[] = [];
const isOnHold = input.cart.buyerIdentity?.purchasingCompany?.location?.metafield?.value;
const locationName = input.cart.buyerIdentity?.purchasingCompany?.location?.name || "";
if (isOnHold === undefined || isOnHold === null) {
console.log(" Metafield not found");
} else if (isOnHold === "true") {
errors.push({
localizedMessage: locationName + ": " + onHoldMessage,
target: "$.cart"
});
}
return {
errors
}
};
And this is run.graphql
query RunInput {
cart {
buyerIdentity {
purchasingCompany {
location {
id
name
metafield(namespace: "custom", key: "on_hold") {
value
}
}
}
}
}
}
Could someone guide me on how to resolve this issue? I hope my explanation makes sense here, but please let me know if you need more clarification.
Thank you in advance for your help!
Best regards,