ミニオンパイプラインの設定

Version:
日本語翻訳に関する免責事項

このページの翻訳はAIによって自動的に行われました。可能な限り正確な翻訳を心掛けていますが、原文と異なる表現や解釈が含まれる場合があります。正確で公式な情報については、必ず英語の原文をご参照ください。

インデックスミニオンパイプラインに特定のブロックを追加し、異なるインデックスミニオンが各エンティティタイプを適切に処理できるようにする必要があります。

フルインデックスミニオンおよびインクリメンタルインデックスミニオンパイプライン

IFullIndexMinionPipelineとIncrementalIndexMinionPipelineにそれぞれブロックを挿入し、インデックス化するエンティティタイプごとにドキュメントビューを作成します。

OrdersプラグインのInitializeOrdersIndexingViewBlockやCustomersプラグインのInitializeCustomersIndexingViewBlockを参照として使うことができます。

public override Task Run(EntityView arg, CommercePipelineExecutionContext context) { Condition.Requires(arg).IsNotNull($"{this.Name}: argument cannot be null.");

var argument = context.CommerceContext.GetObjects().FirstOrDefault(); if (string.IsNullOrEmpty(argument?.Policy?.Name)) { return Task.FromResult(arg); }

var orders = argument.Entities?.OfType().ToList(); if (orders == null || !orders.Any()) { return Task.FromResult(arg); }

var searchViewNames = context.GetPolicy();

orders.ForEach( order => { var documentView = arg.ChildViews.Cast() .FirstOrDefault(v => v.EntityId.Equals(order.Id, StringComparison.OrdinalIgnoreCase) && v.Name.Equals(searchViewNames.Document, StringComparison.OrdinalIgnoreCase)); if (documentView == null) { documentView = new EntityView { Name = context.GetPolicy().Document, EntityId = order.Id }; arg.ChildViews.Add(documentView); }

var email = string.Empty; var customerId = string.Empty; if (order.HasComponent()) { var contactComponent = order.GetComponent(); email = string.IsNullOrEmpty(contactComponent.Email) ? string.Empty : contactComponent.Email; customerId = string.IsNullOrEmpty(contactComponent.CustomerId) ? string.Empty : contactComponent.CustomerId; } documentView.Properties.Add(new ViewProperty { Name = "EntityId", RawValue = Guid.Parse(order.Id).ToString("D") }); documentView.Properties.Add(new ViewProperty { Name = "Email", RawValue = email }); documentView.Properties.Add(new ViewProperty { Name = "CustomerId", RawValue = customerId }); documentView.Properties.Add(new ViewProperty { Name = "Status", RawValue = order.Status }); documentView.Properties.Add(new ViewProperty { Name = "OrderConfirmationId", RawValue = order.OrderConfirmationId }); documentView.Properties.Add(new ViewProperty { Name = "OrderPlacedDate", RawValue = order.OrderPlacedDate }); documentView.Properties.Add(new ViewProperty { Name = "DateCreated", RawValue = order.DateCreated }); documentView.Properties.Add(new ViewProperty { Name = "DateUpdated", RawValue = order.DateUpdated }); documentView.Properties.Add(new ViewProperty { Name = "ArtifactStoreId", RawValue = context.CommerceContext.Environment.ArtifactStoreId }); });

return Task.FromResult(arg); }

Search Viewパイプライン

Search結果ビューを変更したい場合は、SearchViewポリシーで指定されたタグに基づいてSearchPipelineにブロックを追加して、検索結果により多くのデータを追加できます。

OrderプラグインのProcessDocumentSearchResultBlockを参照として使うことができます。

public override async Task Run(EntityView arg, CommercePipelineExecutionContext context) { Condition.Requires(arg).IsNotNull($"{this.Name}: argument can not be null.");

var documents = context.CommerceContext.GetObjects<List>().FirstOrDefault(); if (documents == null || !documents.Any()) { return arg; }

if (!arg.HasPolicy()) { return arg; } var scope = arg.GetPolicy(); var hasTags = scope.ResultDetailsTags.Any(t => t.Name.Equals("OrdersList")); if (!hasTags) { return arg; }

foreach (var document in documents) { var docId = document"EntityId".ToLowerInvariant().ToString();

var child = arg.ChildViews.OfType().FirstOrDefault(c => c.EntityId.Equals(docId, StringComparison.OrdinalIgnoreCase)); if (child == null) { continue; }

Guid orderGuid; if (!Guid.TryParse(docId, out orderGuid)) { continue; }

var orderId = orderGuid.ToString("B"); var order = await this._findPipeline.Run(new FindEntityArgument(typeof(CommerceEntity), orderId), context) as Order; if (order == null) { continue; }

var entityId = child.Properties.FirstOrDefault(p => p.Name.Equals("EntityId", StringComparison.OrdinalIgnoreCase)); if (entityId != null) { entityId.RawValue = orderId; entityId.UiType = string.Empty; entityId.IsHidden = true; }

var confirmationId = child.Properties.FirstOrDefault(p => p.Name.Equals("OrderConfirmationId", StringComparison.OrdinalIgnoreCase)); if (confirmationId != null) { confirmationId.UiType = "EntityLink"; }

var customerId = child.Properties.FirstOrDefault(p => p.Name.Equals("CustomerId", StringComparison.OrdinalIgnoreCase)); if (customerId != null && order.HasComponent()) { var contact = order.GetComponent(); if (contact.IsRegistered) { customerId.UiType = "Html"; var value = customerId.RawValue.ToString(); customerId.RawValue = $"<a href=\"/entityView/Master/{value}\">{contact.Email}"; } else { customerId.RawValue = contact.Email; } }

var status = child.Properties.FirstOrDefault(p => p.Name.Equals("Status", StringComparison.OrdinalIgnoreCase)); var total = new ViewProperty { Name = "total", RawValue = order.Totals.GrandTotal, IsReadOnly = true }; var placedDate = child.Properties.FirstOrDefault(p => p.Name.Equals("OrderPlacedDate", StringComparison.OrdinalIgnoreCase)); var updatedDate = child.Properties.FirstOrDefault(p => p.Name.Equals("DateUpdated", StringComparison.OrdinalIgnoreCase));

child.EntityId = orderId; child.ItemId = orderId;

child.Properties.Clear(); child.Properties.Add(confirmationId); child.Properties.Add(customerId); child.Properties.Add(status); child.Properties.Add(total); child.Properties.Add(placedDate); child.Properties.Add(updatedDate); }

return arg; }

この記事を改善するための提案がある場合は、 お知らせください!