Last active
April 5, 2019 00:40
-
-
Save JamesEggers1/07f931382fb66f377b0870d1a92ecb7b to your computer and use it in GitHub Desktop.
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