/
ExtendSellableItemDetailsViewBlock.cs
60 lines (51 loc) · 2.25 KB
/
ExtendSellableItemDetailsViewBlock.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
namespace Plugin.Sample.Notes.Pipelines.Blocks
{
using Sitecore.Commerce.Core;
using Sitecore.Commerce.EntityViews;
using Sitecore.Commerce.Plugin.Catalog;
using Sitecore.Framework.Conditions;
using Sitecore.Framework.Pipelines;
using System;
using System.Threading.Tasks;
[PipelineDisplayName(nameof(ExtendSellableItemDetailsViewBlock))]
public class ExtendSellableItemDetailsViewBlock : PipelineBlock<EntityView, EntityView, CommercePipelineExecutionContext>
{
protected CommerceCommander Commander { get; set; }
public ExtendSellableItemDetailsViewBlock(CommerceCommander commander)
: base(null)
{
this.Commander = commander;
}
public override Task<EntityView> Run(EntityView entityView, CommercePipelineExecutionContext context)
{
Condition.Requires(entityView).IsNotNull($"{this.Name}: The argument can not be null");
var policy = context.GetPolicy<KnownCatalogViewsPolicy>();
EntityViewArgument request = context.CommerceContext.GetObject<EntityViewArgument>();
if (string.IsNullOrEmpty(request?.ViewName) || !request.ViewName.Equals(policy.Master, StringComparison.OrdinalIgnoreCase))
{
return Task.FromResult(entityView);
}
if (!(request.Entity is SellableItem) || !string.IsNullOrEmpty(request.ForAction))
{
return Task.FromResult(entityView);
}
var sellableItem = request.Entity as SellableItem;
var dateCreatedProperty = new ViewProperty() {
DisplayName = "Date Created",
Name = nameof(sellableItem.DateCreated),
IsReadOnly = true,
RawValue = sellableItem.DateCreated
};
entityView.Properties.Add(dateCreatedProperty);
var dateUpdatedProperty = new ViewProperty()
{
DisplayName = "Date Updated",
Name = nameof(sellableItem.DateUpdated),
IsReadOnly = true,
RawValue = sellableItem.DateUpdated
};
entityView.Properties.Add(dateUpdatedProperty);
return Task.FromResult(entityView);
}
}
}