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 { createClient } from "@wix/sdk";
import { site } from "@wix/site";
import { ecom } from "@wix/site-ecom";
import wixEcomBackend from "wix-ecom-backend";
const wixClient = createClient({ host: site.host(), modules: { ecom } });
document
.getElementById("myNavigateToCartPageButton")
.addEventListener("click", 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 {
// The wixEcomBackend.currentCart module is universal.
// You can call its methods in frontend and backend code.
await wixEcomBackend.currentCart.addToCurrentCart(options);
console.log("item added to cart");
// navigate to cart page after adding item
await wixClient.ecom.navigateToCartPage();
} catch (error) {
console.error(error);
// Handle the error
}
});
import { createClient } from "@wix/sdk";
import { site } from "@wix/site";
import { ecom } from "@wix/site-ecom";
import wixEcomBackend from "wix-ecom-backend";
const wixClient = createClient({ host: site.host(), modules: { ecom } });
document
.getElementById("myNavigateToCartPageButton")
.addEventListener("click", 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 {
// The wixEcomBackend.currentCart module is universal.
// You can call its methods in frontend and backend code.
await wixEcomBackend.currentCart.addToCurrentCart(options);
console.log("item added to cart");
// navigate to cart page after adding item
await wixClient.ecom.navigateToCartPage();
} catch (error) {
console.error(error);
// Handle the error
}
});