AddtoCartItem #myShoppingCartItem error?

Hmm… I’m not sure whats going on here, or why it doesn’t recognise “myShoppingCartItem”.

Thought my logic was OK on this. Click on button, create a variable in a string that grabs the Id of a specific product determined by the ‘dataset’ of the page, then add that product to the cart.

Were am i going wrong here guys and gals, but it doesn’t seem to understand its own function? i have removed hash tag, used comers, no comers, can’t seem to do it, so i would appreciate if someone could shed some light on my problem. :wink:

The error probably means that the id of the shopping cart is wrong (probably because its copy pasted from somewhere)

You need to click on the shopping cart icon on your page, then on the properties panel box on the right you will see the shopping cart’s actual id. use that.

Also, on line 7 remove the quotation marks from “productId”

It should read:

.addToCart(productId, 1)

thanks Shan, I didn’t realise the shopping cart was given a generic ID, I will check that tomorrow, I copied from what I read from the documentation. I did remove the quotations, just I screenshot the image when they were still in there.:slight_smile:

OK, I have rewrote the code and now not getting any errors within it, so thought that would be the end of it, but no. here we go again. On preview i’m getting ‘parsing error’, and my button does sod all. I’m honestly losing the will to live here… Whats going on now? its a simple task, click button, add the product to the cart, job done. It’s all i need for my site. I know its not a done thing, but, please if someone knows how to do this, could i have the code for it. :slight_smile: I looked and searched through the documentation, watched tutorials, ive spent a fair bit of time trying, im just at my wits end. someone please put me out of my misery.

The error means that there is something wrong with your Site Code . On your IDE (where you write the code, look on the left, there are 2 code panels (Page & Site)

Some of the code was in the ‘Site’ sidebar (i never used that,so not sure how that got in there) erased it so its blank. i have no errors now, but the button press function isn’t doing anything, suggestions? still no worky. :frowning:

Have you created an onClick event using the Properties Panel ?

Hi Shan, yes sir, i have.

Use this to catch the error

$w("#shoppingCartIcon1").addToCart(productId, 1)
.then( () => {
    console.log("Product added");
  } )
  .catch( (error) => {
  } );
1 Like

error said 'fetching error, ‘out of stock’, hahahaha, im sorry i shouldn’t laugh, what a clown i am. I have to say though, if stock is one i get the fetch error, only changing the inventory to more than one did it work. that said, im going to try again tomorrow after setting the stock to one again and give the system time to ‘update’ just to make sure there isn’t a delay.

What can i say, other than sorry for wasting your time here, but i am very grateful to you Shan. :slight_smile: this is massive for me now, i can just crack on and create an awesome website!

1 Like