Indexing revenue metrics as an attribute in Algolia lets you use this data in your ranking formula.
By default, the Algolia Link Integration for Salesforce B2C Commerce supports many product attributes. If you’d like to index an attribute that isn’t in the list of supported attributes, you can define a custom function.
-
In your own code, override the following code in the
int_algolia/cartridge/scripts/algolia/model/algoliaProduct.js
file.
// in file: int_algolia/cartridge/scripts/algolia/model/algoliaProduct.js
/**
* Handler complex and calculated Product attributes
*/
var agregatedValueHanlders = {
/* ... */
revenueData: function (product) {
var activeData = product.getActiveData();
return {
quantityLast7Days: activeData.ordersWeek,
revenueLast7Days: activeData.revenueWeek,
quantityLast30Days: activeData.ordersMonth,
revenueLast30Days: activeData.revenuesMonth,
};
},
};
- In your Business Manager, go to Merchant Tools → Site Preferences → Custom Preferences → Algolia. Find Custom Fields and add
revenueData
. - Finally, reindex your data by going in Administration → Operations → Jobs and running the
AlgoliaProductsIndex
job.
Some attributes are protected. You should avoid creating or modifying attributes with the same name.