insoftpub / storefront

ReactJS Storefront
85 stars 34 forks source link

Unable to Add to Cart #5

Open ghost opened 7 years ago

ghost commented 7 years ago

Upon attempting to add a product to the cart, I get an error

r.handleAddProduct @ Product.jsx:120

Where the variant id is undefined as it says

Uncaught TypeError: Cannot read property 'id' of undefined

This happened in the previous release also. Any advice again? I'm simply just excited to get this boilerplate functional and develop it!

vmajsuk commented 7 years ago

@stevecawdery i guess that can happen due to the way of creating an option. Here is how we do it: image image Make sure you checked the underlined checkbox.

ghost commented 7 years ago

I'm wondering about when there are no variants, it seems to dole out the same error on my system. I'm attempting to create an order minus the variantid but wondering if I'm simply missing something here.

ericingram commented 7 years ago

@vmajsuk @stevecawdery Variants are technically optional, so the code should handle that case without error. I guess it's just a matter of checking variant_id before using variant object.

ericingram commented 7 years ago

Made a PR to fix this, let me know if it looks alright https://github.com/insoftpub/storefront/pull/6

ghost commented 7 years ago

Much more elegant than my solution :)