Dedicated to the Hydrogen framework, headless commerce, and building custom storefronts using the Storefront API.
Hey there,
I have created a sub-collection by arranging the collection inside the main menu in the navigation settings part of the store page in my admin dashboard. I have attached a screenshot that shows how this sub-collection as been assigned to another collection.
Now I am trying to use the Storefront GraphQL API to fetch all my collections including those newly created sub-collections.
The documentation is not specifically explaining how to do so, which is why I am asking here.
Is there a way to succeed with what I am describing above?
Thanks in advance!
Solved! Go to the solution
This is an accepted solution.
Hi @rxsto 👋 A collection is a collection, a menu is a menu, there is no overlap except the link that may point to a resource (object) .
Shopify does not have real sub-collections, no such thing, not even frontend tag filtering is an actual "subcollection".
Putting a link in an admin menu is just your personal abstraction, you made it up and called it a "subcollection" , it's an imaginary label.
APIs for menus was finally released June 18, 2024:
To get the contents of a Menu, see the following and dig for the resourceId of the MenuItem
https://shopify.dev/changelog/graphql-admin-api-new-apis-for-menus-are-now-available-in-2024-07
https://shopify.dev/docs/api/storefront/2024-07/queries/menu
https://shopify.dev/docs/api/admin-graphql/2024-07/queries/menu
You have to do multiple requests: getting the menus or the specific menu with the item resourceId's, then query collection(s) with those resourceIds etc.
And that's just for the backend.
Use the new dev assistant to ask "how to get a collection from a menu".
It's inside the search bar on the dev docs, use it for toy queries only... keeping in mind it's a word generator that makes stuff up.
Good Luck.
Contact paull.newton+shopifyforum@gmail.com for the solutions you need
Save time & money ,Ask Questions The Smart Way
Problem Solved? ✔Accept and Like solutions to help future merchants
Answers powered by coffee Thank Paul with a ☕ Coffee for more answers or donate to eff.org
This is an accepted solution.
Hi @rxsto 👋 A collection is a collection, a menu is a menu, there is no overlap except the link that may point to a resource (object) .
Shopify does not have real sub-collections, no such thing, not even frontend tag filtering is an actual "subcollection".
Putting a link in an admin menu is just your personal abstraction, you made it up and called it a "subcollection" , it's an imaginary label.
APIs for menus was finally released June 18, 2024:
To get the contents of a Menu, see the following and dig for the resourceId of the MenuItem
https://shopify.dev/changelog/graphql-admin-api-new-apis-for-menus-are-now-available-in-2024-07
https://shopify.dev/docs/api/storefront/2024-07/queries/menu
https://shopify.dev/docs/api/admin-graphql/2024-07/queries/menu
You have to do multiple requests: getting the menus or the specific menu with the item resourceId's, then query collection(s) with those resourceIds etc.
And that's just for the backend.
Use the new dev assistant to ask "how to get a collection from a menu".
It's inside the search bar on the dev docs, use it for toy queries only... keeping in mind it's a word generator that makes stuff up.
Good Luck.
Contact paull.newton+shopifyforum@gmail.com for the solutions you need
Save time & money ,Ask Questions The Smart Way
Problem Solved? ✔Accept and Like solutions to help future merchants
Answers powered by coffee Thank Paul with a ☕ Coffee for more answers or donate to eff.org
Hey there @PaulNewton,
Thank you so much for the detailed response, I had actually forgotten that I posted this question here, due to the complicated forwarding from the supporters I've been talking to! You won't believe it, but literally minutes after I've posted this question here I found out that I could just recursively fetch a custom menu via the GraphQL API for properly grouping and sub-listing collections, and then - as you mentioned correctly - fetch each ending item as a collection with its products as children.
Initially I've thought that Shopify should be able to handle sub-collections internally, but doing it that way is also simple enough. If it works it works.
Hope this post can help others with the same question too.
Cheers!