project_e_commerce icon indicating copy to clipboard operation
project_e_commerce copied to clipboard

Products in cart are not showing and when I click add cart button it goes blank

Open Alba1020 opened this issue 2 years ago • 8 comments

errors

I am getting these errors in console after clicking add to cart button, strangely enough when I reload the page it will show correct updated number of products. However, I still don't see anything when I go on the cart section besides the title. Anyone had this issue or maybe have any idea what is causing it

Alba1020 avatar Sep 09 '22 14:09 Alba1020

I also have this same error with total_items

crimsoncreates avatar Sep 13 '22 18:09 crimsoncreates

Same error here. Any fix OP?

kevdau03 avatar Sep 23 '22 23:09 kevdau03

I'm having the same issue, anyone with possible solutions?

Oluwa-bunmi avatar Sep 30 '22 16:09 Oluwa-bunmi

I am having the same issues. If I figure it out I will let you guys know. I think it has something to do with :

--mounting the component --the useState hook or --the icon used

https://www.geeksforgeeks.org/what-does-it-mean-for-a-component-to-be-mounted-in-reactjs/#:~:text=Mounting%20is%20the%20initial%20phase,being%20present%20in%20the%20DOM.

https://reactjs.org/docs/react-component.html#mounting

https://daveceddia.com/usestate-hook-examples/

https://mui.com/material-ui/getting-started/installation/

Uwill18 avatar Oct 02 '22 15:10 Uwill18

Hey guys, I found the reason for the blank page. In the App.js, make sure these async functions are written exactly like this, don't destructure the cart yet:

const handleAddToCart = async (productId, quantity) => { const item = await commerce.cart.add(productId, quantity); setCart(item); }; const handleUpdateCart = async (productId, quantity) => { const item = await commerce.cart.update(productId, { quantity }); setCart(item); }; const handleRemoveFromCart = async (productId) => { const item = await commerce.cart.remove(productId); setCart(item); }; const handleEmptyCart = async () => { const item = await commerce.cart.empty(); setCart(item); };

Oluwa-bunmi avatar Oct 02 '22 22:10 Oluwa-bunmi

Thank you @Oluwa-bunmi! That is super helpful!

Uwill18 avatar Oct 04 '22 04:10 Uwill18

@Oluwa-bunmi Thanks buddy, saved tons of time

developerUmair avatar Feb 18 '23 05:02 developerUmair

Thank you @Oluwa-bunmi :)

Auzaiealias avatar Apr 17 '23 05:04 Auzaiealias