Commerceビューを拡張して、ビジネス ツールに追加情報を表示する

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

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

Commerceビューを拡張して、Sitecore XC Business Toolsユーザー インターフェイスに追加情報を表示できます。以下は、エンティティ ビューを拡張して、獲得したポイントの概要を Order Details ページに表示する方法の例です。新しいEntityViewブロックを追加することで、ビューを拡張します。

コマース ビューを拡張して追加情報を表示するには:

  1. サンプル ブロックをコピーして貼り付け、GetOrderSummaryViewBlockという名前を付けます。

  2. GetEntityViewブロックは、EntityViewをパラメーターとして受け取り、EntityViewを返します。この拡張機能は注文を参照する必要があるため、次のようにOrdersプラグインへの参照を追加する必要があります。

    Sitecore.Commerce.Plugin.Orders": "1.0.2301
  3. 新しいブロックを追加します。

    if (request.ViewName != context.GetPolicy<KnownOrderViewsPolicy>().Summary 
                    && request.ViewName != context.GetPolicy<KnownOrderViewsPolicy>().Master)
                {
                    // Do nothing if this request is for a different view
                    return Task.FromResult(entityView);
                }
                if (request.Entity == null)
                {
                    // Do nothing if there is no entity loaded
                    return Task.FromResult(entityView);
                }
                // Only do something if the Entity is an order
                if (!(request.Entity is Order))
                {
                    return Task.FromResult(entityView);
                }
                var order = request.Entity as Order;
                EntityView entityViewToProcess;
                if (request.ViewName == context.GetPolicy<KnownOrderViewsPolicy>().Master)
                {
                    entityViewToProcess = entityView.ChildViews.FirstOrDefault(p=>p.Name == "Summary") as EntityView;
                }
                else
                {
                    entityViewToProcess = entityView;
                }
                int pointsEarned = 0;
                foreach(var line in order.Lines.Where(p=>p.HasComponent<LoyaltyComponent>()))
                {
                    pointsEarned = pointsEarned + line.GetComponent<LoyaltyComponent>().Points;
                }
                entityViewToProcess.Properties.Add(new ViewProperty { Name = "Points Earned", IsReadOnly = true, RawValue = pointsEarned });
                return Task.FromResult(entityView);
この記事を改善するための提案がある場合は、 お知らせください!