eCommerce Data Filtering and Sorting Guide
    • 2 Minutes to read
    • Dark
      Light

    eCommerce Data Filtering and Sorting Guide

    • Dark
      Light

    Article summary

    Overview

    Filtering and sorting can be combined and applied to different types of eCommerce data, such as Wishlist, AbandonedCart, AbandonedBrowse, Transaction, or Recommended Products.

    This guide provides an overview of how to apply filtering and ordering operations to eCommerce personalization placeholders, such as <%user.WishlistProducts%>. These operations allow for dynamic handling of eCommerce data for users.

    Data can be loaded from these sources:

    • Product Catalog

    • Related Data

    Filtering

    Using operators, you can filter eCommerce data based on date range or specific fields. Below are examples of different use cases:

    Date Range Filtering

    To retrieve eCommerce data for a user within a specified date range:

    • Last 6 days:

      <%ForEach var='wishlist' items="${ecx:filterDateRange(user.wishlistProducts, 'timestamp', ecx:formatDate(ecm:addInterval(date.today, '-6d'), 'yyyy-MM-dd', ecm:timeZone('Europe/Berlin'), 'de', false), '')}"%>
    • Between two specific dates:

      <%ForEach var='wishlist' items="${ecx:filterDateRange(user.wishlistProducts, 'timestamp', ecm:toDate('2024-10-10 13:45:00',null), ecm:toDate('2024-12-10 14:45:00',null))}"%>

    Field Filtering with Operators

    Filter data by field using various operators such as:

    • Product name starts with "shoes":

      <%ForEach var='wishlist' items="${ecx:filter(user.wishlistProducts, 'productName', 'startswith', 'shoes')}"%>

    The available operators are:

    • EQUALS (==)

    • NOT_EQUALS (!=)

    • EMPTY (empty)

    • NOT_EMPTY (notempty)

    • LESS_THAN (<)

    • GREATER_THAN (>)

    • LESS_EQUALS_THAN (<=)

    • GREATER_EQUALS_THAN (>=)

    • STARTS_WITH (startswith)

    • ENDS_WITH (endswith)

    • CONTAINS (contains)

    • CONTAINS_CASE_INSENSITIVE (containsignorecase)

    • REGEX (regex)

    Using an operator for an incompatible data type will result in an empty return.

    Sorting and Removing Duplicates

    Removing Duplicates

    To remove duplicate entries based on a specific field, such as productSKU:

    <%ForEach var='wishlist' items="${ecx:filterDuplicatesByField(user.wishlistProducts, 'productSKU')}"%>

    Sorting Data

    To sort eCommerce data by a specific field (e.g., by timestamp):

    • Sort in descending order:

      <%ForEach var='wishlist' items="${ecx:sort(user.wishlistProducts, 'timestamp', 'desc')}" max="5"%>

    You can also combine sorting and removing duplicates:

    • Get 5 newest items without duplicates:

      <%ForEach var='wishlist' items="${ecx:sort(ecx:filterDuplicatesByField(user.wishlistProducts, 'productSKU'), 'timestamp', 'desc')}" max="5"%>

    Use Cases

    Use Case 1: Top 3 Abandoned Cart Products (Last 7 Days, Sorted by Price)

    To retrieve the top 3 abandoned cart products from the last 7 days, sorted by price in descending order, you can use the following example:

    Example Data:

    Abandoned Cart Table (user.AbandonedCartProducts):

    • Product A (SKU: 1234, Price: $50, Timestamp: 2024-10-05)

    • Product B (SKU: 5678, Price: $70, Timestamp: 2024-10-03)

    • Product C (SKU: 91011, Price: $40, Timestamp: 2024-10-04)

    Personalization Example:

    <%ForEach var='cart' items="${ecx:sort(ecx:filterDateRange(user.AbandonedCartProducts, 'timestamp', ecx:formatDate(ecm:addInterval(date.today, '-7d'), 'yyyy-MM-dd', ecm:timeZone('Europe/Berlin'), 'de', false), ''), 'price', 'desc')}" max="3"%>
      <%${cart['productName']} - ${cart['price']}%>
    <%/ForEach%>

    This will return the top 3 abandoned cart products ordered by their price from the last 7 days.

    Use Case 2: Top 3 Wishlist Products Using Related Data (Sorted by Name)

    To showcase how Related Data is used, let’s retrieve the top 3 wishlist products from a related data table (e.g., myrdlistwithproductdata), sorted by product name.

    Example Data:

    Related Data Wishlist Table (user.WishlistProductsRD):

    • Shoes A (Description: Running Shoes, Price: $50, Timestamp: 2024-10-01)

    • Shoes B (Description: Hiking Shoes, Price: $70, Timestamp: 2024-09-30)

    • Shoes C (Description: Casual Shoes, Price: $40, Timestamp: 2024-10-03)

    Personalization Example:

    <%ForEach var="wishlist" items="${ecx:sort(user.wishlistProductsRD['myrdlistwithproductdata'], 'productName', 'asc')}" max="3"%>
      Wishlist Description: <%${wishlist['description']}%><br>
      Wishlist Price: <%${wishlist['price']}%><br><br>
    <%/ForEach%>

    This will retrieve and display the top 3 wishlist products from the Related Data table, sorted by product name in ascending order.


    Was this article helpful?


    ESC

    AI Assistant, facilitating knowledge discovery through conversational intelligence