@eagleeye-solutions/integration-events-common
Version:
Eagle Eye CDP connector common functionality
49 lines • 1.93 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getProductAttributes = getProductAttributes;
exports.getTotalBasketValueAfterDiscount = getTotalBasketValueAfterDiscount;
exports.getDiscountsReceived = getDiscountsReceived;
exports.getTotalPointsEarned = getTotalPointsEarned;
function getProductAttributes(entity) {
if (entity.objectValue.basket.contents) {
const products = entity.objectValue.basket.contents.map(product => {
return {
upc: product.upc,
description: product.description,
itemUnitCost: product.itemUnitCost,
totalUnitCostAfterDiscount: product.totalUnitCostAfterDiscount,
totalUnitCost: product.totalUnitCost,
itemUnitCount: product.itemUnitCount,
};
});
return products;
}
else {
return [];
}
}
function getTotalBasketValueAfterDiscount(entity) {
// Rather than using the totalBasketValue (which includes all
// products, even those that have not yet been fulfilled) we
// sum up the totalUnitCostAfterDiscount for all fulfilled
// products.
return entity.objectValue.basket.contents?.reduce((totalBasketValue, product) => {
return totalBasketValue + product.totalUnitCostAfterDiscount;
}, 0);
}
function getDiscountsReceived(entity) {
if (entity.objectValue.basket.summary?.totalDiscountAmount) {
const values = Object.values(entity.objectValue.basket.summary.totalDiscountAmount).filter((x) => Number.isInteger(x));
const discountReceived = values.reduce((total, value) => {
return total + value;
}, 0);
return discountReceived;
}
else {
return 0;
}
}
function getTotalPointsEarned(entity) {
return entity.objectValue.basket.summary?.results?.points.earn ?? 0;
}
//# sourceMappingURL=create-common.js.map