thetrevorharmon / gatsby-theme-shopify-manager

The easiest way to start a Shopify shop on Gatsby.
https://gatsby-theme-shopify-manager.netlify.app/
MIT License
121 stars 11 forks source link

Gatsby shopifyId versus MyShopify shopifyId #86

Open d0t15t opened 3 years ago

d0t15t commented 3 years ago

Hi, thanks for your Shopify theme! It's the best : )

in Gatsby's graphQl, shopifyProduct (also ShopifyProductVariant and other nodes) have a shopifyId that looks something like Z2lkOi8vc2hvcGlmeS9Qdm9kdWN0LzQwOTQ3NDU1OQ==. In MyShopify however, the same product has an ID like 409470000.

What is the correlation between the values? Is there a way to get the integer-Id in gatsby, or to transform between the values?

Many thanks!

davidpaulsson commented 3 years ago

Hey @IsaacBigsbyTrogdon, Shopify wants a "global id", the gid is something like gid://shopify/ProductVariant/409470000, but as base-64. You can generate the gid for a product variant like

const shopifyProductVariantId = 409470000;
const gid = btoa(`gid://shopify/ProductVariant/${shopifyProductVariantId}`);
console.log(gid); // Z2lkOi8vc2hvcGlmeS9Qdm9kdWN0LzQwOTQ3NDU1OQ==
d0t15t commented 3 years ago

Thanks @davidpaulsson !