Liquid, JavaScript, themes, sales channels
Hi,
When I receive the product details on my webhook endpoint, I can't tell if the product has only the default variant of has one custom variant
Default variant only
/*variants:*/ [
{
id: XXX,
product_id: XXXXX,
title: 'Default Title',
price: '7.500',
sku: '',
position: 1,
inventory_policy: 'deny',
compare_at_price: null,
fulfillment_service: 'manual',
inventory_management: null,
option1: 'Default Title',
option2: null,
option3: null,
created_at: '2021-07-25T05:55:20-04:00',
updated_at: '2021-07-25T05:57:38-04:00',
taxable: true,
barcode: '',
grams: 0,
image_id: null,
weight: 0,
weight_unit: 'kg',
inventory_item_id: XXXXX,
inventory_quantity: 0,
old_inventory_quantity: 0,
requires_shipping: true,
admin_graphql_api_id: 'gid://shopify/ProductVariant/XXXXXXX'
}
]
With one custom variant
/*variants:*/ [
{
id: XXXX,
product_id: XXXXXXXXXX,
title: 'S',
price: '7.500',
sku: '',
position: 1,
inventory_policy: 'deny',
compare_at_price: null,
fulfillment_service: 'manual',
inventory_management: null,
option1: 'S',
option2: null,
option3: null,
created_at: '2021-07-25T05:57:54-04:00',
updated_at: '2021-07-25T05:57:54-04:00',
taxable: true,
barcode: '',
grams: 0,
image_id: null,
weight: 0,
weight_unit: 'kg',
inventory_item_id: XXX,
inventory_quantity: 0,
old_inventory_quantity: 0,
requires_shipping: true,
admin_graphql_api_id: 'gid://shopify/ProductVariant/XXXX'
}
]
How to reliably tell if the product has one custom variant
On the resource selector, I used the prop `hasOnlyDefaultVariant` but in the webhook body, it isn't present at all
Thank you
Solved! Go to the solution
This is an accepted solution.
I ended up making a graphql request like so
const _query = `
query getProduct($id: ID!) {
product(id: $id) {
hasOnlyDefaultVariant
}
}
`;
This is an accepted solution.
I ended up making a graphql request like so
const _query = `
query getProduct($id: ID!) {
product(id: $id) {
hasOnlyDefaultVariant
}
}
`;
Are you ready to take your business to the next level? Look no further than the latest ...
By SarahF_Shopify Apr 15, 2024We’re keeping the ball rolling to make sure you’re always ahead of the game. So buckle ...
By JasonH Apr 8, 2024Portrait of Stephen positioned next to an image of planet Earth, with the Stephen's World ...
By JasonH Mar 18, 2024