Only getting the output "[object Object]" when attempting to call the getCurrentCart() function in my store

I am trying to get the shipping total from the current cart, and am trying to start by making sure I can get all the information from the getCurrentCart() function on a test page before just focusing on that one particular number.

So far I’ve created a backend page “events.jsw” and added the following code:

import wixStores from 'wix-stores-backend'

export function getCurrentCart() {
 return wixStores.getCurrentCart();
}

Then on a blank page on the front end, I’ve added a text block and have the following code:

import wixStores from 'wix-stores';
import {getCurrentCart} from 'backend/events.jsw';

 $w.onReady(async function () {
  const results = await getCurrentCart();
  $w("#text12").text = results.toString();
 });

However, the output I get in “#text12” is simply “[object Object]”

The API Resources found here for wix-stores-backend, have the same example “Get the current site visitor’s cart” over and over again but it’s all the same. Using the code from the repeated example provided as well as trying to use this video tutorial and this article on working with Promises to try and figure out the front end code, I have been able to come up with what I showed above. However the example from the API Resource seems to indicate that the fulfilled promise should be giving a lot of details on the cart.

What am I doing wrong, or what do I need to do/read/watch to figure out how to get the information to appear? Thank you.

#wixStores #wixStoresBackend code #getCurrentCart #CartTotal #cart #promise #promises #objects #help #backendCode #backend #store

Please use like :
$w(“#text15”).text = results.lineItems[0].name;
instead of $w(“#text15”).text = results.toString();

It’s a JSON example like below :
{
“lineItem”: [
{
“name”:“xyz”
} ]
}

i got the error message : TypeError: Cannot read property ‘name’ of undefined !!!

So far I’ve created a backend page “stores.jsw” and added the following code:

import wixStores from 'wix-stores-backend'

export function getCurrentCart() {
 return wixStores.getCurrentCart();
}

Then on a blank page on the front end, I’ve added a text block and have the following code:

import {getCurrentCart} from ‘backend/stores.jsw’;

$w.onReady(async function () {
const results = await getCurrentCart();
$w(“#myRepeatedText”).text = results.lineItems[0].name;
});

whats wrong ?

1 Like

That solved my problem and now shows the first product in the cart. Thank you very much.