Doofinder allows you to display different data to different users whenever you need to. For instance, you may have special requirements regarding pricing, such as which users can (or can’t) see prices or have different prices depending on the customer group they belong to.
There are four ways in which you could use to display different data to different users. These are:
1. Adding to your data feed all the different prices you need to display
Here, you will need to index all the prices in your database based on your different user groups. Ideally, in your data feed, the price fields’ names in your data feed must follow this schema:
“price + userGroup”.
It is important to properly configure the callback and inform Doofinder which field must be shown in the layer.
Below you can download some samples in .txt and .xml formats:
2. Set variables in your website to identify the customer
Depending on what you want to get, you’ll need to set a Javascript variable or more based on your requirements. For instance, if you only want to hide prices for not logged in customers, you only need to set a variable informing the user that they are not logged in. The way to set such variables depends on your platform. You could get the value for the variable from the user session, from an AJAX request, or by rendering the value in your HTML template.
Besides, if you have different user groups with different pricing, you need to set another variable that defines the user group.
For instance:
- User Logged (loggedIn)
- Customer Group (userGroup)
3. Set transformer to null in your script
📌 Note: You can skip this step if you only want to hide the price for not logged users.
Doofinder search servers return the minimum fields needed so layers can work without too much configuration. If you want to display any other data you’ve indexed (which is the case) or the original field names, first, you have to set this option to null:
{
searchParams: {
transformer: null
}
}
This way, we’ll get all the different prices in the search response.
4. Add a callback in your doofinder script that will display the right data for each customer
Doofinder shows by default price and sale_price fields from your data feed. In this case, those fields won’t exist because they must be named, including the userGroup, as we explained in the first point.
The callback establishes the value for the price field shown in the results, taking the different prices in the response and the userGroup defined on the page.
"callbacks": {
loaded: function(instance) {
var controller = instance.layer.controller;
controller.processors.push(function(response){
response.results = response.results.map(function(result){
// If the user is not logged, hide price and sale price
if (!loggedIn) {
delete result.price;
delete result.sale_price;
}
// If the user is logged, show the prices
else {
// Here doofinder get the proper prices values
result.price = result['price' + userGroup];
result.sale_price = result['sale_price' + userGroup];
}
return result;
});
return response;
});
}
}
Once you finish, your site will display different prices to your customers based on the login and user group.
Should you encounter any problems, please contact support@doofinder.com
Last Updated: August 2021