Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more
Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more
Product associations (or relations) can promote products in the following ways:
You can display merchandising items on category, product, shopping cart, checkout, or receipt pages.
The following examples show how to implement product associations.
You can provide product recommendations based on the purchasing history of other customers. Shoppers also can view items that other customers bought in a personalized storefront. Recommendations are dynamically displayed based on defined business logic.
Example: utilizing an entry association to expose a predefined set of product recommendations for an entry
private void SampleGetRecomendedEntries(Entry entry)
{
Association[] assocs = entry.Associations;
string key = "CrossSell"; // You can define association keys in Commerce Manager.
bool matchFound = false;
if (assocs == null) return;
foreach (Association assoc in assocs)
{
if (assoc.EntryAssociations == null) continue;
// Match the association string key defined in the Commerce Manager or elsewhere.
if (assoc.Name == key && assoc.EntryAssociations.Association.Length > 0)
{
matchFound = true;
// The Association property exposes a EntryAssociation[] array.
// The EntryAssociation object has a property Entry, which gives you access to each Entry.
YourRepeaterControl.DataSource = assoc.EntryAssociations.Association;
YourRepeaterControl.DataBind();
// Break from foreach loop.
break;
}
}
}
You can remind customers of recent products of interest by displaying a list of the last products viewed in the store. This is traditionally used in the shopping cart and product pages for easier navigation.
Example: binding a collection of recently viewed entry objects
private void SampleGetRecentlyViewedEntryCollection()
{
NameValueCollection history = StoreHelper.GetBrowseHistory();
List<Entry> recentlyViewedEntries = new List<Entry>();
string[] keys = history.GetValues("Entries");
if (keys != null)
{
bool isFirst = true;
foreach (string key in keys)
{
// Skip the first item.
if (isFirst)
{
isFirst = false;
continue;
}
if (!String.IsNullOrEmpty(key))
{
Entry entry = CatalogContext.Current.GetCatalogEntry(key);
if (entry != null)
recentlyViewedEntries.Add(entry);
}
}
}
if (recentlyViewedEntries.Count == 0)
{
// No recently viewed entries were found.
return;
}
// Bind the collection to your control.
YourRepeaterControl.DataSource = recentlyViewedEntries.ToArray();
YourRepeaterControl.DataBind();
}
Last updated: Oct 12, 2015