# Add to Cart from Custom database

**URL:** <https://forum.wixstudio.com/t/add-to-cart-from-custom-database/3866>\
**Category:** Ask the community\
**Tags:** code, question\
**Created:** [March 5, 2023, 2:10pm UTC](https://forum.wixstudio.com/t/add-to-cart-from-custom-database/3866 "2023-03-05T14:10:48Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![toranvale](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/toranvale/32/9040_2.png) [@toranvale](https://forum.wixstudio.com/u/toranvale)\
**Post date:** [March 5, 2023, 2:10pm UTC](https://forum.wixstudio.com/t/add-to-cart-from-custom-database/3866/1 "2023-03-05T14:10:48Z")

</div>

Hello!  
I am trying to make a website page where the customer can modify the product’s dimensions, which will affect the product’s price. I am using a custom database to add the customized product, but I am unable to add products from the database to the cart.  
This is the code I have written so far.

```javascript
let itemObj = $w("#Dataset").
const products = [{
                "productId": itemObj._id,
                "quantity": itemObj.quantity,
            }];
           
           cart.addProducts(products)
                .then((updatedCart) => {
                    // Products added to cart
                    const cartId = updatedCart._id;
                    const cartLineItems = updatedCart.lineItems;
                    console.log(updatedCart);
                    console.log("Products added");
                })
                .catch((error) => {
                    // Products not added to cart
                    console.error(error);
                });

```

This is not giving me any error, but the product Lso doesn’t get added to the cart.  
Can someone tell me how to solve this?

Thanks

---

<div class="post-metadata">

**Author:** ![amandam](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/amandam/32/79539_2.png) [@amandam](https://forum.wixstudio.com/u/amandam)\
**Post date:** [March 7, 2023, 8:54pm UTC](https://forum.wixstudio.com/t/add-to-cart-from-custom-database/3866/2 "2023-03-07T20:54:45Z")

</div>

When you console.log the products object, is there anything in there?

---

<div class="post-metadata">

**Author:** ![toranvale](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/toranvale/32/9040_2.png) [@toranvale](https://forum.wixstudio.com/u/toranvale)\
**Post date:** [March 7, 2023, 9:13pm UTC](https://forum.wixstudio.com/t/add-to-cart-from-custom-database/3866/3 "2023-03-07T21:13:09Z")

</div>

Yup I can see the product id. But that product is added to a custom collection called “Dataset” instead of the inventory “Products”. I am unable to add a product from collection to the cart using velo code.

---

<div class="post-metadata">

**Author:** ![amandam](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/amandam/32/79539_2.png) [@amandam](https://forum.wixstudio.com/u/amandam)\
**Post date:** [March 7, 2023, 9:19pm UTC](https://forum.wixstudio.com/t/add-to-cart-from-custom-database/3866/4 "2023-03-07T21:19:31Z")

</div>

Are you using the custom catalog SPI? It sounds like this is what you could need.

[https://www.wix.com/velo/reference/spis/getting-started/ecommerce-catalog](https://www.wix.com/velo/reference/spis/getting-started/ecommerce-catalog)

---

<div class="post-metadata">

**Author:** ![toranvale](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/toranvale/32/9040_2.png) [@toranvale](https://forum.wixstudio.com/u/toranvale)\
**Post date:** [March 8, 2023, 11:24am UTC](https://forum.wixstudio.com/t/add-to-cart-from-custom-database/3866/5 "2023-03-08T11:24:43Z")

</div>

Hey  
Thank you for the reply. I tried using SPI but how to make sure that when I add product to the cart, this SPI is getting called? I have added code into the custom extensions but not sure if it’s getting called before a product is added to cart

---

<div class="post-metadata">

**Author:** ![amandam](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/amandam/32/79539_2.png) [@amandam](https://forum.wixstudio.com/u/amandam)\
**Post date:** [March 8, 2023, 12:59pm UTC](https://forum.wixstudio.com/t/add-to-cart-from-custom-database/3866/6 "2023-03-08T12:59:34Z")

</div>

When configuring the custom catalog, you have to. make sure to configure the appId to point to your custom collection. That’s likely the missing piece.

See this tutorial, it’s no. 10 in step 1 - it tells you how to get and then set the new app id for the custom catalog. [https://support.wix.com/en/article/velo-tutorial-ecommerce-catalog-custom-extension-beta](https://support.wix.com/en/article/velo-tutorial-ecommerce-catalog-custom-extension-beta)

Once it’s pointing to your catalog, the add to cart functionality is automatically pointing to those items instead of the regular product collection

---

<div class="post-metadata">

**Author:** ![toranvale](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/toranvale/32/9040_2.png) [@toranvale](https://forum.wixstudio.com/u/toranvale)\
**Post date:** [March 8, 2023, 1:05pm UTC](https://forum.wixstudio.com/t/add-to-cart-from-custom-database/3866/7 "2023-03-08T13:05:00Z")

</div>

I tried that but the api id was only visible the first time I added the extension and published the site. When publishing the site after that, it wasn’t visible. So I am not sure what happened. The app store also doesn’t show the custom catalog.

---

<div class="post-metadata">

**Author:** ![amandam](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/amandam/32/79539_2.png) [@amandam](https://forum.wixstudio.com/u/amandam)\
**Post date:** [March 8, 2023, 1:16pm UTC](https://forum.wixstudio.com/t/add-to-cart-from-custom-database/3866/8 "2023-03-08T13:16:25Z")

</div>

That is correct that the appID is only available the first time (for now, this is still a beta functionality so things could change). This is why the step says to save this ID. I will have to ask how to retrieve it another way, I’m not sure at the moment.

You also need the appID again for the testing addToCurrentCart as shown here: [https://www.wix.com/velo/reference/wix-ecom-backend/currentcart/addtocurrentcart?branch=autodocs-wix-ecom-backend](https://www.wix.com/velo/reference/wix-ecom-backend/currentcart/addtocurrentcart?branch=autodocs-wix-ecom-backend)

specifically, when testing a custom catalog you must add appID here in the line items

 ![](https://us1.discourse-cdn.com/wix/original/3X/3/d/3df74ba1876b1ebaf64c321b6b85a4c835de641d.jpeg)

I will get back to you about how to get the appID if you have not saved it after the initial step and see if having that helps get this working

---

<div class="post-metadata">

**Author:** ![Alexandre\_Plasti\_Mel](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/alexandre_plasti_mel/32/81983_2.png) [@Alexandre\_Plasti\_Mel](https://forum.wixstudio.com/u/Alexandre_Plasti_Mel)\
**Post date:** [September 29, 2023, 6:30pm UTC](https://forum.wixstudio.com/t/add-to-cart-from-custom-database/3866/9 "2023-09-29T18:30:32Z")

</div>

Hey. Did you solved this issue? I am facing the same problem.

Tks
