Velo addProducts() doesn't work on my site

I have written a product configurator and I have spent a lot of time getting the code so that it correctly creates a product, and this works. I can get the configured product to appear in my store with all the correct information and pricing. However, I can’t get the product to add to cart. I have tried copying the API addProducts() function over, using it as described in the API and also using it with my own tweaks to change the product name within the function argument, but I cannot get it to work.

I’m always getting a console error when trying to run the addProducts() function - “t.reduce is not a function”.

I have also tried copying the API code over to a brand new page with no custom code, and running it as simply as possible. This also does not work.

I have been working on this problem for 3 days straight and I’m running out of time to get my website ready - I was hoping to launch a product on the 7th November but I am quickly seeing that date approach.

The “product” array is presented in the correct format as required by the API and the product creates on the store with no issues.

newProduct = await createProduct ( product );
(This works fine)

cart . addProducts ( newProduct )
. then (( updatedCart ) => {
// Products added to cart
const cartId = updatedCart._id ;
const cartLineItems = updatedCart.lineItems ;
})
. catch (( error ) => {
// Products not added to cart
// console.error(error);
});

This does not work at all. This is copied straight from the API apart from the (newProduct) within brackets.

I really can’t see what I’m missing. I’ve had various other people look at it and they can’t work it out either!

ALSO: Sometimes it runs through the code with no errors and my console logs to show me the start and end of the “addProducts” code ARE running, so the code is passing through, but the cart is still empty, despite having no errors.

I’m completely lost at this point.

1 Like

Hello there,

Can you please provide a sample object of the created product?

Hi cosmicaudioltd,
this might come a bit late but you are adding an incorrect object to the cart
The cart needs amount and productId

If you add

const product = [{
“productId”: newProduct._id ,
“quantity”: 1 // or any quantity from user selection or script
}]

then do this

cart . addProducts ( product )
. then (( updatedCart ) => { // Products added to cart
const cartId = updatedCart._id ;
const cartLineItems = updatedCart.lineItems ;
})
. catch (( error ) => { // Products not added to cart//
console.error(error);
});

Your issue will be resolved

Take care

I’m having the same issue. Copied from the API code and tried running its as simple as possible with just an ID and quantity, but it refuses to add to the cart. No console errors. Did anyone ever figure this out?