ndimatteo / HULL

💀 Headless Shopify Starter – powered by Next.js + Sanity.io
https://hull.dev
MIT License
1.36k stars 167 forks source link

Add to cart issue #91

Closed dashbaz closed 2 years ago

dashbaz commented 2 years ago

Hey,

I've been exploring the project for a little while now and ready to start a fresh production repo.

Add to cart wasn't working on the repo I had previously, but I wasn't concerned about it. I think in my very first, repo I had I was able to get it working after the auto deploy via sanity and then manually doing step 1. Pretty sure I was throwing sh*t at the wall and it worked but I can't recreate that currently.

Today, I generated a fresh project and I'm not able to add to cart.

I've tried the manual and auto deploy via sanity to test.

I checked the cors origin on sanity and env variables on the local front end as well.

Is there something else I should be checking for?

Is there a procedure you can give me to ensure I'm checking all the boxes?

You're appreciated, thanks!

ndimatteo commented 2 years ago

Hey there @dashbaz, thanks for the kind words!

I think I can shed some light on the Cart issues on fresh installs (both manual and automatic approaches):

All of the "demo" products included are for presentational purposes only when running the automatic deploy of HULL. Since these products are tied to the HULL Shopify Store, the only place they can truly be added to a cart is on the official live demo.

You'll still be able to see them in your Sanity Studio and your storefront because that's all just static data. However, the "add to cart" functionality is tied to the Shopify Client connected to HULL (see step 2 in the readme).

Even once you connect your own Shopify account, the HULL demo products still won't add to cart since those products do not exist in your store (remember, the product/variant ID are generated from Shopify).

So, what I'd suggest doing:

  1. Remove all of the demo products (and variants) from your Sanity Studio if you went the auto deploy route (if you went the manual route, no products should exist yet)
  2. Make sure you've properly setup the custom Shopify app and env variables, deploying to Vercel to ensure the Shopify Webhooks run properly
  3. Create a product in Shopify and wait for it to sync into Sanity

Once you do that, you should have a product that maps to a real product in Shopify and you should be able to add to cart properly (both on localhost and in production)!

Let me know if that makes sense, or if I'm misunderstanding the issue. 🤘

dashbaz commented 2 years ago

Sorry for late response, followed this awhile back and got it working. You my tech goat!