Product not added to cart when using

I am using eCommerce Catalog Custom Extension to create a new collection of products, called “Itens”.

I already coded frontend and backend scripts, but when the user clicks the button, I have a success log message that item was added to cart, but the cart continues with zero items.

Frontend:


import {addLensToCart} from 'backend/ecom-integration';


let selectedLens;



$w.onReady(function () {
    const lensDetailsRepeater = $w('#lensRepeater');
    lensDetailsRepeater.onItemReady(($item, itemData, index) => {
        $item('#subtitleText').text = itemData.subtitle;
        $item('#subtitleText').onClick(() => {
            selectedLens = itemData; 
            console.log(selectedLens);
        });
    });


    $w('#btnAddToCart').onClick(() => {
        const item = $w("#dynamicDataset").getCurrentItem();
        const lineItem = {
            id: item._id,

        };
        addLensToCart(lineItem.id,);
    });
});


Backend:

import { currentCart, cart } from 'wix-ecom-backend';

export async function addLensToCart(lensId) {
    const options = {
        lineItems: [{
            catalogReference: {
                appId: "96c81ef5-dbfe-471b-b449-7fb7a1552cd6",
                catalogItemId: lensId,

            },
            quantity: 1, 
             title: item.title,
             price: item.price,
             mainMedia: item.image,
             description: item.description,
             quantityAvailable: 1,

        }]
    };

    const myCart = await currentCart.getCurrentCart();
    if (myCart) {
        const addToCartIdResponse = await cart.addToCart(myCart._id, options);
        console.log("addToCartIdResponse: ", {addToCartIdResponse});
    } else {
        const createCartResponse = await cart.createCart(options);
        console.log("createCartResponse: ", {createCartResponse});
    }
}

Any ideas on what could be going wrong?

Tks!

Alexandre,

Hi, curious if you got this working. I am planning on adding something similar for our site but I’m concerned that as this is a beta feature it may have issues. I can’t even get the catalog extension to publish to get the appid. Did you do anything special to do that? I posted a question here about it:

Would like to know if the extension has been working for you as we are also trying to add items to the cart from our own backend and not a wix collection.

Thanks,
Jeff