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

[gatsby-source-shopify] create parent-child link between products and variants #21602

Closed
alexluong opened this issue Feb 20, 2020 · 8 comments
Closed
Assignees
Labels
help wanted Issue with a clear description that the community can help with. topic: source-shopify Related to the gatsby-source-shopify plugin

Comments

@alexluong
Copy link
Contributor

alexluong commented Feb 20, 2020

Summary

Create parent-child link between ShopifyProduct and ShopifyProductVariant

Motivation

When working with Shopify, some time it's quite helpful to go up 1 level from variant to product. One example is to get product thumbnails from checkout.lineItems which contains variantIds.


I'd love to hear what you think about this idea?

@pieh
Copy link
Contributor

pieh commented Feb 20, 2020

Generally agree, just would want to clarify that this shouldn't be parent/child in sense of "gatsby nodes", but instead it should be regular link that will allow to traverse from variant to product.

From what I understand gatsby-source-shopify let's you access variants from product:

if (node.variants) {
const variants = node.variants.edges.map(edge => edge.node)
node.variants___NODE = variants.map(variant =>
generateNodeId(PRODUCT_VARIANT, variant.id)
)
delete node.variants
}

We would need similar thing for

export const ProductVariantNode = imageArgs =>
createNodeFactory(PRODUCT_VARIANT, async node => {
if (node.metafields) {
const metafields = node.metafields.edges.map(edge => edge.node)
node.metafields___NODE = metafields.map(metafield =>
generateNodeId(PRODUCT_VARIANT_METAFIELD, metafield.id)
)
delete node.metafields
}
if (node.image)
node.image.localFile___NODE = await downloadImageAndCreateFileNode(
{
id: node.image.id,
url: node.image.originalSrc && node.image.originalSrc.split(`?`)[0],
},
imageArgs
)
return node
})

That would set product___NODE (but we would have to pass product node (full object or id) to that factory from

if (x.variants)
await forEach(x.variants.edges, async edge => {
const v = edge.node
if (v.metafields)
await forEach(v.metafields.edges, async edge =>
createNode(
await ProductVariantMetafieldNode(imageArgs)(edge.node)
)
)
return createNode(await ProductVariantNode(imageArgs)(edge.node))
})

@pieh pieh added the help wanted Issue with a clear description that the community can help with. label Feb 20, 2020
@alexluong
Copy link
Contributor Author

@pieh Thanks for promptly addressing the issue. I'd be happy to work on this.

@github-actions
Copy link

Hiya!

This issue has gone quiet. Spooky quiet. 👻

We get a lot of issues, so we currently close issues after 30 days of inactivity. It’s been at least 20 days since the last update here.
If we missed this issue or if you want to keep it open, please reply here. You can also add the label "not stale" to keep this issue open!
As a friendly reminder: the best way to see this issue, or any other, fixed is to open a Pull Request. Check out gatsby.dev/contribute for more information about opening PRs, triaging issues, and contributing!

Thanks for being a part of the Gatsby community! 💪💜

@github-actions github-actions bot added the stale? Issue that may be closed soon due to the original author not responding any more. label Mar 12, 2020
@alexluong alexluong added not stale and removed stale? Issue that may be closed soon due to the original author not responding any more. labels Mar 12, 2020
@danabrit danabrit added the topic: source-shopify Related to the gatsby-source-shopify plugin label May 29, 2020
@github-actions
Copy link

Hiya!

This issue has gone quiet. Spooky quiet. 👻

We get a lot of issues, so we currently close issues after 30 days of inactivity. It’s been at least 20 days since the last update here.
If we missed this issue or if you want to keep it open, please reply here. You can also add the label "not stale" to keep this issue open!
As a friendly reminder: the best way to see this issue, or any other, fixed is to open a Pull Request. Check out gatsby.dev/contribute for more information about opening PRs, triaging issues, and contributing!

Thanks for being a part of the Gatsby community! 💪💜

@github-actions github-actions bot added the stale? Issue that may be closed soon due to the original author not responding any more. label Jun 19, 2020
@jzabala jzabala assigned jzabala and unassigned jzabala Jun 25, 2020
@jzabala
Copy link
Contributor

jzabala commented Jun 25, 2020

Hi @alexluong, still working on this one?

@alexluong
Copy link
Contributor Author

Hey @jzabala, no I'm not working on this one. Turn out there are other ways to solve my problem.

I still think this is a great addition though. Feel free to take it on!

@jzabala
Copy link
Contributor

jzabala commented Jun 25, 2020

Hey @jzabala, no I'm not working on this one. Turn out there are other ways to solve my problem.

I still think this is a great addition though. Feel free to take it on!

Awesome @alexluong. Thanks for letting me know.

@jzabala jzabala self-assigned this Jun 25, 2020
@jzabala jzabala removed the stale? Issue that may be closed soon due to the original author not responding any more. label Jun 25, 2020
@LekoArts
Copy link
Contributor

Hi! We've released a new major verison (v5) which fundamentally works different. Please try the upgrade and if you still hit this please open a new issue with a reproduction. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Issue with a clear description that the community can help with. topic: source-shopify Related to the gatsby-source-shopify plugin
Projects
None yet
Development

No branches or pull requests

5 participants