App reviews, troubleshooting, and recommendations
Hi Guys I am doing an app with remix for discounts, all is going good and I am coding a DataTable where the merchant can edit the discount, when the discount is clicked it takes the merchant to the specific page successfully, but I dont know how to query the metafields for that specific discount dynamically so it works everywhere.
Here is what i have so far in my query:
Hi @jacobovelasquez,
I have created a sample code.
If there is anything here that’s unclear please do let me know!
app/routes/app.discount.$functionId.$id.tsx
export const loader = async ({ params, request }: LoaderFunctionArgs) => {
const { admin } = await shopify.authenticate.admin(request);
const { id } = params;
const discountNode = await getDiscount(admin, id!);
return json({ discountNode });
};
const getDiscount = async (
admin: AdminApiContext<RestResources>,
id: string,
) => {
const response = await admin.graphql(
getDiscountNode(),
{
variables: {
id: 'gid://shopify/DiscountNode/' + id,
namespace: METAFIELD_NAMESPACE,
key: METAFIELD_CONFIGURATION_KEY
},
}
);
const responseJson = await response.json();
const discountNode = responseJson.data.discountNode;
if (!discountNode) return undefined;
if (!discountNode.metafield) return undefined;
if (typeof discountNode.metafield.value !== 'object') {
const value = JSON.parse(discountNode.metafield.value)
value.volume = value.volume.map((obj: any) => ({
quantity: String(obj.quantity),
percentage: String(obj.percentage)
}));
discountNode.metafield.value = value;
}
return discountNode;
}
const getDiscountNode = () => {
return `#graphql
query getDiscountNode($id: ID!, $namespace: String!, $key: String!){
discountNode(id: $id) {
discount {
... on DiscountAutomaticApp {
__typename
asyncUsageCount
combinesWith {
orderDiscounts
productDiscounts
shippingDiscounts
}
endsAt
startsAt
status
title
}
... on DiscountCodeApp {
__typename
asyncUsageCount
appliesOncePerCustomer
codeCount
combinesWith {
orderDiscounts
productDiscounts
shippingDiscounts
}
endsAt
startsAt
status
title
usageLimit
codes(first: 1) {
edges {
node {
code
}
}
}
}
}
id
metafield(namespace: $namespace, key: $key) {
value
id
}
}
}`
}
@Hirano_00 @jacobovelasquez is there any way to get list discountNodes created by an app?
Shopify and our financial partners regularly review and update verification requiremen...
By Jacqui Mar 14, 2025Unlock the potential of marketing on your business growth with Shopify Academy's late...
By Shopify Mar 12, 2025Learn how to increase conversion rates in every stage of the customer journey by enroll...
By Shopify Mar 5, 2025