Search...
onCartUpdated( )
An event that triggers when a cart is updated.
Description
The onCartUpdated()
event handler runs when a cart is updated. The received CartUpdated
object contains information about the cart that was updated and event metadata.
Note: Backend events don't work when previewing your site.
Syntax
function wixEcom_onCartUpdated(event: CartUpdated): void
onCartUpdated Parameters
NAME
TYPE
DESCRIPTION
event
Optional
CartUpdated
Information about the cart that was updated and event metadata.
Returns
This function does not return anything.
Return Type:
void
Was this helpful?
An event fired when a cart is updated
Copy Code
1// Place this code in the events.js file2// of your site's Backend section.3// Add the file if it doesn't exist.45export function wixEcom_onCartUpdated(event) {6 const cartSubtotal = event.entity.subtotal.amount;7 const cartId = event.entity._id;8 const eventId = event.metadata.id;9 console.log('Cart updated', event);10}111213/* Full event object:14 *15 * {16 * "metadata": {17 * "id": "e508b5f9-a7d2-4b37-94ce-2b7767cfa49c",18 * "entityId": "b79fd177-ec98-4245-b9f6-f09e7afa9d04",19 * "eventTime": "2022-10-27T11:42:17.211724Z",20 * "triggeredByAnonymizeRequest": false21 * },22 * "entity": {23 * "_id": "b79fd177-ec98-4245-b9f6-f09e7afa9d04",24 * "lineItems": [25 * {26 * "_id": "00000000-0000-0000-0000-000000000001",27 * "quantity": 2,28 * "catalogReference": {29 * "catalogItemId": "df19c1f7-07d8-a265-42f8-e8dfa824cc6e",30 * "appId": "215238eb-22a5-4c36-9e7b-e7c08025e04e",31 * "options": {32 * "variantId": "e62fee23-7878-437a-bf0e-292f17d11cb5"33 * }34 * },35 * "productName": {36 * "original": "Shoe",37 * "translated": "Shoe"38 * },39 * "url": "https://example.wixsite.com",40 * "price": {41 * "amount": "85",42 * "convertedAmount": "85",43 * "formattedAmount": "$85.00",44 * "formattedConvertedAmount": "$85.00"45 * },46 * "fullPrice": {47 * "amount": "85",48 * "convertedAmount": "85",49 * "formattedAmount": "$85.00",50 * "formattedConvertedAmount": "$85.00"51 * },52 * "priceBeforeDiscounts": {53 * "amount": "85",54 * "convertedAmount": "85",55 * "formattedAmount": "$85.00",56 * "formattedConvertedAmount": "$85.00"57 * },58 * "descriptionLines": [59 * {60 * "name": {61 * "original": "Color",62 * "translated": "Color"63 * },64 * "colorInfo": {65 * "original": "Black",66 * "translated": "Black",67 * "code": "#000"68 * },69 * "lineType": "UNRECOGNISED"70 * }71 * ],72 * "image": "wix:image://v1/3c76e2_bf235c38610f4d2a905db71095b351cf~mv2.jpg#originWidth=1000&originHeight=1000",73 * "availability": {74 * "status": "AVAILABLE",75 * "quantityAvailable": 3076 * },77 * "physicalProperties": {78 * "sku": "364215376135191",79 * "shippable": true80 * },81 * "couponScopes": [82 * {83 * "namespace": "stores",84 * "group": {85 * "name": "collection",86 * "entityId": "00000000-000000-000000-000000000001"87 * }88 * },89 * {90 * "namespace": "stores",91 * "group": {92 * "name": "product",93 * "entityId": "df19c1f7-07d8-a265-42f8-e8dfa824cc6e"94 * }95 * }96 * ],97 * "itemType": {98 * "preset": "PHYSICAL"99 * },100 * "paymentOption": "FULL_PAYMENT_ONLINE"101 * },102 * {103 * "_id": "00000000-0000-0000-0000-000000000002",104 * "quantity": 3,105 * "catalogReference": {106 * "catalogItemId": "1a2d7e83-4bef-31d5-09e1-3326ee271c09",107 * "appId": "215238eb-22a5-4c36-9e7b-e7c08025e04e",108 * "options": {109 * "variantId": "132b84e8-aab8-47a1-a1f6-2c47557b64a4"110 * }111 * },112 * "productName": {113 * "original": "Watch",114 * "translated": "Watch"115 * },116 * "url": "https://example.wixsite.com",117 * "price": {118 * "amount": "30",119 * "convertedAmount": "30",120 * "formattedAmount": "$30.00",121 * "formattedConvertedAmount": "$30.00"122 * },123 * "fullPrice": {124 * "amount": "30",125 * "convertedAmount": "30",126 * "formattedAmount": "$30.00",127 * "formattedConvertedAmount": "$30.00"128 * },129 * "priceBeforeDiscounts": {130 * "amount": "30",131 * "convertedAmount": "30",132 * "formattedAmount": "$30.00",133 * "formattedConvertedAmount": "$30.00"134 * },135 * "descriptionLines": [136 * {137 * "name": {138 * "original": "Size",139 * "translated": "Size"140 * },141 * "plainText": {142 * "original": "Medium",143 * "translated": "Medium"144 * },145 * "lineType": "UNRECOGNISED"146 * },147 * {148 * "name": {149 * "original": "Color",150 * "translated": "Color"151 * },152 * "colorInfo": {153 * "original": "Grey",154 * "translated": "Grey",155 * "code": "rgb(128, 128, 128)"156 * },157 * "lineType": "UNRECOGNISED"158 * }159 * ],160 * "image": "wix:image://v1/3c76e2_8891bbe3372a428aac976ac59aa0ac74~mv2.jpg#originWidth=1000&originHeight=1000",161 * "availability": {162 * "status": "AVAILABLE"163 * },164 * "physicalProperties": {165 * "sku": "217537123517253",166 * "shippable": true167 * },168 * "couponScopes": [169 * {170 * "namespace": "stores",171 * "group": {172 * "name": "collection",173 * "entityId": "00000000-000000-000000-000000000001"174 * }175 * },176 * {177 * "namespace": "stores",178 * "group": {179 * "name": "product",180 * "entityId": "1a2d7e83-4bef-31d5-09e1-3326ee271c09"181 * }182 * }183 * ],184 * "itemType": {185 * "preset": "PHYSICAL"186 * },187 * "paymentOption": "FULL_PAYMENT_ONLINE"188 * }189 * ],190 * "buyerInfo": {191 * "visitorId": "4c7ce95c-9fb3-417d-9f02-b41e82b841f7"192 * },193 * "currency": "USD",194 * "conversionCurrency": "USD",195 * "buyerLanguage": "en",196 * "siteLanguage": "en",197 * "taxIncludedInPrices": false,198 * "weightUnit": "KG",199 * "subtotal": {200 * "amount": "260",201 * "convertedAmount": "260",202 * "formattedAmount": "$260.00",203 * "formattedConvertedAmount": "$260.00"204 * },205 * "appliedDiscounts": [],206 * "inSync": false,207 * "_createdDate": "2022-06-22T11:32:29.601Z",208 * "_updatedDate": "2022-07-03T13:19:26.450Z"209 * },210 * "metadata": {211 * "id": "cac6f823-0ec7-4dd0-9147-48738c76134c",212 * "entityId": "b79fd177-ec98-4245-b9f6-f09e7afa9d04",213 * "eventTime": "2022-07-03T13:19:26.458843Z",214 * "triggeredByAnonymizeRequest": false215 * }216 * }217 *218 */