Created
September 14, 2022 05:56
-
-
Save agehlot/9e68acbcbb873cdbe74b19c7bce09a8f to your computer and use it in GitHub Desktop.
Sitecore CDP-Decision model: Programmable to get the list of product in abandoned cart. Previous example was to get the product detail in ul/li but this sample return the product list as an object.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function () { | |
function getTriggeredSession(){ | |
if (entity && entity.ref) | |
for (i=0;i<guest.sessions.length;i++) | |
if (guest.sessions[i].ref === entity.ref) return guest.sessions[i]; | |
return undefined; | |
} | |
function formatEvent(event) { | |
return { | |
"type": event.arbitraryData.product.type, | |
"price": event.arbitraryData.product.price, | |
"currency": event.arbitraryData.product.currency, | |
"name": event.arbitraryData.product.name, | |
"item": event.arbitraryData.product.item_id, | |
"quantity": event.arbitraryData.product.quantity, | |
} | |
} | |
function getEvents(session, eventType){ | |
events = []; | |
if (session !== undefined && eventType !== undefined) | |
session.events.forEach(e => { if (e.type === eventType) events.push(formatEvent(e));}); | |
return events.length>=1?events:undefined; | |
} | |
addEvents = getEvents(getTriggeredSession(), "ADD"); | |
return (addEvents)?{ | |
"hasCart": true, | |
"products" : addEvents | |
}:{"hasCart": false}; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment