CartID missing on Live Site

Hello,

I am using EditorX and have a Store but rather than displaying all items, I actually have just one product page for one product. Additionally, I have 2 step process similar to Patagonia.com when adding an item to the cart. In other words, I have a custom Button named “Add to Bag” which makes a call to cart.addProducts() on click and adds a product of quantity 1 with selected options to the cart. At least that is what it should do …

I am not using the default Add To Cart button because it doesn’t give me the flexibility to specify all of the product options I want.

I am following the API documentation here Cart - Velo API Reference - Wix.com

I am able to test it in Preview mode. However, once published, the same code throws an INTERNAL_SERVER_ERROR on the cart API call saying that it cannot resolve the cartId because it is null.

The error I get in production from the cart.addProducts API call is:

FetchError: {"message":"Cannot read properties of null (reading 'cartId')","locations":[{"line":3,"column":5}],"path":["cart","addToCart"],"extensions":{"code":"INTERNAL_SERVER_ERROR","exception":{"name":"ERROR:addToCart:RESOLVER_ERROR"}}}

Any help is much appreciated! Here is my code:

 // I understand that wix-stores.getCurrentCart() is deprecated but cart.getCurrentCart() isn't and I wanted to see if the cartID is actually missing. I am able to get the cart and the cartId is not missing!
    cart.getCurrentCart()
    .then((currentCart) => {
        const cartId = currentCart._id;
        const cartLineItems = currentCart.lineItems;
        console.log(cartId); // this exists when I log it
        console.log(cartLineItems); // this exists when I log it
    })
    .catch((error) => {
        console.error(error);
    });
    
// This is where the problem is on the live site. This call returns the error
    cart.addProducts(productsToAdd).then((updatedCart) => {
        // Products added to cart
        console.log(updatedCart);
        let dataObj = {
            "cart": updatedCart,
            "size": sizeSelection.label,
            "color": colorSelection.label
        }

	wixWindow.openLightbox("AddedToBagLightbox", dataObj);
        }
    })

One more thing, I am able to navigate to the cart page with. There are no products added though because the server call fails…

import {navigate} from 'wix-stores';

...
navigate.toCart();

Thanks,

2 Likes

Hi, @plamenanpetrova
Did you figure it out. I’m facing exactly the same error on hitting custom add to cart.

Hi, @plamenanpetrova , I am facing the same error, on custom code ( add to cart ).
Any help will be appreciated.

Have you found a solution for this?

I am having the exact same issue with adding products to a cart using the velo api. I get a null cart ID on Live. My guess is that velo doesn’t create a cart where the built-in add-to-cart button creates a cart and also adds the product to it, hence getting a null cart ID. Any help on this would be fantastic

Hello Jonathan! No. I have filed bugs wirh WIX and unfortunately they haven’t done anything to fix this bug. I filed this on their EditorX forum too since I’m paying for their highest plan and all I have gotten from them is “we will take a look” and literally nothing more. I even provided then with all of the necessary logging and test cases and it’s been two months now. To say that this is unacceptable support for a hoghly priced service is an understatement.

I had this same issue - but it turns out it was because I had marked this product as “out of stock” while I was testing the website (for obvious reasons). When I changed it to “in stock” add to cart worked.

This is SUPER confusing because the error thrown has nothing to do with the issue.

I would say double check that your product is available for purchase and try again. (Republish site in between)

And let’s pray together that WiX creates a better sandbox environment for testing out store customizations

So did you get this code to work in a live environment? When my code is live I get a null cart ID and had to do a bunch of stuff to circumvent the

And the plot thickens - turns out the “customTextFields” value I was passing also plays a part. I was trying to make the value a URL (even tried .toString()) but no go - then I tried “undefined” and “test” and both worked…

Not sure what the logic is here but :upside_down_face:

For the grand finale - the url I was passing was more than the 500 char limit of the text field… again no relationship between thrown error and actual error but a great debugging exercise.

So does your costume add to cart work in live?? Mine worked in test but I got the null cart ID error as described by the OP when I published my site and tried it

Yes I did - by making sure that my product was in stock and that all the fields of the product object I was passing were in compliance with the settings in the dashboard product.

Yes I did - by making sure that my product was in stock and that all the fields of the product object I was passing were in compliance with the settings in the dashboard product.

I have the exact same problem, wierdly it works if I first add a ‘static’ product from the ‘shop’ page, and then after do my ‘dynamic’ addProducts. It works perfectly in test but not in live.