Dedicated to the Hydrogen framework, headless commerce, and building custom storefronts using the Storefront API.
I Faced an issue with JS SDK
While Trying to do
const lineItemsToAdd = [
variantId: 'Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0VmFyaWFudC8yOTEwNjAyMjc5Mg==',
quantity: 1
}
];
const shippingAddress = {
address1: self.selectedAddress.address1,
address2: self.selectedAddress.address2,
city: self.selectedAddress.city,
company: null,
country: self.selectedAddress.country.country_language.name,
firstName: 'Bob',
lastName: 'Norman',
phone: self.selectedAddress.phone,
province: self.selectedAddress.state.state_language.name,
zip: '11001'
};
await client.checkout.updateShippingAddress(checkoutData.id, shippingAddress);
let mainCheckoutId = await client.checkout.addLineItems(checkoutData.id, lineItemsToAdd);
address works find but the
mainCheckoutId.lineItems = null
userErrors retuns message ="Variant is invalid";
i tried many products and all are published to online sale channel
any suggestions please ???
I had this same issue.
It happened, when I altered the variants of a product in the Shopify admin. I also had a checkout that maintained a reference to the now defunct variants.
The solution is to discard the checkout that has reference to the old variant ids. As I maintained a reference to the checkout id in LocalStorage it was a simple matter of clearing the checkoutId from LocalStorage to fix this problem
I just spent many hours on this issue myself and I'm convinced that the docs are vague to force you to ask for help, at which point they say it's complicated and refer you to the certified "experts".
Maybe this will point you and others in the right direction. Look at the variant object for the the property "admin_graphql_api_id" that is a string starting with "gid://shopify....." and base64encode that using the JS function btoa( passing in the string ) and try adding the result to the checkout as the "variantId"
Not happy about the intentional ambiguity at all