Hi Developers,
I’m currently building a Shopify App with Remix.js to add descriptions to the product description field via form submissions. The current setup works, but each submission is replacing the entire product description. I’d like to update the functionality so each form submission either prepends or appends content to the existing description instead of overriding it. Below is the action function handling the form submission:
// Action function to handle form submission
export const action = async ({ request }: ActionFunctionArgs) => {
const { admin } = await authenticate.admin(request);
const formData = await request.formData();
const zipcode = formData.get("zipcode");
const price = formData.get("price");
const id = "gid://shopify/Product/8304181903529";
const descriptionHtml = `<p>Zipcode: ${zipcode}</p><p>Price: ${price}</p>`;
try {
const productUpdateResponse = await admin.graphql(
`mutation updateProduct($productInput: ProductInput!) {
productUpdate(input: $productInput) {
product {
id
descriptionHtml
}
userErrors {
field
message
}
}
}`,
{
variables: {
productInput: {
id,
descriptionHtml,
},
},
}
);
return json({ success: "Product description updated successfully!" });
} catch (error) {
console.error("Unexpected error:", error);
return json({ errors: ["Unexpected error occurred"], message: error.message }, { status: 500 });
}
};
Can you please help me adjust the GraphQL mutation to ensure each form submission appends content to the current description rather than replacing it?
I would really appreciate your help and information.
Many thanks