---
title: "Business Toolsで情報を表示または隠すためにCommerceビューをカスタマイズ"
slug: "customize-a-commerce-view-to-show-or-hide-information-in-the-business-tools"
abstract: "カスタムCommerceビューやプロパティを、Business Toolsのユーザーインターフェースで表示または非表示する方法。"
---
# Business Toolsで情報を表示または隠すためにCommerceビューをカスタマイズ

[Commerce Viewsプラグイン](https://doc.sitecore.com/xp/ja/developers/100/sitecore-experience-commerce/commerce-views-service.html "Commerce Views service")は、Business Toolsアプリケーション自体を変更しなくても、Business Toolsのユーザーインターフェースの特定の側面をカスタマイズできます。例えば、既存のビューに新しいビュープロパティを追加するカスタムプラグインを作成できます。または、子ビューやプロパティなどの要素を、Business Tools UIから削除する必要がある場合もあります。これらのカスタマイズは、適切なCommerce Engineプラグインを拡張することで実現できます。

> !注Business Toolsのユーザーインターフェースを使って [カスタムの子ビューやプロパティの追加または削除](https://doc.sitecore.com/xp/en/users/100/sitecore-experience-commerce/adding-properties-to-commerce-entities.html) も可能ですが、デフォルトの子ビューやプロパティの削除には使えません。

例えば、カスタム子ビューやプロパティを追加・削除するためには、カスタムパイプラインブロックを作成し、修正されたデフォルトブロックの後に実行されるように設定する必要があります。以下の例では、デフォルトのCustomer Entitlementsビュー(entitlementView)を拡張してギフトカードのコードを新しいプロパティとして表示します。新しいパイプラインブロックはGetCustomerGiftCardCodeViewBlockと名付けられます。

コマースビューを情報の表示または非表示にカスタマイズするには:

1.  カスタムプラグインを作成し、ブロックしてください。拡張機能にはSitecore.Commerce.Plugin.GiftCardsプラグインへの参照を含める必要があります。なぜならカスタマイズの目的はギフトカードデータの取得だからです。
    
2.  新しいGetCustomerGiftCardCodeViewBlockブロックはパラメータとしてEntityViewを取り、EntityViewを返さなければなりません。
    
    public class GetCustomerGiftCardCodeViewBlock : PipelineBlock<EntityView, EntityView, CommercePipelineExecutionContext>
    
3.  カスタムブロックにrunメソッドを追加します。カスタムブロックはまず、修正すべきCommerceエンティティビューを特定する条件を指定しなければなりません。
    
    以下はカスタムブロックの例です:
    
    {
     private readonly FindEntityCommand \_findEntityCommand;
    
     public GetCustomerGiftCardCodeViewBlock(FindEntityCommand command)
     {
     \_findEntityCommand = command;
     }
     public override async Task<EntityView> RunAsync(EntityView arg, CommercePipelineExecutionContext context)
     {
     Condition.Requires(arg).IsNotNull($"{this.Name}: The argument cannot be null.");
     var request = context.CommerceContext.GetObject<EntityViewArgument>();
    
     // Do nothing if:
     // -the EntityViewArgument object cannot be found in the context
     // -or the name of the requested view is not Commented
     // -or the requested entity is not a Customer
     if (string.IsNullOrEmpty(request?.ViewName) ||
     (!request.ViewName.Equals(context.GetPolicy<KnownEntitlementsViewsPolicy>().CustomerEntitlements, StringComparison.OrdinalIgnoreCase)
     && !request.ViewName.Equals(context.GetPolicy<KnownCustomerViewsPolicy>().Master, StringComparison.OrdinalIgnoreCase))
     || !(request.Entity is Customer))
     {
     return arg;
     }
    
     var customer = (Customer)request.Entity;
    
     // Check if the Customer has entitlements
     if (!customer.HasComponent<EntitlementsComponent>())
     {
     return arg;
     }
    
     // Find all the entitlements view that were already added by another block
     var entitlementsView = request.ViewName.Equals(context.GetPolicy<KnownCustomerViewsPolicy>().Master, StringComparison.OrdinalIgnoreCase) ? arg.ChildViews.OfType<EntityView>().FirstOrDefault(ev => ev.Name.Equals(context.GetPolicy<KnownEntitlementsViewsPolicy>().CustomerEntitlements, StringComparison.OrdinalIgnoreCase)) : arg;
     var entitlementViews = entitlementsView?.ChildViews.Where(cv => cv.Name.Equals(context.GetPolicy<KnownEntitlementsViewsPolicy>().CustomerEntitlementDetails, StringComparison.OrdinalIgnoreCase)).OfType<EntityView>().ToList();
     if (entitlementViews == null)
     {
     return arg;
     }
    
     foreach (var entitlementView in entitlementViews)
     {
     var entitlement = await \_findEntityCommand.Process(context.CommerceContext, typeof(Entitlement), entitlementView.ItemId).ConfigureAwait(false);
     if (entitlement == null)
     {
     continue;
     }
    
     var card = entitlement as GiftCard;
     if (card == null)
     {
     continue;
     }
    
     entitlementView.Properties.Add(new ViewProperty { Name = "Code", IsReadOnly = true, RawValue = card.GiftCardCode });
     }
    
     return arg;
     }
     }
    }
    
4.  カスタムパイプラインとブロックをCommerce Engineに登録してください。カスタムプラグインプロジェクトでConfigureSitecore.csファイルを開き、Sitecore.Commerce.Plugin.GiftCardsプラグインブロックの後にカスタムGetCustomerGiftCardCodeViewBlockブロックをIGetEntityViewPipelineに追加してくださいGetCustomerGiftCardEntitlementDetailsViewBlock。
    
5.  [Sitecore XCソリューションを展開しましょう](https://doc.sitecore.com/xp/ja/developers/100/sitecore-experience-commerce/deploying-your-sitecore-xc-solution.html "Deploying your Sitecore XC solution")。
    

## カスタム子表示を削除してください

カスタムCommerceエンティティを削除するには:

-   以下の例のようにRemoveChildView法を用いてください。
    
    public static void RemoveChildView(EntityView entityView, string viewNameToRemove)
     {
     // Remove a child view
     var viewToRemove = entityView.ChildViews.FirstOrDefault(p => p.Name.Equals(viewNameToRemove, StringComparison.OrdinalIgnoreCase)) as EntityView;
     entityView.ChildViews.Remove(viewToRemove);
     }
    

## カスタムビュープロパティを削除してください

カスタムCommerceプロパティを削除するには:

-   以下の例に示すRemoveViewPropertyFromView法を用いてください:
    
    public static void RemoveViewPropertyFromView(EntityView entityView, string viewPropertyName)
     {
     // Remove a property
     var propertyToRemove = entityView.Properties.FirstOrDefault(p => p.Name.Equals(viewPropertyName, StringComparison.OrdinalIgnoreCase));
     entityView.Properties.Remove(propertyToRemove);
     }