Sitecore 8.x Custom Facet Repository
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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