Skip to content

Instantly share code, notes, and snippets.

@JamesEggers1
Last active April 5, 2019 00:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JamesEggers1/07f931382fb66f377b0870d1a92ecb7b to your computer and use it in GitHub Desktop.
Save JamesEggers1/07f931382fb66f377b0870d1a92ecb7b to your computer and use it in GitHub Desktop.
Sitecore 8.x Custom Facet Repository
using System;
using Sitecore.Analytics;
using Sitecore.Analytics.Model.Entities;
namespace MyNamespace.Repositories
{
public interface IPaymentFacetRepository
{
void SetFacentInformation(string userIdentifier, decimal lastPaymentAmount, DateTime lastPaymentDate);
}
public class PaymentFacetRepository : IPaymentFacetRepository
{
public void SetFacentInformation(string userIdentifier, decimal lastPaymentAmount, DateTime lastPaymentDate)
{
if (Tracker.Current?.Session?.Contact != null)
{
var contact = Tracker.Current.Session.Contact;
try
{
if (string.IsNullOrWhiteSpace(contact.Identifiers.Identifier))
{
Tracker.Current.Session.Identify(userIdentifier);
}
var paymentFacet = contact.GetFacet<ICustomerPaymentFacet>("Payment");
paymentFacet.LastPaymentAmount = lastPaymentAmount;
paymentFacet.LastPaymentDate = lastPaymentDate;
}
catch (Exception ex)
{
// Log Exception here.
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment