updateCart( )
Updates a specified cart's properties.
Description
The updateCart()
function returns a Promise that resolves when the specified cart's properties are updated.
Note: When updating catalog items,
options.lineItems.catalogReference
is required.
Syntax
function updateCart(_id: string, options: UpdateCartOptions): Promise<Cart>
updateCart Parameters
NAME
TYPE
DESCRIPTION
ID of the cart to be updated.
Available options to use when updating a cart.
Returns
Fulfilled - Updated 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?
Update a cart
Apply a coupon to 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 myUpdateCartFunction = webMethod(Permissions.Anyone, async (_id, options) => {9 try {10 const updatedCart = await cart.updateCart(_id, options);11 console.log('Success! Updated cart:', updatedCart);12 return updatedCart;13 } catch (error) {14 console.error(error);15 // Handle the error16 }17});1819/*************20 * Page code *21 ************/2223import { myUpdateCartFunction } from 'backend/my-backend-file.web';2425// Sample cartId:26const _id = 'ba47a627-7bb8-4918-89b2-6a72af464765';2728// Coupon code to be applied to the cart29const updateOptions = {30 "couponCode": "SUMMERSALE10"31}3233myUpdateCartFunction(_id, updateOptions)34 .then((updatedCart) => {35 // appliedCoupon boolean resolves to true if coupon object exists36 const appliedCoupon = !!updatedCart.appliedDiscounts[0].coupon3738 console.log('Success! Updated cart:', updatedCart);39 return updatedCart;40 })41 .catch((error) => {42 console.error(error);43 // Handle the error44 });4546/* Promise resolves to:47 *48 * {49 * "_id": "ba47a627-7bb8-4918-89b2-6a72af464765",50 * "appliedDiscounts": [51 * {52 * "coupon": {53 * "_id": "fbb94b06-7447-4161-9c48-59bfcdc39e77",54 * "code": "SUMMERSALE10"55 * }56 * }57 * ],58 * "lineItems": [59 * {60 * "_id": "00000000-0000-0000-0000-000000000001",61 * "quantity": 1,62 * "catalogReference": {63 * "catalogItemId": "c8539b66-7a44-fe18-affc-afec4be8562a",64 * "appId": "215238eb-22a5-4c36-9e7b-e7c08025e04e"65 * },66 * "productName": {67 * "original": "Shirt",68 * "translated": "Shirt"69 * },70 * "url": "https://example.wixsite.com",71 * "price": {72 * "amount": "10",73 * "convertedAmount": "10",74 * "formattedAmount": "€10.00",75 * "formattedConvertedAmount": "€10.00"76 * },77 * "fullPrice": {78 * "amount": "10",79 * "convertedAmount": "10",80 * "formattedAmount": "€10.00",81 * "formattedConvertedAmount": "€10.00"82 * },83 * "priceBeforeDiscounts": {84 * "amount": "10",85 * "convertedAmount": "10",86 * "formattedAmount": "€10.00",87 * "formattedConvertedAmount": "€10.00"88 * },89 * "descriptionLines": [],90 * "image": "wix:image://v1/3c76e2_c5331f937348492a97df87b0a3b34ea4~mv2.jpg#originWidth=1000&originHeight=1000",91 * "availability": {92 * "status": "AVAILABLE"93 * },94 * "physicalProperties": {95 * "sku": "364115376135191",96 * "shippable": true97 * },98 * "couponScopes": [99 * {100 * "namespace": "stores",101 * "group": {102 * "name": "collection",103 * "entityId": "00000000-000000-000000-000000000001"104 * }105 * },106 * {107 * "namespace": "stores",108 * "group": {109 * "name": "product",110 * "entityId": "c8539b66-7a44-fe18-affc-afec4be8562a"111 * }112 * }113 * ],114 * "itemType": {115 * "preset": "PHYSICAL"116 * },117 * "paymentOption": "FULL_PAYMENT_ONLINE"118 * }119 * ],120 * "buyerInfo": {121 * "visitorId": "4c7ce95c-9fb3-417d-9f02-b41e82b841f7"122 * },123 * "currency": "EUR",124 * "conversionCurrency": "EUR",125 * "buyerLanguage": "en",126 * "siteLanguage": "en",127 * "taxIncludedInPrices": false,128 * "weightUnit": "KG",129 * "subtotal": {130 * "amount": "10",131 * "convertedAmount": "10",132 * "formattedAmount": "€10.00",133 * "formattedConvertedAmount": "€10.00"134 * },135 * "inSync": true,136 * "_createdDate": "2022-05-15T11:31:30.484Z",137 * "_updatedDate": "2022-06-16T09:20:23.388Z"138 * }139 *140 */