purchased_items

Determines which products within a given set were previously purchased by the user and returns a new set consisting of only those purchased products or only those that have not been purchased.

You can use this function on an array of horizon_select product recommendations or Prediction ManagerĀ item predictions to exclude products that were already purchased by the user within a given period.

list purchased_items( array items, bool show, integer lookback )

Given a JSON array of items, determines which of those items were purchased by the user within the past number of lookback days.

  • If show = TRUE, returns a JSON array of those purchased items.
  • If show = FALSE, returns the original JSON array with those purchased items filtered out.
  • lookback has a maximum of 90 days. There are plans to remove this limitation in the future.

Display Content Recommended Based on Past Purchases

Use Case: You want to check a data feed for any items a user may have already purchased. If they have, call out those specifically in their own “Because you purchased…” section and find non-purchased items for a “We recommend section.”

Zephyr:

{content = personalize({
"algorithm" : "popular",
"size" : 100
})}

{nonPurchased = purchased_items(content,false,90)}

We recommend for you:
{foreach slice(nonPurchased,0,3) as c}
{c.title}<br/>
{/foreach}

Output:

We recommend for you:

Item 1

Item 2

Item 3

Explanation: This script uses the personalize() function to create a content object of 100 items based on what’s currently popular in your Content Library. The script then uses the purchased_items() function to check if the user has purchased any of those items in the past 90 days. If they haven’t, the item is added to a “nonPurchased” content object. Next, a foreach loop iterates through this object, and using the slice() function, displays the top three items.

Top