カスタム コマース パイプラインまたはブロックの登録

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

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

Microsoft Visual Studioでカスタム プラグイン プロジェクトを作成すると、Sitecore.Commerce.Plugin.Sampleプロジェクト テンプレート ( Sitecore.Commerce.Engine.SDKの一部として提供) に必要なConfigureSitecoreクラスが含まれます。 ConfigureSitecoreクラスは通常、プラグインプロジェクトのルートにあります。

必要なビジネス ロジックを実装するには、カスタム パイプラインとブロックをConfigureServicesメソッド ( ConfigureSitecoreクラスの一部) に追加し、他のパイプライン ブロックとの依存関係を定義します。 ConfigureSitecoreクラスを使用すると、新しいパイプラインとカスタム ブロックをCommerce Engineに登録し、ブロックの実行順序を構成できます。

他のCommerceパイプライン ブロックの依存関係を特定して定義するために、実行中のCommerce Engineインスタンス の現在登録されているパイプラインのログを表示する か、Postmanを使用して 登録済みパイプラインを取得できます

カスタムプラグインが依存する既存のパイプラインとブロックを特定したら、.addpipelineメソッドを使用して必要なパイプラインをConfigureServicesメソッドに追加します。各パイプラインを設定するには、提供する関連するパイプライン ブロックに対して実行する関数を指定します。

パイプライン フレームワークは、次のメソッドと関数のサポートを提供します。

  • .configure.Replace - この方法を使用して、既存のパイプライン ブロックを新しいブロックに置き換えます。例えば:

    services.Sitecore().Pipelines(config => config
                 .ConfigurePipeline<IFormatEntityViewPipeline>(
                        configure =>
                        {
                            configure.Replace<GetEntityViewBlock>, <NewGetEntityViewBlock>();
                        })
          );
  • .configure.Remove - この方法を使用して、既存のパイプラインから不要な機能ブロックを削除します。例えば:

    services.Sitecore().Pipelines(config => config
                 .ConfigurePipeline<IFormatEntityViewPipeline>(
                        configure =>
                        {
                            configure.Remove<CalculateCartLinesFulfillmentBlock>();
                        })
          );

次の例は、カスタムブロック(.Add<AddOrderToServiceBusSendListBlock>)を挿入するように設定されたパイプラインを示しており、定義するアクションがIPersistOrderPipelineの実行before実行されるようにしています。

.ConfigurePipeline<ICreateOrderPipeline>(configuration => configuration
     .Add<AddOrderToServiceBusSendListBlock>().Before<IPersistOrderPipeline>()
                )

次の例では、パイプライン設定によって、<PopulateEntityViewActionsBlock>の実行.Add<EnsureActions>afterカスタムブロックが挿入されます。

.ConfigurePipeline<IFormatEntityViewPipeline>(configuration => configuration
     .Add<EnsureActions>().After<PopulateEntityViewActionsBlock>()
     .Add<EnsurePluginActions>().After<PopulateEntityViewActionsBlock>()             

サンプルConfigureSitecoreクラス

次に、Sitecore.Commerce.Plugin.Sampleプロジェクト テンプレートがVisual Studioで既定で作成するサンプルConfigureSitecoreクラスの例を示します。

namespace Sitecore.Commerce.Plugin.Sample 
{
    using System.Reflection;
    using Microsoft.Extensions.DependencyInjection;
    using Sitecore.Commerce.Core;
    using Sitecore.Framework.Configuration;
    using Sitecore.Framework.Pipelines.Definitions.Extensions;

    /// <summary>
    /// The configure sitecore class.
    /// </summary>
    public class ConfigureSitecore : IConfigureSitecore
    {
        /// <summary>
        /// The configure services.
        /// </summary>
        /// <param name="services">
        /// The services.
        /// </param>
        public void ConfigureServices(IServiceCollection services)
        {
            var assembly = Assembly.GetExecutingAssembly();
            services.RegisterAllPipelineBlocks(assembly);

            services.Sitecore().Pipelines(config => config

             .AddPipeline<ISamplePipeline, SamplePipeline>(
                    configure =>
                        {
                            configure.Add<SampleBlock>();
                        })

             .ConfigurePipeline<IConfigureServiceApiPipeline>(configure => configure.Add<ConfigureServiceApiBlock>()));

            services.RegisterAllCommands(assembly);
        }
    }
}
この記事を改善するための提案がある場合は、 お知らせください!