Last active
February 11, 2016 18:10
-
-
Save karbyninc/95a6b55d9abfcb04982f to your computer and use it in GitHub Desktop.
Sitecore Development Insight - Custom Conditions
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 System.Collections.Generic; | |
using System.Linq; | |
using System.Web; | |
using Sitecore.Rules; | |
using Sitecore.Rules.Conditions; | |
using Sitecore.Data.Items; | |
using Sitecore.Analytics; | |
using Karbyn.SC.Core.Extensions; | |
namespace Karbyn.SC.SmartStart.Website.Rules | |
{ | |
public class USRegionCondition<T> : WhenCondition<T> where T:RuleContext | |
{ | |
public string RegionItemId { get; set; } | |
protected override bool Execute(T ruleContext) | |
{ | |
string region = Tracker.CurrentVisit.Region; | |
if (string.IsNullOrWhiteSpace(region)) | |
{ | |
return false; | |
} | |
else | |
{ | |
// Get the Item that has the places in the region | |
Item regionItem = Sitecore.Context.Database.Items.GetItem(RegionItemId); | |
if (null != regionItem) | |
{ | |
string regionValues = regionItem.GenerateTextFieldValue("Region"); | |
if (!string.IsNullOrWhiteSpace(regionValues)) | |
{ | |
if (regionValues.ToLowerInvariant().Contains(region.ToLowerInvariant())) | |
{ | |
return true; | |
} | |
} | |
} | |
return false; | |
} | |
} | |
} | |
} |
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
// Get the Item that has the places in the region | |
Item regionItem = Sitecore.Context.Database.Items.GetItem(RegionItemId); |
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
string regionValues = regionItem.GenerateTextFieldValue("Region"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment