Skip to content

Instantly share code, notes, and snippets.

@websterian
Created October 10, 2018 20:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save websterian/0a799517ed68b294e2fbbdc1dc39d506 to your computer and use it in GitHub Desktop.
Save websterian/0a799517ed68b294e2fbbdc1dc39d506 to your computer and use it in GitHub Desktop.
using System;
using System.Linq;
using System.Threading.Tasks;
using Sitecore.Commerce.Core;
using Sitecore.Commerce.EntityViews;
using Sitecore.Framework.Conditions;
using Sitecore.Framework.Pipelines;
namespace Sitecore.Services.Examples.Entities.Pipelines.Blocks
{
[PipelineDisplayName("EntityViewBlock")]
public class EntityViewBlock : PipelineBlock<EntityView, EntityView, CommercePipelineExecutionContext>
{
public override async Task<EntityView> Run(EntityView entityView, CommercePipelineExecutionContext context)
{
Condition.Requires(entityView).IsNotNull($"{Name}: The argument cannot be null.");
var entityViewArgument = context.CommerceContext.GetObjects<EntityViewArgument>().FirstOrDefault();
var viewName = entityViewArgument?.ViewName;
if (string.IsNullOrEmpty(viewName) || !entityViewArgument.ViewName.Equals("BrandsDashboard", StringComparison.OrdinalIgnoreCase))
{
return await Task.FromResult(entityView);
}
return await Task.FromResult(entityView);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment