カスタム同期戦略の作成

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

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

カスタム同期戦略を使用するには:

  1. 新しいカスタム戦略クラスを作成し、ISynchronizationStrategyインターフェースを実装します。

    このインターフェイスには、同期の方向を受け取る1つのResolveメソッドと、外部システムとSitecoreからの基本製品エンティティが含まれています。

    Resolveメソッドは、更新するシステム (ECSまたはSitecore) を決定し、結果を返します。

    namespace Sitecore.Commerce.Products
    {
        using Sitecore.Commerce.Entities.Products;
    
        /// <summary>
        /// The SynchronizationStrategy interface.
        /// </summary>
    
        public interface ISynchronizationStrategy
        {
            /// <summary>
            /// Resolves the specified direction.
            /// </summary>
            /// <param name="direction">The direction.</param>
            /// <param name="externalSystemEntity">The external system entity.</param>
            /// <param name="sitecoreEntity">The entity from content management system.</param>
            /// <returns>The place, where we decide if entity is updated.</returns>
    
            UpdateIn Resolve(Direction direction, ProductEntity externalSystemEntity, ProductEntity sitecoreEntity);
        }
    }
  2. カスタム同期戦略クラスをSitecore.Commerce.Products.configファイルに登録します。

    これを行うには、synchronizationStrategy要素のtype属性値をカスタム同期戦略タイプに変更します。

<synchronizationStrategy type="Sitecore.Commerce.Products.DateTimeSynchronizationStrategy, Sitecore.Commerce" singleInstance="true" />

The default DateTime based strategy that comes with Connect is the simplest possible strategy:

/// <summary>

/// The synchronization strategy based on updated date of entity in external system and content management system.

/// </summary>

public class DateTimeSynchronizationStrategy : ISynchronizationStrategy

{

    /// <summary>
    /// Resolves the specified direction.
    /// </summary>
    /// <param name="direction">The direction.</param>
    /// <param name="externalSystemEntity">The external system entity.</param>
    /// <param name="sitecoreEntity">The entity from content management system.</param>
    /// <returns>
    /// The place, where we decide if entity is updated.
    /// </returns>

    public UpdateIn Resolve(Direction direction, ProductEntity externalSystemEntity, ProductEntity sitecoreEntity)
    {
        if (string.IsNullOrEmpty(sitecoreEntity.ExternalId) && (direction == Direction.Both || direction == Direction.Inbound))
        {
            return UpdateIn.Sitecore;
        }
        if (externalSystemEntity.Updated == sitecoreEntity.Updated)
        {
            return UpdateIn.None;
        }
        if (externalSystemEntity.Updated < sitecoreEntity.Updated)
        {
            if (direction == Direction.Both || direction == Direction.Outbound)
            {
                return UpdateIn.ExternalCommerceSystem;
            }
        }
        else
        {
            if (direction == Direction.Both || direction == Direction.Inbound)
            {
                return UpdateIn.Sitecore;
            }
        }
        return UpdateIn.None;
    }
}
この記事を改善するための提案がある場合は、 お知らせください!