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 following 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,

Hey @plamenanpetrova Thanks for bringing this up. I’ll check this out and get the team to take a look at this. @miril

Can you share the site you are working on @plamenanpetrova so our team can take investigate this?

Hi @Rob ,
Thanks for responding! I am working on arnidoggears.com. At the moment, This functionality is on the “Fancy: Bed” page (which is hidden behind a password) and is on two sections, which are not being displayed because of the issue i reported. Those two sections are called “addToCart” and “buyButtonSection”.

-Plamena

@Rob and @miril do you have any updates on this?

Repinged the team. I’ll also make a ticket on your behalf and send it to our Velo team.

This literally just started to work at 5AM UTC only to stop working again less than an hour later without any code changes from me!!!

I honestly don’t know what is going on your velo’s side but this is obviously a server-side issue! It took more than 3 weeks to hear back from anyone, only to be told that I should be using the async functionality (which I am) and that they can’t see my side nor code because there is a password on it. Well of course there is password of it! I haven’t been able to launch it because this functionality is still broken and why would I launch something that is broken? Since I am a paying customer, at the balmy rate of 85$/month, I imagine your developers can view and debug someone’s site on the backend considering it doesn’t work in preview nor on live (until of course it decides to work and then stop again).

The cart icon IS there so there should be a cart. I even added an await to block and force the response form the cart and the cart has an id full of 0s. This is very suspicious, since for the one hour it was working, there was an actual cartID!

Please look at your server logs and fix the addToCart functionality!

The level of debugging for this paid product that I have had to do is ridiculous, and I am a software engineer for a living!

Here is one more proof that something is wrong with the cart server-side!

  1. Try to get the cart using the cart API:
export async function addToBagButton_click(event) {
    // let me see what is in that cart
    let cartresult = await cart.getCurrentCart();
    ...
} 
  1. This returns. The 0s in that ID don’t look right.
{_id: '00000000-000000-000000-000000000000', buyerNote: null, appliedCoupon: null, status: 'INCOMPLETE', shippingInfo: null, …}
appliedCoupon: null
billingAddress: null
buyerInfo: null
buyerNote: null
currency: {code: 'USD', symbol: ''}
lineItems: []
shippingInfo: null
status: "INCOMPLETE"
totals: {discount: 0, quantity: 0, shipping: 0, subtotal: 0, tax: 0, …}
weightUnit: null
_id: "00000000-000000-000000-000000000000"
[[Prototype]]: Object
constructor: ƒ Object()
hasOwnProperty: ƒ hasOwnProperty()
isPrototypeOf: ƒ isPrototypeOf()
propertyIsEnumerable: ƒ propertyIsEnumerable()
toLocaleString: ƒ toLocaleString()
toString: ƒ toString()
valueOf: ƒ valueOf()
__defineGetter__: ƒ __defineGetter__()
__defineSetter__: ƒ __defineSetter__()
__lookupGetter__: ƒ __lookupGetter__()
__lookupSetter__: ƒ __lookupSetter__()
__proto__: (...)
get __proto__: ƒ __proto__()
set __proto__: ƒ __proto__()
length: 1
name: "set __proto__"
arguments: (...)
caller: (...)
[[Prototype]]: ƒ ()
[[Scopes]]: Scopes[0]
No properties
  1. Try to add a product using the API;
export async function addToBagButton_click(event) {
    //...
    const products = [{
    "productId": "1a5bd1e5-c726-3772-d550-a4df6787db07",
    "quantity": 1,
    "options": {
            "choices": {
                "Size": "S",
                "Color": "#F7F5F0"
            }}
    }]

    cart.addProducts(products)
        .then((updatedCart) => {
            // Products added to cart successfully
            console.log("Product added...");
            const cartId = updatedCart._id;
            const cartLineItems = updatedCart.lineItems;
            console.log("cartID:")
            console.log(cartId);
            console.log("cartLineItems:")
            console.log(cartLineItems);
        })
        .catch((error) => {
            // Products not added to cart
            console.log(error);
            $w('#addToCartErrorBox').expand();
            $w('#addToCartErrorBox').show();
        });
 }
  1. You get this error. It’s as if even though the cartIcon is there, the object doesn’t exist!
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"}}}
    at new e (FetchError.js:5:28)
    at t.eval (fetch-wrapper.js:32:35)
    at eval (tslib.es6.js:102:23)
    at Object.eval [as next] (tslib.es6.js:83:53)
    at a (tslib.es6.js:73:58)
  1. Click Wix’s “out-of-the-box” AddToCart button, which opens the Product’s QuickView.
  2. Select product options.
  3. Click Add To Cart.
  4. Product appears in cart, and now the cart-ID is not 0s.
{_id: '9281b5d7-68a3-4349-9a60-f96bb13753ad', buyerNote: null, appliedCoupon: null, status: 'INCOMPLETE', shippingInfo: {…}, …}
appliedCoupon: null
billingAddress: null
buyerInfo: null
buyerNote: null
currency: {code: 'USD', symbol: ''}
lineItems: [{…}]
shippingInfo: {shippingAddress: {…}}
status: "INCOMPLETE"
totals: {discount: 0, quantity: 1, shipping: 15.99, subtotal: 400, tax: 0, …}
weightUnit: null
_id: "9281b5d7-68a3-4349-9a60-f96bb13753ad"
[[Prototype]]: Object
  1. Now go back to step 3 and try to add a product via the cart API again, and you can successfully add a product using the cart API!!!

Either a key piece is missing from the documentation or there is a bug on the server side where it is not initializing the cart and therefore doesn’t return it.

Product added...
createConsoleProxy.ts:47 cartID:
createConsoleProxy.ts:47 9281b5d7-68a3-4349-9a60-f96bb13753ad
createConsoleProxy.ts:47 cartLineItems:
createConsoleProxy.ts:47 
(2) [{…}, {…}]
0: {mediaItem: {…}, productId: 'd7388836-f53c-814f-7dcd-e6f5c4f1eda0', lineItemType: 'PHYSICAL', name: 'The Bed', notes: null, …}
1: {mediaItem: {…}, productId: '1a5bd1e5-c726-3772-d550-a4df6787db07', lineItemType: 'PHYSICAL', name: 'The Reusable Bag', notes: null, …}
length: 2
[[Prototype]]: Array(0)

Hey Plamena, thank you for reaching back out and letting us know it worked momentarily.

I’ll reopen the ticket so our team can investigate and update it with these updates you provided.