カスタム製品エンティティの実装

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

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

フィールドをメイン製品テンプレートと対応するオブジェクトに追加するか、サブアイテムに追加するかを決定するときは、フィールドがすべての製品に適用されるかどうかを自問してください。

主要な製品エンティティを拡張するには:

  1. デフォルトの製品テンプレート(/sitecore/templates/CommerceConnect/Products/Product)を継承し、さらにフィールドで拡張するカスタムテンプレートを作成します。

  2. デフォルトのIDクラスを継承し、さらにプロパティで拡張するカスタム製品クラスSitecore.Commerce.Entities.Products.Product作成します。

  3. デフォルトのSitecore.Commerce.Data.Products.ProductRepositoryクラスから継承するカスタムProductRepositoryクラスを作成します。

  4. 次の2つの方法をオーバーライドして、拡張プロパティを保存して読み込みます。これらのメソッドの基本実装を呼び出します。

    • protected override void UpdateEntityItem(Item entityItem, Product entity)

    • protected override void PopulateEntity(Item entityItem, Product entity)

  5. Sitecore.Commerce.Product.configファイル内のProductRepository要素を更新するには:

    • 属性typeの値を、カスタム製品リポジトリ クラスの完全なタイプ名に置き換えます。次のスニペットで、type値を斜体で示しています。

    • サブ要素テンプレートで設定されたテンプレートIDを置き換えます。次のスニペットと、テンプレート値を斜体で示したスニペットを参照してください。

    <productRepository type="Sitecore.Commerce.Data.Products.ProductRepository, Sitecore.Commerce" singleInstance="true">
    
    <template>{47D1A39E-3B4B-4428-A9F8-B446256C9581}</template>
    • IncludeTemplatesセクションで、ProductTemplateIDのGUIDを更新します。

      詳細については、「 製品インデックス」を参照してください。

    • Sitecore.CommerceProduct.configファイルのCommerce.Entitiesセクションで、Productエンティティ エントリのtype属性を更新します。

      <commerce.Entities>
      
      <Product type="Sitecore.Commerce.Entities.Products.Product, Sitecore.Commerce" />
    • Sitecore.Commerce.Products.LuceneDefaultIndexConfiguration.configファイルのExcludeTemplatesセクションで、ProductTemplateIDのGUIDを更新します。

      詳細については、「 デフォルトインデックス」を参照してください。

    • 双方向同期を使用する場合は、デフォルトのSitecore.Commerce.Pipelines.Products.SynchronizeProductEntity.ResolveProductChangesクラスを継承するカスタムResolveProductChangesクラスを作成します。

関連するリポジトリ内の項目を参照する新しいプロパティ ( Manufacturersなど) は、指定されたタイプのコレクションをロードし、値を設定します。 PopulateEntityFieldCollectionsなどの一部の内部ヘルパーメソッドが提供されています。次に、製品エンティティの読み込み中にManufacturersコレクションがどのように入力されるかの例を示します。

entity.Manufacturers = this.PopulateEntityFieldCollections(
entityItem,
"Manufacturer",
typeof(Manufacturer),
new Dictionary<string, string> { { "ExternalId", "ExternalID" }, { "Name", "Name" }, { "Description", "Description" } })
.Cast<Manufacturer>().ToList();

The actual manufacturer type should be created by calling the Create method on the type Sitecore.Commerce.Entities.EntityFactory, but this is left out to simplify the example.
The PopulateEntityFieldCollections method has the following signature:

/// <summary>
/// Fills the entity collections.
/// </summary>
/// <param name="entityItem">The entity item.</param>
/// <param name="fieldName">Name of the field.</param>
/// <param name="collectionMemberType">Type of the collection member.</param>
/// <param name="properties">The properties.</param>
/// <returns>
/// The collection of the product entities.
/// </returns>

private IEnumerable<ProductEntity> PopulateEntityFieldCollections(Item entityItem, string fieldName, Type collectionMemberType, IDictionary<string, string> properties)

他の製品エンティティについても同じ手順に従います。

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