How to display different data to different users

or send an email to

How to display different data to different users

If you manage a B2B ecommerce and have special requirements regarding pricing, like which users can (or can’t) see prices, or different prices depending on the customer group they belong, you can get it.

Let us help you do it.

What do you need to do to achieve this?

1. Put on your data feed all the different prices you need to display

You need to index all the prices that you have 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.

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, depending on your requirements. For instance, if you only want to hide prices for not logged customers, you only need to set a variable, which inform the user if is logged or not. The way to set those variables depends on your platform. You could get the value for the variable from user session, from an AJAX request, or 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 which group the user belongs to.

For instance:

  • User Logged (loggedIn)

  • Customer Group (userGroup)

3. Set transformer to null in your script

Notice: If you only want to hide the price for not logged users, you can skip this step.

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;
    response.results ={
    // 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.

Hope this article help you to achieve a better user experiences in your online store.