Adds catalog line items and/or custom line items to a checkout.
The addToCheckout()
function returns a Promise that resolves to the updated checkout when the specified items have been added.
Note: When adding catalog items, options.lineItems.catalogReference
is required.
function addToCheckout(
_id: string,
options: AddToCheckoutOptions,
): Promise<AddToCheckoutResponse>;
Checkout ID.
Items to be added to checkout.
/**************************************
* Backend code - my-backend-file.jsw *
*************************************/
import { checkout } from "wix-ecom-backend";
export async function myAddToCheckoutFunction(_id, options) {
try {
const updatedCheckout = await checkout.addToCheckout(_id, options);
console.log("Success! Updated checkout:", updatedCheckout);
return updatedCheckout;
} catch (error) {
console.error(error);
// Handle the error
}
}
/*************
* Page code *
************/
import { myAddToCheckoutFunction } from "backend/my-backend-file";
// Sample checkout ID:
const _id = "63879d9f-0d1c-49aa-a0c5-5fc612a24ec7";
// Sample addToCheckout options:
const options = {
lineItems: [
{
catalogReference: {
// Wix Stores appId
appId: "215238eb-22a5-4c36-9e7b-e7c08025e04e",
// Wix Stores productId
catalogItemId: "df19c1f7-07d8-a265-42f8-e8dfa824cc6e",
// Wix Stores variantId
options: {
variantId: "e62fee23-7878-437a-bf0e-292f17d11cb5",
},
},
quantity: 1,
},
],
};
myAddToCheckoutFunction(_id, options)
.then((updatedCheckout) => {
const checkoutSubtotal = updatedCheckout.priceSummary.subtotal.amount;
const numberOfCheckoutLineItems = updatedCheckout.lineItems.length;
console.log("Success! Updated checkout:", updatedCheckout);
return updatedCheckout;
})
.catch((error) => {
console.error(error);
// Handle the error
});
/* Promise resolves to:
*
* {
* "_id": "63879d9f-0d1c-49aa-a0c5-5fc612a24ec7",
* "lineItems": [
* {
* "_id": "00000000-0000-0000-0000-000000000001",
* "quantity": 1,
* "catalogReference": {
* "catalogItemId": "c8539b66-7a44-fe18-affc-afec4be8562a",
* "appId": "215238eb-22a5-4c36-9e7b-e7c08025e04e"
* },
* "productName": {
* "original": "Shirt",
* "translated": "Shirt"
* },
* "url": "https://example.wixsite.com/ep-tester/product-page/shirt",
* "price": {
* "amount": "10",
* "convertedAmount": "10",
* "formattedAmount": "$10.00",
* "formattedConvertedAmount": "$10.00"
* },
* "lineItemPrice": {
* "amount": "10",
* "convertedAmount": "10",
* "formattedAmount": "$10.00",
* "formattedConvertedAmount": "$10.00"
* },
* "fullPrice": {
* "amount": "10",
* "convertedAmount": "10",
* "formattedAmount": "$10.00",
* "formattedConvertedAmount": "$10.00"
* },
* "priceBeforeDiscounts": {
* "amount": "10",
* "convertedAmount": "10",
* "formattedAmount": "$10.00",
* "formattedConvertedAmount": "$10.00"
* },
* "totalPriceAfterTax": {
* "amount": "10",
* "convertedAmount": "10",
* "formattedAmount": "$10.00",
* "formattedConvertedAmount": "$10.00"
* },
* "totalPriceBeforeTax": {
* "amount": "10",
* "convertedAmount": "10",
* "formattedAmount": "$10.00",
* "formattedConvertedAmount": "$10.00"
* },
* "taxDetails": {
* "taxableAmount": {
* "amount": "10",
* "convertedAmount": "10",
* "formattedAmount": "$10.00",
* "formattedConvertedAmount": "$10.00"
* },
* "taxRate": "0",
* "totalTax": {
* "amount": "0",
* "convertedAmount": "0",
* "formattedAmount": "$0.00",
* "formattedConvertedAmount": "$0.00"
* },
* "rateBreakdown": []
* },
* "discount": {
* "amount": "0",
* "convertedAmount": "0",
* "formattedAmount": "$0.00",
* "formattedConvertedAmount": "$0.00"
* },
* "descriptionLines": [],
* "media": "wix:image://v1/3c76e2_c5331f937348492a97df87b0a3b34ea4~mv2.jpg#originWidth=1000&originHeight=1000",
* "availability": {
* "status": "AVAILABLE"
* },
* "physicalProperties": {
* "sku": "364115376135191",
* "shippable": true
* },
* "couponScopes": [
* {
* "namespace": "stores",
* "group": {
* "name": "collection",
* "entityId": "00000000-000000-000000-000000000001"
* }
* },
* {
* "namespace": "stores",
* "group": {
* "name": "product",
* "entityId": "c8539b66-7a44-fe18-affc-afec4be8562a"
* }
* }
* ],
* "itemType": {
* "preset": "PHYSICAL"
* },
* "paymentOption": "FULL_PAYMENT_ONLINE",
* "rootCatalogItemId": "c8539b66-7a44-fe18-affc-afec4be8562a"
* },
* {
* "_id": "00000000-0000-0000-0000-000000000002",
* "quantity": 1,
* "catalogReference": {
* "catalogItemId": "df19c1f7-07d8-a265-42f8-e8dfa824cc6e",
* "appId": "215238eb-22a5-4c36-9e7b-e7c08025e04e",
* "options": {
* "variantId": "e62fee23-7878-437a-bf0e-292f17d11cb5"
* }
* },
* "productName": {
* "original": "Shoe",
* "translated": "Shoe"
* },
* "url": "https://example.wixsite.com/ep-tester/product-page/shoe",
* "price": {
* "amount": "85",
* "convertedAmount": "85",
* "formattedAmount": "$85.00",
* "formattedConvertedAmount": "$85.00"
* },
* "lineItemPrice": {
* "amount": "85",
* "convertedAmount": "85",
* "formattedAmount": "$85.00",
* "formattedConvertedAmount": "$85.00"
* },
* "fullPrice": {
* "amount": "85",
* "convertedAmount": "85",
* "formattedAmount": "$85.00",
* "formattedConvertedAmount": "$85.00"
* },
* "priceBeforeDiscounts": {
* "amount": "85",
* "convertedAmount": "85",
* "formattedAmount": "$85.00",
* "formattedConvertedAmount": "$85.00"
* },
* "totalPriceAfterTax": {
* "amount": "85",
* "convertedAmount": "85",
* "formattedAmount": "$85.00",
* "formattedConvertedAmount": "$85.00"
* },
* "totalPriceBeforeTax": {
* "amount": "85",
* "convertedAmount": "85",
* "formattedAmount": "$85.00",
* "formattedConvertedAmount": "$85.00"
* },
* "taxDetails": {
* "taxableAmount": {
* "amount": "85",
* "convertedAmount": "85",
* "formattedAmount": "$85.00",
* "formattedConvertedAmount": "$85.00"
* },
* "taxRate": "0",
* "totalTax": {
* "amount": "0",
* "convertedAmount": "0",
* "formattedAmount": "$0.00",
* "formattedConvertedAmount": "$0.00"
* },
* "rateBreakdown": []
* },
* "discount": {
* "amount": "0",
* "convertedAmount": "0",
* "formattedAmount": "$0.00",
* "formattedConvertedAmount": "$0.00"
* },
* "descriptionLines": [
* {
* "name": {
* "original": "Color",
* "translated": "Color"
* },
* "colorInfo": {
* "original": "Black",
* "translated": "Black",
* "code": "#000"
* },
* "lineType": "COLOR",
* "color": "Black"
* }
* ],
* "media": "wix:image://v1/3c76e2_bf235c38610f4d2a905db71095b351cf~mv2.jpg#originWidth=1000&originHeight=1000",
* "availability": {
* "status": "AVAILABLE",
* "quantityAvailable": 30
* },
* "physicalProperties": {
* "sku": "364215376135191",
* "shippable": true
* },
* "couponScopes": [
* {
* "namespace": "stores",
* "group": {
* "name": "collection",
* "entityId": "00000000-000000-000000-000000000001"
* }
* },
* {
* "namespace": "stores",
* "group": {
* "name": "product",
* "entityId": "df19c1f7-07d8-a265-42f8-e8dfa824cc6e"
* }
* }
* ],
* "itemType": {
* "preset": "PHYSICAL"
* },
* "paymentOption": "FULL_PAYMENT_ONLINE",
* "rootCatalogItemId": "df19c1f7-07d8-a265-42f8-e8dfa824cc6e"
* }
* ],
* "shippingInfo": {
* "carrierServiceOptions": []
* },
* "buyerInfo": {
* "contactId": "f7dc17a6-825a-466e-a78e-c4abea0217db",
* "memberId": "c43190d2-eea3-493e-b6e8-f146850c6873"
* },
* "conversionCurrency": "USD",
* "priceSummary": {
* "subtotal": {
* "amount": "95",
* "convertedAmount": "95",
* "formattedAmount": "$95.00",
* "formattedConvertedAmount": "$95.00"
* },
* "shipping": {
* "amount": "0",
* "convertedAmount": "0",
* "formattedAmount": "$0.00",
* "formattedConvertedAmount": "$0.00"
* },
* "tax": {
* "amount": "0",
* "convertedAmount": "0",
* "formattedAmount": "$0.00",
* "formattedConvertedAmount": "$0.00"
* },
* "discount": {
* "amount": "0",
* "convertedAmount": "0",
* "formattedAmount": "$0.00",
* "formattedConvertedAmount": "$0.00"
* },
* "total": {
* "amount": "95",
* "convertedAmount": "95",
* "formattedAmount": "$95.00",
* "formattedConvertedAmount": "$95.00"
* },
* "additionalFees": {
* "amount": "0",
* "convertedAmount": "0",
* "formattedAmount": "$0.00",
* "formattedConvertedAmount": "$0.00"
* }
* },
* "calculationErrors": {
* "orderValidationErrors": []
* },
* "appliedDiscounts": [],
* "customFields": [],
* "weightUnit": "KG",
* "currency": "USD",
* "channelType": "WEB",
* "siteLanguage": "en",
* "buyerLanguage": "en",
* "completed": false,
* "taxIncludedInPrice": false,
* "createdBy": {
* "memberId": "c43190d2-eea3-493e-b6e8-f146850c6873"
* },
* "_createdDate": "2023-01-04T15:11:20.762Z",
* "_updatedDate": "2023-01-04T15:15:24.035Z",
* "payNow": {
* "subtotal": {
* "amount": "95",
* "convertedAmount": "95",
* "formattedAmount": "$95.00",
* "formattedConvertedAmount": "$95.00"
* },
* "shipping": {
* "amount": "0",
* "convertedAmount": "0",
* "formattedAmount": "$0.00",
* "formattedConvertedAmount": "$0.00"
* },
* "tax": {
* "amount": "0",
* "convertedAmount": "0",
* "formattedAmount": "$0.00",
* "formattedConvertedAmount": "$0.00"
* },
* "discount": {
* "amount": "0",
* "convertedAmount": "0",
* "formattedAmount": "$0.00",
* "formattedConvertedAmount": "$0.00"
* },
* "total": {
* "amount": "95",
* "convertedAmount": "95",
* "formattedAmount": "$95.00",
* "formattedConvertedAmount": "$95.00"
* },
* "additionalFees": {
* "amount": "0",
* "convertedAmount": "0",
* "formattedAmount": "$0.00",
* "formattedConvertedAmount": "$0.00"
* }
* },
* "payLater": {
* "subtotal": {
* "amount": "0",
* "convertedAmount": "0",
* "formattedAmount": "$0.00",
* "formattedConvertedAmount": "$0.00"
* },
* "shipping": {
* "amount": "0",
* "convertedAmount": "0",
* "formattedAmount": "$0.00",
* "formattedConvertedAmount": "$0.00"
* },
* "tax": {
* "amount": "0",
* "convertedAmount": "0",
* "formattedAmount": "$0.00",
* "formattedConvertedAmount": "$0.00"
* },
* "discount": {
* "amount": "0",
* "convertedAmount": "0",
* "formattedAmount": "$0.00",
* "formattedConvertedAmount": "$0.00"
* },
* "total": {
* "amount": "0",
* "convertedAmount": "0",
* "formattedAmount": "$0.00",
* "formattedConvertedAmount": "$0.00"
* },
* "additionalFees": {
* "amount": "0",
* "convertedAmount": "0",
* "formattedAmount": "$0.00",
* "formattedConvertedAmount": "$0.00"
* }
* },
* "membershipOptions": {
* "eligibleMemberships": [],
* "invalidMemberships": [],
* "selectedMemberships": {
* "memberships": []
* }
* },
* "additionalFees": [],
* "payNowTotalAfterGiftCard": {
* "amount": "95",
* "convertedAmount": "95",
* "formattedAmount": "$95.00",
* "formattedConvertedAmount": "$95.00"
* }
* }
*
*/
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.