Business Toolsで情報を表示または隠すためにCommerceビューをカスタマイズ
このページの翻訳はAIによって自動的に行われました。可能な限り正確な翻訳を心掛けていますが、原文と異なる表現や解釈が含まれる場合があります。正確で公式な情報については、必ず英語の原文をご参照ください。
Commerce Viewsプラグインは、Business Toolsアプリケーション自体を変更しなくても、Business Toolsのユーザーインターフェースの特定の側面をカスタマイズできます。例えば、既存のビューに新しいビュープロパティを追加するカスタムプラグインを作成できます。または、子ビューやプロパティなどの要素を、Business Tools UIから削除する必要がある場合もあります。これらのカスタマイズは、適切なCommerce Engineプラグインを拡張することで実現できます。
!注Business Toolsのユーザーインターフェースを使って カスタムの子ビューやプロパティの追加または削除 も可能ですが、デフォルトの子ビューやプロパティの削除には使えません。
例えば、カスタム子ビューやプロパティを追加・削除するためには、カスタムパイプラインブロックを作成し、修正されたデフォルトブロックの後に実行されるように設定する必要があります。以下の例では、デフォルトのCustomer Entitlementsビュー(entitlementView)を拡張してギフトカードのコードを新しいプロパティとして表示します。新しいパイプラインブロックはGetCustomerGiftCardCodeViewBlockと名付けられます。
コマースビューを情報の表示または非表示にカスタマイズするには:
-
カスタムプラグインを作成し、ブロックしてください。拡張機能にはSitecore.Commerce.Plugin.GiftCardsプラグインへの参照を含める必要があります。なぜならカスタマイズの目的はギフトカードデータの取得だからです。
-
新しいGetCustomerGiftCardCodeViewBlockブロックはパラメータとしてEntityViewを取り、EntityViewを返さなければなりません。
public class GetCustomerGiftCardCodeViewBlock : PipelineBlock<EntityView, EntityView, CommercePipelineExecutionContext>
-
カスタムブロックにrunメソッドを追加します。カスタムブロックはまず、修正すべきCommerceエンティティビューを特定する条件を指定しなければなりません。
以下はカスタムブロックの例です:
{ private readonly FindEntityCommand _findEntityCommand;
public GetCustomerGiftCardCodeViewBlock(FindEntityCommand command) { _findEntityCommand = command; } public override async Task
RunAsync(EntityView arg, CommercePipelineExecutionContext context) { Condition.Requires(arg).IsNotNull($"{this.Name}: The argument cannot be null."); var request = context.CommerceContext.GetObject (); // 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
().CustomerEntitlements, StringComparison.OrdinalIgnoreCase) && !request.ViewName.Equals(context.GetPolicy ().Master, StringComparison.OrdinalIgnoreCase)) || !(request.Entity is Customer)) { return arg; } var customer = (Customer)request.Entity;
// Check if the Customer has entitlements if (!customer.HasComponent
()) { return arg; } // Find all the entitlements view that were already added by another block var entitlementsView = request.ViewName.Equals(context.GetPolicy
().Master, StringComparison.OrdinalIgnoreCase) ? arg.ChildViews.OfType ().FirstOrDefault(ev => ev.Name.Equals(context.GetPolicy ().CustomerEntitlements, StringComparison.OrdinalIgnoreCase)) : arg; var entitlementViews = entitlementsView?.ChildViews.Where(cv => cv.Name.Equals(context.GetPolicy ().CustomerEntitlementDetails, StringComparison.OrdinalIgnoreCase)).OfType ().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; } } }
-
カスタムパイプラインとブロックをCommerce Engineに登録してください。カスタムプラグインプロジェクトでConfigureSitecore.csファイルを開き、Sitecore.Commerce.Plugin.GiftCardsプラグインブロックの後にカスタムGetCustomerGiftCardCodeViewBlockブロックをIGetEntityViewPipelineに追加してくださいGetCustomerGiftCardEntitlementDetailsViewBlock。
カスタム子表示を削除してください
カスタム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); }