In Nacelle V2 each product variant has its own nacelleEntryId. This ID is used by the shopify-cart package to, as the name suggests, add specific items to a users cart. However, when using the Compatibility Connector the nacelleEntryId is lost. Here's a function that will allow you to convert a variant's id to a nacelleEntryId:
functionvariantSourceEntryIdToNacelleEntryId(shopifySubdomain, sourceEntryId, locale="en-US") {Note that that the `shopifySubdomain` parameter in the function above is not the full URL, just your site's unique name. For example, if your site's full subdomain is "my-site.myshopify.com," then you'd only need to pass in "my-site."
letbase64Decode = (x) =>x;
letbase64Encode = (x) =>x;
if (typeofdocument !== "undefined") {
// browser runtime
base64Decode = globalThis.atob;
base64Encode = globalThis.btoa;
} else {
// server runtime
base64Decode = (x) => Buffer.from(x, "base64").toString("utf-8");
base64Encode = (x) => Buffer.from(x).toString("base64");
}
constdecodedSourceEntryId = base64Decode(sourceEntryId); // returns 'gid://shopify/ProductVariant/<variant-id>'
constvariantId = decodedSourceEntryId.split("/").at(-1);
nacelleEntryId = base64Encode(
`id://SHOPIFY/${shopifySubdomain}/default/PRODUCT_VARIANT/${variantId}/${locale}`
);
console.log(nacelleEntryId)
}
Comments
0 comments
Please sign in to leave a comment.