Problem Adding Product to Cart

Hello there, need some help with an error being thrown while trying to add a product with different options to the cart using the updated .addProducts() method.

I created a custom product page that checks availability for all the different options (color, size and etc.) and then I’m trying to add the selected product and options to the cart that is giving me this error:

TypeError: Cannot read properties of undefined (reading 'id')

This error is being caught by the .catch() method of the resulting promise.

    buttonBuy.onClick(async () => {
        const productOptions = selectedOptions(
            selectedKey,
            dropdownColor.value,
            selectedOption,
            dropdownSize.value
        )
        const products = createProductToCart(
            currentProduct._id,
            Number(inputQtd.value),
            productOptions
        )
        const result = await cart
            .addProducts(products)
            .catch(error => console.error(error))
        console.log(result)
    })

I tried inserting the product object directly (without going through functions) and got the same error.

[
  {
    "productId": "23b2b8fa-fe3a-a50b-e074-6d1238a9e687",
    "quantity": 1,
    "options": {
      "choices": {
        "Cor": "Bege",
        "Pontuação": "36"
      },
      "customTextFields": [
        {
          "title": "Custom package sticker",
          "value": "Enjoy your coffee!"
        }
      ]
    }
  }
]

If someone had this problem and solved it, please…

2 Likes

Hi Bruno!
Did you figure this out? If not, I’ll find someone to help you out. Let me know!

Hello @marlowe-shaeffer , did not figure it out. But, the product is going to the cart, even though the error is being caught.

Hi Bruno,
Can you share the URL for your site/page where the code is, and any steps to reproduce, so the team can investigate? Thanks.

I have this exact same problem, same error, but the product is getting added to the cart.

Hi mcustode,
Please share the URL for your site so the team can investigate why the error is occurring. Thanks.

I don’t know if this is related (I will open up another thread just in case) but I am having add to cart errors with subscription products.

We added 7 non-subscription products just fine, but when we attempt to add a subscription product we receive a message saying "one time purchase is not allowed for product with id … "

We can add it to cart via Wix stores just fine ---- but not via code?

Marlowe,

I am working on a new project for a client that involves adding Products to The Store and Items To The Cart. I have found a few issues using the new APIs. Can we schedule a Zoom meeting from someone on your team and I will be happy to review the issues I have found. Let me know if that works and we can schedule it.

@marlowe-shaeffer I just tried the published version and no error was caught. It seems to be a Preview Mode error.

Here is the link: Here

Was there an update on this?

Trying to add a New Product to the Store and even though I am passing a valid image URL, keep getting this error and no image

mainMedia:
“wix:image://v1/614034_103e8f4ab0ae4536a38b319d3eb437ed~mv2.png/missing-media.png#originWidth=500&originHeight=500”

Currently, you can’t perform “Subscribe now” from Velo (add a subscription to cart).
You can add a subscription product to cart if it has a “one time purchase” option.

@bwprado Hi Bruno,
A developer on the Stores team looked into the issue, and he reported that he was not able to get the error when logged in as the site owner. Everything worked fine in both Preview mode and on the live site. However, he did see an Identity issue in Preview mode when logged in as a temp contributor. What is your site role?

This issue was reported and fixed before, but he will report it again to the team to look into. The error is not coming from adding to cart, but from fetching the updated cart after the add to cart is complete.

In the meantime, here are some workarounds:

  • Test in Live mode (not ideal, sorry!)

  • Log in as Site Owner

Thanks!

hello, we have the same problem, We can create a custom product with 8 options in a dynamic page, similar to the custom sweater example, but we are unable to send the final design to cart.

The product goes to cart, but only the default product image appears in the cart, so we cannot tell what the chosen options are in the final sale/purchase of the custom product.

Can anybody please help with a solution. We have speant a few weeks on this and have even tried a different product randomisation dynamic page option, which also fails at the cart stage.

We have read through several velo posts and it appears that many people are unable to get the cart page working with customised or randomised products.

Product customisation is becoming increasingly popular so making this happen will be a big win for many WIX website customers.

Big thanks in advance:)

Exploring Senses

I have a number of clients that can add customized products to the cart. There are a lot of issues that have to be overcome to get it to work.

If you are interested in my solution and would like to have a discussion send me an email at mcustode@aol.com or call me at (201) 207-5387 and we can discuss. I am located in New Jersey EDT (timezone). - Mike Custode