Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

variantForOptions always return undefined #71

Open
lezan opened this issue Sep 4, 2022 · 0 comments
Open

variantForOptions always return undefined #71

lezan opened this issue Sep 4, 2022 · 0 comments

Comments

@lezan
Copy link

lezan commented Sep 4, 2022

I was testing the variantForOptions when I find out it is always undefined so this line

client.product.helpers.variantForOptions(product, variant) || variant

always assign the second part (variant),

Checking Shopify documentation (here)[https://shopify.github.io/js-buy-sdk/product-helpers.js.html#line6] variant it is not what variantForOptions expect as the second argument but more an object like that

{
  size: "Small",
  color: "Red"
}

So maybe something like that can work and fix the issue

const productVariant = client?.product?.helpers?.variantForOptions(shopify, {
  [variant?.selectedOptions[0]?.name]: variant?.selectedOptions[0]?.value,
  [variant?.selectedOptions[1]?.name]: variant?.selectedOptions[1]?.value,
}) || variant;

If you wanna try it yourself just fork this repo and print the helpers with a console.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant