getCart( )
Retrieves a cart.
Description
The getCart()
function returns a Promise that resolves when the specified cart is retrieved.
Syntax
function getCart(_id: string): Promise<Cart>
getCart Parameters
NAME
TYPE
DESCRIPTION
ID of the cart to retrieve.
Returns
Fulfilled - The specified cart.
Return Type:
NAME
TYPE
DESCRIPTION
Date and time the cart was created.
Cart ID.
Date and time the cart was updated.
Cart discounts.
Buyer information.
Language for communication with the buyer. Defaults to the site language. For a site that supports multiple languages, this is the language the buyer selected.
ID of the checkout that originated from this cart.
Contact info.
Currency code used for all the converted prices that are returned. For a site that supports multiple currencies, this is the currency the buyer selected.
Currency used for pricing.
Line items.
overrideCheckoutUrl
allows the flexibility to redirect customers to a customized checkout page.
This field overrides the checkoutUrl
in a cart or checkout. checkoutUrl
is used to send customers back to their checkouts. By default, a checkoutUrl
generates for a checkout and directs to a standard Wix checkout page. When overrideCheckoutUrl
has a value, it will replace and set the value of checkoutUrl
.
Persistent ID that correlates between the various eCommerce elements: cart, checkout, and order.
Selected shipping option.
Site language in which original values are displayed.
Whether tax is included in line item prices.
Weight measurement unit - defaults to site's weight unit. Supported values:
"KG"
"LB"
Was this helpful?
Get a cart
1/**************************************2 * Backend code - my-backend-file.web.js *3 *************************************/45import { Permissions, webMethod } from 'wix-web-module';6import { cart } from 'wix-ecom-backend';78export const myGetCartFunction = webMethod(Permissions.Anyone, async (cartId) => {9 try {10 const retrievedCart = await cart.getCart(cartId);11 console.log('Success! Retrieved cart:', retrievedCart);12 return retrievedCart;13 } catch (error) {14 console.error(error);15 // Handle the error16 }17});1819/*************20 * Page code *21 ************/2223import { myGetCartFunction } from 'backend/my-backend-file.web';2425// Sample cartId:26const cartId = '96a61a4b-6b61-47d1-a039-0213a8230ccd';2728myGetCartFunction(cartId)29 .then((cart) => {30 const cartCheckoutId = cart.checkoutId;31 const formattedCartTotal = cart.subtotal.formattedAmount;32 const numOfCartLineItems = cart.lineItems.length;3334 console.log('Success! Retrieved cart:', cart);35 return cart;36 })37 .catch((error) => {38 console.error(error);39 // Handle the error40 });4142/* Promise resolves to:43 *44 * {45 * "_id": "96a61a4b-6b61-47d1-a039-0213a8230ccd",46 * "lineItems": [47 * {48 * "_id": "00000000-0000-0000-0000-000000000001",49 * "quantity": 3,50 * "catalogReference": {51 * "catalogItemId": "c8539b66-7a44-fe18-affc-afec4be8562a",52 * "appId": "215238eb-22a5-4c36-9e7b-e7c08025e04e"53 * },54 * "productName": {55 * "original": "Shirt",56 * "translated": "Shirt"57 * },58 * "url": "https://example.wixsite.com",59 * "price": {60 * "amount": "10",61 * "convertedAmount": "10",62 * "formattedAmount": "€10.00",63 * "formattedConvertedAmount": "€10.00"64 * },65 * "fullPrice": {66 * "amount": "10",67 * "convertedAmount": "10",68 * "formattedAmount": "€10.00",69 * "formattedConvertedAmount": "€10.00"70 * },71 * "priceBeforeDiscounts": {72 * "amount": "10",73 * "convertedAmount": "10",74 * "formattedAmount": "€10.00",75 * "formattedConvertedAmount": "€10.00"76 * },77 * "descriptionLines": [],78 * "image": "wix:image://v1/3c76e2_c5331f937348492a97df87b0a3b34ea4~mv2.jpg#originWidth=1000&originHeight=1000",79 * "availability": {80 * "status": "AVAILABLE"81 * },82 * "physicalProperties": {83 * "sku": "364115376135191",84 * "shippable": true85 * },86 * "couponScopes": [87 * {88 * "namespace": "stores",89 * "group": {90 * "name": "collection",91 * "entityId": "00000000-000000-000000-000000000001"92 * }93 * },94 * {95 * "namespace": "stores",96 * "group": {97 * "name": "product",98 * "entityId": "c8539b66-7a44-fe18-affc-afec4be8562a"99 * }100 * }101 * ],102 * "itemType": {103 * "preset": "PHYSICAL"104 * },105 * "paymentOption": "FULL_PAYMENT_ONLINE"106 * }107 * ],108 * "buyerInfo": {109 * "contactId": "f7dc17a6-825a-466e-a78e-c4abea0217db",110 * "memberId": "c43190d2-eea3-493e-b6e8-f146850c6873"111 * },112 * "currency": "EUR",113 * "conversionCurrency": "EUR",114 * "buyerLanguage": "en",115 * "siteLanguage": "en",116 * "taxIncludedInPrices": false,117 * "weightUnit": "KG",118 * "subtotal": {119 * "amount": "30",120 * "convertedAmount": "30",121 * "formattedAmount": "€30.00",122 * "formattedConvertedAmount": "€30.00"123 * },124 * "appliedDiscounts": [],125 * "inSync": false,126 * "_createdDate": "2022-05-16T12:04:01.244Z",127 * "_updatedDate": "2022-05-16T12:04:01.244Z"128 * }129 *130 */