I am trying to get all the current items in the cart into a textbox. I am getting an error "Cannot read property of “0” of undefined."I have created a backend function that gets the items and a front end function to display the items. Here is my code;
//backend
import wixStores from 'wix-stores-backend'
export function getCurrentCart() {
return wixStores.getCurrentCart();
}
//frontend
import {getCurrentCart} from 'backend/events.jsw';
$w.onReady(async function () {
const results = await getCurrentCart();
let items = results.lineItems;
for (var i = 0; i < items.length; i++) {
$w("#textBox1").value = results.items[i].name;
}})
Any help will be appreciated.
how was this marked solved? I don’t see any answer!
Hola,
La solución cuando invocamos el método getCurrentCart() de wix-stores-backend y da el sigiuente error:
Cart with person identity 46ef0d8c-23d5-46f5-87dd-5142a87f7a86 not found
//Backend → archivo producto.jsw
import wixStoresBackend from ‘wix-stores-backend’
export function getCurrentCart ( ) {
return wixStoresBackend . getCurrentCart ();
}
//Cart Page
import { getCurrentCart } from ‘backend/productos.jsw’
$w . onReady ( function () {
getCurrentCart ()
. then ( result => { arguments
console . log ( result , ‘current cart’ )
})
});
El problema es que en el ambiente de ‘Vista Previa’ no funciona el código su totalidad, debes publicar y ver el sitio, en ese ‘ambiente’ verás los cambios (el console.log())
Saludos!