An event that triggers when a new cart is created.
The onCartCreated()
event handler runs when a new cart is created. The received CartCreated
object contains information about the cart that was created and event metadata.
Note: Backend events don't work when previewing your site.
function wixEcom_onCartCreated(event: CartCreated): void;
Information about the cart that was created and event metadata.
// Place this code in the events.js file
// of your site's Backend section.
// Add the file if it doesn't exist.
export function wixEcom_onCartCreated(event) {
const cartSubtotal = event.entity.subtotal.amount;
const cartId = event.entity._id;
const eventId = event.metadata.id;
console.log("Cart created", event);
}
/* Full event object:
*
* {
* "metadata": {
* "id": "ba8e0c2e-dd90-4060-b83c-2590aa075b65",
* "entityId": "1c68f377-4e8f-47c1-bc72-01b18a23cb08",
* "eventTime": "2022-07-04T12:47:21.376865Z",
* "triggeredByAnonymizeRequest": false
* },
* "entity": {
* "_id": "1c68f377-4e8f-47c1-bc72-01b18a23cb08",
* "lineItems": [
* {
* "_id": "00000000-0000-0000-0000-000000000001",
* "quantity": 3,
* "catalogReference": {
* "catalogItemId": "df19c1f7-07d8-a265-42f8-e8dfa824cc6e",
* "appId": "215238eb-22a5-4c36-9e7b-e7c08025e04e",
* "options": {
* "variantId": "e62fee23-7878-437a-bf0e-292f17d11cb5"
* }
* },
* "productName": {
* "original": "Shoe",
* "translated": "Shoe"
* },
* "url": "https://example.wixsite.com",
* "price": {
* "amount": "85",
* "convertedAmount": "85",
* "formattedAmount": "$85.00",
* "formattedConvertedAmount": "$85.00"
* },
* "fullPrice": {
* "amount": "85",
* "convertedAmount": "85",
* "formattedAmount": "$85.00",
* "formattedConvertedAmount": "$85.00"
* },
* "priceBeforeDiscounts": {
* "amount": "85",
* "convertedAmount": "85",
* "formattedAmount": "$85.00",
* "formattedConvertedAmount": "$85.00"
* },
* "descriptionLines": [
* {
* "name": {
* "original": "Color",
* "translated": "Color"
* },
* "colorInfo": {
* "original": "Black",
* "translated": "Black",
* "code": "#000"
* },
* "lineType": "UNRECOGNISED"
* }
* ],
* "image": "wix:image://v1/3c76e2_bf235c38610f4d2a905db71095b351cf~mv2.jpg#originWidth=1000&originHeight=1000",
* "availability": {
* "status": "AVAILABLE",
* "quantityAvailable": 30
* },
* "physicalProperties": {
* "sku": "364215376135191",
* "shippable": true
* },
* "couponScopes": [
* {
* "namespace": "stores",
* "group": {
* "name": "collection",
* "entityId": "00000000-000000-000000-000000000001"
* }
* },
* {
* "namespace": "stores",
* "group": {
* "name": "product",
* "entityId": "df19c1f7-07d8-a265-42f8-e8dfa824cc6e"
* }
* }
* ],
* "itemType": {
* "preset": "PHYSICAL"
* },
* "paymentOption": "FULL_PAYMENT_ONLINE"
* }
* ],
* "buyerInfo": {
* "visitorId": "4c7ce95c-9fb3-417d-9f02-b41e82b841f7"
* },
* "currency": "USD",
* "conversionCurrency": "USD",
* "buyerLanguage": "en",
* "siteLanguage": "en",
* "taxIncludedInPrices": false,
* "weightUnit": "KG",
* "subtotal": {
* "amount": "255",
* "convertedAmount": "255",
* "formattedAmount": "$255.00",
* "formattedConvertedAmount": "$255.00"
* },
* "appliedDiscounts": [],
* "inSync": false,
* "_createdDate": "2022-07-04T12:47:21.371Z",
* "_updatedDate": "2022-07-04T12:47:21.371Z"
* }
* }
*
*/
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.