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