Closed kuleyu closed 2 years ago
Hey there @kuleyu!
This is because _id
and id
are different data points. You're looking at the _id
which is a Sanity-specific field that's auto-generated when creating documents in the studio. The reason the format is different is because the ones sync'd from Shopify are created by the sync function where we explicitly set the _id
value that's generated (see here).
The error you're seeing when visiting a manually created product is because it's looking for the variantID
that's supplied via Shopify, which is constructed as the id
in GROQ for the product data. You can see that being defined here.
Since HULL is meant to work with Shopify, it expects that these fields would always be filled out in order for the "add to cart" and checkout experiences to work properly.
Let me know if that makes sense!
Hey there @kuleyu I hope my previous comment helped!
Going to close this issue now, but feel free to follow up 🤘
@ndimatteo can you provide more information how how you would solve the above issue? I am running into the same problem and I cant figure out how to stop sanity from giving its own ID
@kuleyu Did you solve this issue? can you provide me with some guidance on this problem?
@QuinAiton I'm not sure what you're trying to accomplish, but the entire functionality behind product
documents is inextricably linked to Shopify product data.
The _id
of the document is irrelevant to how variants
and their IDs are referenced on the front-end.
I do not recommend adding products manually from the Studio, but if you must, you would also need to create productVariant
documents for each and fill out every Shopify-powered field in order to avoid Server errors on the frontend.
Again, I'm not sure how this is viable, since the entire shopping experience relies on the product also existing in Shopify (this is how the cart is powered and persisted, as well as checkout).
I hope that helps, but holler if there are more questions!
Thanks @Naimatteo for creating and sharing such a fantastic project. I really love it.
I have some needs to add products manually, not only getting products by syncing from shopify. So, I edited the file "shop-product.js" as follows:
Then it seems to work well, and I can add and edit new products manually in the studio panel. But when I visit the frontend site, every page which contains the manual added product will get the same error as follows:
Then, when I Inspect the manual created product, I see the value of the
_id
isa4ed66e1-1051-499c-b974-f42d880c8e0d
. While when I Inspect a product which is sync from shopify, I see the value of the_id
isproduct-7152543826104
.It seems that they are in different format. I'm not sure if this is the key point of the error. And what should I do? Thank you.