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