Using the NextJS Store Demo, Product does not (add to Cart)


#1

Anyone solve this? Thank you in advance.


#2

Hi Jeff,

Are you getting any errors back from the API? If you could show me the response from the developer console that would be great.

Thanks


#3

Uncaught (in promise) ReferenceError: cartId is not defined
at ProxyComponent._callee$ (AddToCart.js:29)
at tryCatch (main.js:12181)
at Generator.invoke [as _invoke] (main.js:12415)
at Generator.prototype.(:3000/anonymous function) [as next] (http://localhost:3000/_next/-/main.js:12233:21)
at step (product.js:30)
at product.js:30
at new Promise ()
at Object.onClick (product.js:30)
at apply (_apply.js:15)
at baseInvoke (_baseInvoke.js:21)


#4

Before the uncaught…I’m also getting:

A bad HTTP response code (404) was received when fetching the script.
Failed to load resource: net::ERR_INVALID_RESPONSE
AddToCart.js:15 ~~~~~YOU HIT THIS HANDLE SUBMIT~
AddToCart.js:16 props: {productId: “9793227c-d030-454b-b50a-e31ded0c52d4”}
AddToCart.js:17 state: {loading: false, quantity: 1}


#5

Hey Jeff,

The cartId is something that you need to set. Its a unique identifier for the cart. (like cartID = “yourcartID”. It can be something static like that. Looking at the example store it looks like one is being used. Have you taking a look to see if this is being set and used (‘mcart’). Are you able to print out cartId before you try to add products?

const cartId = await localStorage.getItem('mcart')

-George


#6

I made that changes and now I get this:

POST https://api.moltin.com/v2/carts/32db3483-d675-4380-9ac8-e379e565bffc/items 400 (Bad Request)
product.js:30 Uncaught (in promise) {status: 400, ok: false, json: {…}}
step @ product.js:30
(anonymous) @ product.js:30
Promise.then (async)
s
e


#7

It works now…Thank you. I had to increment the inventory from 0 to 10. Thank you!


#8

Hi Jeff1
Thank you :slight_smile:
I have the same error , I wanted to increament the inventory , but it seems the inventory unit option is not available to me in the trial. have you experienced the error during trial?

Thanks


#9

Go into your product and try an inventory transaction (on the right side of the page). Record a New Transaction. Choose increment…Good Luck to you.


#10

Thank you , sorted ! :slight_smile: