public override async Task <EntityView> Run(EntityView arg, CommercePipelineExecutionContext context) { Condition.Requires(arg).IsNotNull(arg.Name + ": The argument cannot be null"); ViewProperty entity = arg.Properties.FirstOrDefault(p => p.Name.EqualsOrdinalIgnoreCase("Condition") || p.Name.EqualsOrdinalIgnoreCase("Action")); if (entity == null || !entity.RawValue.ToString().StartsWith("Hc_") || !entity.RawValue.ToString().Contains("InCategory")) { return(arg); } ViewProperty categorySelection = arg.Properties.FirstOrDefault(x => x.Name.EqualsOrdinalIgnoreCase("Hc_SpecificCategory")); if (categorySelection == null) { return(arg); } SearchScopePolicy policyByType = SearchScopePolicy.GetPolicyByType(context.CommerceContext, context.CommerceContext.Environment, typeof(Category)); if (policyByType == null) { return(arg); } var policy = new Policy { PolicyId = "EntityType", Models = new List <Model> { new Model { Name = nameof(Category) } } }; categorySelection.UiType = "Autocomplete"; categorySelection.Policies.Add(policy); categorySelection.Policies.Add(policyByType); await AddReadOnlyFullPath(arg, context, categorySelection); return(arg); }
public virtual async Task <IEnumerable <GiftCard> > Process(CommerceContext commerceContext, DateTimeOffset startDate, DateTimeOffset endDate) { // Filter order on activation date var filterQuery = new FilterQuery(new AndFilterNode(new LessThanFilterNode( new FieldNameFilterNode("activationdate"), new FieldValueFilterNode(endDate .ToString(SearchConstants.DateTimeSearchFormat, CultureInfo.InvariantCulture), FilterNodeValueType.Date)), new GreaterThanFilterNode(new FieldNameFilterNode("activationdate"), new FieldValueFilterNode( startDate .ToString(SearchConstants.DateTimeSearchFormat, CultureInfo.InvariantCulture), FilterNodeValueType.Date)))); var scope = SearchScopePolicy.GetPolicyByType(commerceContext, commerceContext.Environment, typeof(GiftCard)); var searchResults = await _commander.Command <SearchEntitiesCommand>() .Process <GiftCard>(commerceContext, scope.Name, new SearchQuery(), filterQuery).ConfigureAwait(false); return(searchResults.OrderByDescending(g => g.ActivationDate)); }
/// <summary>Sets the CategoryId view property to autocomplete.</summary> /// <param name="view">The <see cref="EntityView"/>.</param> /// <param name="context">The context.</param> protected virtual void PopulateItemDetails(EntityView view, CommercePipelineExecutionContext context) { if (view == null) { return; } var categoryId = view.GetProperty("CategoryId"); if (categoryId == null) { return; } var policyByType = SearchScopePolicy.GetPolicyByType( context.CommerceContext, context.CommerceContext.Environment, typeof(Category)); if (policyByType != null) { var policy = new Policy() { PolicyId = "EntityType", Models = new List <Model>() { new Model() { Name = "Category" } } }; categoryId.UiType = "Autocomplete"; categoryId.Policies.Add(policy); categoryId.Policies.Add(policyByType); } }