Using the frontend eCom API, you can interact with the native cart and checkout components on your site.
With the frontend eCom API, you can:
To use the frontend eCom API, import * as wixSiteEcom
from the @wix/site-ecom
module:
It's important to note the following points before starting to code:
You need to add eCommerce functionality to your site.
Upgrade your site to a premium business plan in order to accept payments.
Directs the browser to navigate to the site visitor's Cart Page.
The navigateToCartPage()
function returns a Promise that resolves when the browser successfully navigates to the Cart Page.
function navigateToCartPage(): Promise<void>;
import { ecom } from "@wix/site-ecom";
import { addToCart } from "backend/addToCart";
$w("#myNavigateToCartPageButton").onClick(async () => {
// Example values for the options object
const options = {
lineItems: [
{
catalogReference: {
// Wix Stores appId
appId: "215238eb-22a5-4c36-9e7b-e7c08025e04e",
// Wix Stores productId
catalogItemId: "3fb6a3c8-988b-8755-04bd-5c59ae0b18ea",
},
quantity: 1,
},
],
};
try {
// addToCart() is defined by you in a backend file
// that calls currentCard.addToCurrentCart from the
// backend ecom SDK module.
await addToCart(options);
console.log("Item added to cart");
// Navigate to cart page after adding item
await ecom.navigateToCartPage();
} catch (error) {
console.error(error);
// Handle the error
}
});
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.