Search...
addToCheckout( )
Adds catalog line items and/or custom line items to a checkout.
Description
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.
Syntax
function addToCheckout(_id: string, options: AddToCheckoutOptions): Promise<AddToCheckoutResponse>
addToCheckout Parameters
NAME
TYPE
DESCRIPTION
_id
string
Checkout ID.
options
Optional
AddToCheckoutOptions
Items to be added to checkout.
Returns
Return Type:
Promise<
AddToCheckoutResponse
>NAME
TYPE
DESCRIPTION
checkout
Checkout
Updated checkout.
Was this helpful?
Add a catalog item to a checkout
Copy Code
1/**************************************2 * Backend code - my-backend-file.jsw *3 *************************************/45import { checkout } from 'wix-ecom-backend';67export async function myAddToCheckoutFunction(_id, options) {8 try {9 const updatedCheckout = await checkout.addToCheckout(_id, options);10 console.log('Success! Updated checkout:', updatedCheckout);11 return updatedCheckout;12 } catch (error) {13 console.error(error);14 // Handle the error15 }16}1718/*************19 * Page code *20 ************/2122import { myAddToCheckoutFunction } from 'backend/my-backend-file';2324// Sample checkout ID:25const _id = "63879d9f-0d1c-49aa-a0c5-5fc612a24ec7";26// Sample addToCheckout options:27const options = {28 "lineItems": [{29 "catalogReference": {30 // Wix Stores appId31 "appId": "1380b703-ce81-ff05-f115-39571d94dfcd",32 // Wix Stores productId33 "catalogItemId": "df19c1f7-07d8-a265-42f8-e8dfa824cc6e",34 // Wix Stores variantId35 "options": {36 "variantId": "e62fee23-7878-437a-bf0e-292f17d11cb5"37 }38 },39 "quantity": 140 }]41};4243myAddToCheckoutFunction(_id, options)44 .then((updatedCheckout) => {45 const checkoutSubtotal = updatedCheckout.priceSummary.subtotal.amount;46 const numberOfCheckoutLineItems = updatedCheckout.lineItems.length;4748 console.log('Success! Updated checkout:', updatedCheckout);49 return updatedCheckout;50 })51 .catch((error) => {52 console.error(error);53 // Handle the error54 });5556/* Promise resolves to:57 *58 * {59 * "_id": "63879d9f-0d1c-49aa-a0c5-5fc612a24ec7",60 * "lineItems": [61 * {62 * "_id": "00000000-0000-0000-0000-000000000001",63 * "quantity": 1,64 * "catalogReference": {65 * "catalogItemId": "c8539b66-7a44-fe18-affc-afec4be8562a",66 * "appId": "1380b703-ce81-ff05-f115-39571d94dfcd"67 * },68 * "productName": {69 * "original": "Shirt",70 * "translated": "Shirt"71 * },72 * "url": "https://example.wixsite.com/ep-tester/product-page/shirt",73 * "price": {74 * "amount": "10",75 * "convertedAmount": "10",76 * "formattedAmount": "$10.00",77 * "formattedConvertedAmount": "$10.00"78 * },79 * "lineItemPrice": {80 * "amount": "10",81 * "convertedAmount": "10",82 * "formattedAmount": "$10.00",83 * "formattedConvertedAmount": "$10.00"84 * },85 * "fullPrice": {86 * "amount": "10",87 * "convertedAmount": "10",88 * "formattedAmount": "$10.00",89 * "formattedConvertedAmount": "$10.00"90 * },91 * "priceBeforeDiscounts": {92 * "amount": "10",93 * "convertedAmount": "10",94 * "formattedAmount": "$10.00",95 * "formattedConvertedAmount": "$10.00"96 * },97 * "totalPriceAfterTax": {98 * "amount": "10",99 * "convertedAmount": "10",100 * "formattedAmount": "$10.00",101 * "formattedConvertedAmount": "$10.00"102 * },103 * "totalPriceBeforeTax": {104 * "amount": "10",105 * "convertedAmount": "10",106 * "formattedAmount": "$10.00",107 * "formattedConvertedAmount": "$10.00"108 * },109 * "taxDetails": {110 * "taxableAmount": {111 * "amount": "10",112 * "convertedAmount": "10",113 * "formattedAmount": "$10.00",114 * "formattedConvertedAmount": "$10.00"115 * },116 * "taxRate": "0",117 * "totalTax": {118 * "amount": "0",119 * "convertedAmount": "0",120 * "formattedAmount": "$0.00",121 * "formattedConvertedAmount": "$0.00"122 * },123 * "rateBreakdown": []124 * },125 * "discount": {126 * "amount": "0",127 * "convertedAmount": "0",128 * "formattedAmount": "$0.00",129 * "formattedConvertedAmount": "$0.00"130 * },131 * "descriptionLines": [],132 * "media": "wix:image://v1/3c76e2_c5331f937348492a97df87b0a3b34ea4~mv2.jpg#originWidth=1000&originHeight=1000",133 * "availability": {134 * "status": "AVAILABLE"135 * },136 * "physicalProperties": {137 * "sku": "364115376135191",138 * "shippable": true139 * },140 * "couponScopes": [141 * {142 * "namespace": "stores",143 * "group": {144 * "name": "collection",145 * "entityId": "00000000-000000-000000-000000000001"146 * }147 * },148 * {149 * "namespace": "stores",150 * "group": {151 * "name": "product",152 * "entityId": "c8539b66-7a44-fe18-affc-afec4be8562a"153 * }154 * }155 * ],156 * "itemType": {157 * "preset": "PHYSICAL"158 * },159 * "paymentOption": "FULL_PAYMENT_ONLINE",160 * "rootCatalogItemId": "c8539b66-7a44-fe18-affc-afec4be8562a"161 * },162 * {163 * "_id": "00000000-0000-0000-0000-000000000002",164 * "quantity": 1,165 * "catalogReference": {166 * "catalogItemId": "df19c1f7-07d8-a265-42f8-e8dfa824cc6e",167 * "appId": "1380b703-ce81-ff05-f115-39571d94dfcd",168 * "options": {169 * "variantId": "e62fee23-7878-437a-bf0e-292f17d11cb5"170 * }171 * },172 * "productName": {173 * "original": "Shoe",174 * "translated": "Shoe"175 * },176 * "url": "https://example.wixsite.com/ep-tester/product-page/shoe",177 * "price": {178 * "amount": "85",179 * "convertedAmount": "85",180 * "formattedAmount": "$85.00",181 * "formattedConvertedAmount": "$85.00"182 * },183 * "lineItemPrice": {184 * "amount": "85",185 * "convertedAmount": "85",186 * "formattedAmount": "$85.00",187 * "formattedConvertedAmount": "$85.00"188 * },189 * "fullPrice": {190 * "amount": "85",191 * "convertedAmount": "85",192 * "formattedAmount": "$85.00",193 * "formattedConvertedAmount": "$85.00"194 * },195 * "priceBeforeDiscounts": {196 * "amount": "85",197 * "convertedAmount": "85",198 * "formattedAmount": "$85.00",199 * "formattedConvertedAmount": "$85.00"200 * },201 * "totalPriceAfterTax": {202 * "amount": "85",203 * "convertedAmount": "85",204 * "formattedAmount": "$85.00",205 * "formattedConvertedAmount": "$85.00"206 * },207 * "totalPriceBeforeTax": {208 * "amount": "85",209 * "convertedAmount": "85",210 * "formattedAmount": "$85.00",211 * "formattedConvertedAmount": "$85.00"212 * },213 * "taxDetails": {214 * "taxableAmount": {215 * "amount": "85",216 * "convertedAmount": "85",217 * "formattedAmount": "$85.00",218 * "formattedConvertedAmount": "$85.00"219 * },220 * "taxRate": "0",221 * "totalTax": {222 * "amount": "0",223 * "convertedAmount": "0",224 * "formattedAmount": "$0.00",225 * "formattedConvertedAmount": "$0.00"226 * },227 * "rateBreakdown": []228 * },229 * "discount": {230 * "amount": "0",231 * "convertedAmount": "0",232 * "formattedAmount": "$0.00",233 * "formattedConvertedAmount": "$0.00"234 * },235 * "descriptionLines": [236 * {237 * "name": {238 * "original": "Color",239 * "translated": "Color"240 * },241 * "colorInfo": {242 * "original": "Black",243 * "translated": "Black",244 * "code": "#000"245 * },246 * "lineType": "COLOR",247 * "color": "Black"248 * }249 * ],250 * "media": "wix:image://v1/3c76e2_bf235c38610f4d2a905db71095b351cf~mv2.jpg#originWidth=1000&originHeight=1000",251 * "availability": {252 * "status": "AVAILABLE",253 * "quantityAvailable": 30254 * },255 * "physicalProperties": {256 * "sku": "364215376135191",257 * "shippable": true258 * },259 * "couponScopes": [260 * {261 * "namespace": "stores",262 * "group": {263 * "name": "collection",264 * "entityId": "00000000-000000-000000-000000000001"265 * }266 * },267 * {268 * "namespace": "stores",269 * "group": {270 * "name": "product",271 * "entityId": "df19c1f7-07d8-a265-42f8-e8dfa824cc6e"272 * }273 * }274 * ],275 * "itemType": {276 * "preset": "PHYSICAL"277 * },278 * "paymentOption": "FULL_PAYMENT_ONLINE",279 * "rootCatalogItemId": "df19c1f7-07d8-a265-42f8-e8dfa824cc6e"280 * }281 * ],282 * "shippingInfo": {283 * "carrierServiceOptions": []284 * },285 * "buyerInfo": {286 * "contactId": "f7dc17a6-825a-466e-a78e-c4abea0217db",287 * "memberId": "c43190d2-eea3-493e-b6e8-f146850c6873"288 * },289 * "conversionCurrency": "USD",290 * "priceSummary": {291 * "subtotal": {292 * "amount": "95",293 * "convertedAmount": "95",294 * "formattedAmount": "$95.00",295 * "formattedConvertedAmount": "$95.00"296 * },297 * "shipping": {298 * "amount": "0",299 * "convertedAmount": "0",300 * "formattedAmount": "$0.00",301 * "formattedConvertedAmount": "$0.00"302 * },303 * "tax": {304 * "amount": "0",305 * "convertedAmount": "0",306 * "formattedAmount": "$0.00",307 * "formattedConvertedAmount": "$0.00"308 * },309 * "discount": {310 * "amount": "0",311 * "convertedAmount": "0",312 * "formattedAmount": "$0.00",313 * "formattedConvertedAmount": "$0.00"314 * },315 * "total": {316 * "amount": "95",317 * "convertedAmount": "95",318 * "formattedAmount": "$95.00",319 * "formattedConvertedAmount": "$95.00"320 * },321 * "additionalFees": {322 * "amount": "0",323 * "convertedAmount": "0",324 * "formattedAmount": "$0.00",325 * "formattedConvertedAmount": "$0.00"326 * }327 * },328 * "calculationErrors": {329 * "orderValidationErrors": []330 * },331 * "appliedDiscounts": [],332 * "customFields": [],333 * "weightUnit": "KG",334 * "currency": "USD",335 * "channelType": "WEB",336 * "siteLanguage": "en",337 * "buyerLanguage": "en",338 * "completed": false,339 * "taxIncludedInPrice": false,340 * "createdBy": {341 * "memberId": "c43190d2-eea3-493e-b6e8-f146850c6873"342 * },343 * "_createdDate": "2023-01-04T15:11:20.762Z",344 * "_updatedDate": "2023-01-04T15:15:24.035Z",345 * "payNow": {346 * "subtotal": {347 * "amount": "95",348 * "convertedAmount": "95",349 * "formattedAmount": "$95.00",350 * "formattedConvertedAmount": "$95.00"351 * },352 * "shipping": {353 * "amount": "0",354 * "convertedAmount": "0",355 * "formattedAmount": "$0.00",356 * "formattedConvertedAmount": "$0.00"357 * },358 * "tax": {359 * "amount": "0",360 * "convertedAmount": "0",361 * "formattedAmount": "$0.00",362 * "formattedConvertedAmount": "$0.00"363 * },364 * "discount": {365 * "amount": "0",366 * "convertedAmount": "0",367 * "formattedAmount": "$0.00",368 * "formattedConvertedAmount": "$0.00"369 * },370 * "total": {371 * "amount": "95",372 * "convertedAmount": "95",373 * "formattedAmount": "$95.00",374 * "formattedConvertedAmount": "$95.00"375 * },376 * "additionalFees": {377 * "amount": "0",378 * "convertedAmount": "0",379 * "formattedAmount": "$0.00",380 * "formattedConvertedAmount": "$0.00"381 * }382 * },383 * "payLater": {384 * "subtotal": {385 * "amount": "0",386 * "convertedAmount": "0",387 * "formattedAmount": "$0.00",388 * "formattedConvertedAmount": "$0.00"389 * },390 * "shipping": {391 * "amount": "0",392 * "convertedAmount": "0",393 * "formattedAmount": "$0.00",394 * "formattedConvertedAmount": "$0.00"395 * },396 * "tax": {397 * "amount": "0",398 * "convertedAmount": "0",399 * "formattedAmount": "$0.00",400 * "formattedConvertedAmount": "$0.00"401 * },402 * "discount": {403 * "amount": "0",404 * "convertedAmount": "0",405 * "formattedAmount": "$0.00",406 * "formattedConvertedAmount": "$0.00"407 * },408 * "total": {409 * "amount": "0",410 * "convertedAmount": "0",411 * "formattedAmount": "$0.00",412 * "formattedConvertedAmount": "$0.00"413 * },414 * "additionalFees": {415 * "amount": "0",416 * "convertedAmount": "0",417 * "formattedAmount": "$0.00",418 * "formattedConvertedAmount": "$0.00"419 * }420 * },421 * "membershipOptions": {422 * "eligibleMemberships": [],423 * "invalidMemberships": [],424 * "selectedMemberships": {425 * "memberships": []426 * }427 * },428 * "additionalFees": [],429 * "payNowTotalAfterGiftCard": {430 * "amount": "95",431 * "convertedAmount": "95",432 * "formattedAmount": "$95.00",433 * "formattedConvertedAmount": "$95.00"434 * }435 * }436 *437 */438