Commerce 検索結果レンダリングのカスタマイズ
このページの翻訳はAIによって自動的に行われました。可能な限り正確な翻訳を心掛けていますが、原文と異なる表現や解釈が含まれる場合があります。正確で公式な情報については、必ず英語の原文をご参照ください。
Commerce 検索結果レンダリング バリアントには、Scriban テンプレートの形式のレンダラーが含まれています。
Scriban テンプレートは、個々の商品カードのマークアップをレンダリングする役割を果たします。これは、商品アイテムを反復処理するループ内で実行されます。商品カード用に生成されるマークアップを変更するには、Scriban テンプレートを変更します。この場合、ソフトウェアのアップグレード時にカスタマイズがオーバーライドされないように、新しいカスタム レンダリング バリアントを作成することをお勧めします。レンダリングのラベルを変更することもできます。
次の表に、Commerce 検索結果レンダリング Scriban テンプレートの主要なプロパティの詳細を示します。
プロパティまたは変数 |
説明 |
---|---|
デフォルトの実装では、アイテムはすべて | |
| |
|
displayName 変数は、さまざまなコンテキストで使用されます。たとえば、 また、アンカー タグの |
画像リンクは、 | |
この関数は、サイトのディクショナリ ドメイン (sitecore/Content/<テナント>/<サイト>/Storefront Dictionary) で定義されたアイテムを表示するために使用されます。 | |
|
このプロパティは、商品のブランド名を格納し、 |
次のコードは、デフォルトのレンダリング バリアント内で定義された Commerce 検索結果レンダリング Scriban テンプレートを示しています。
{{ # The <div> element renders a product item with values from the search item (i_item) and the ProductSummaryViewModel (o_model) }}
<div class="product-summary" data-id="{{ i_item.name }}">
{{
# If the o_model is not available, set it to an empty object to be accessed by the rest of the template without null reference error
if !o_model
o_model = {}
end
# Escape any HTML characters in the display name
displayName = i_item.display_name | html.escape
}}
{{ # The <div> element contains the product photo }}
<div class="product-photo">
{{ # The <a> element wraps the product photo with a link to navigate to the product page }}
<a title="{{ displayName }}" href="{{ i_item.url }}">
<img src="{{ o_model.master_product_image | sc_imagelink 220 220 }}" alt="{{ o_model.master_product_image.alternate_text }}" />
{{ ## The <div> element contains the savings percentage and savings label.
The CSS class "promotion" is added on server side (if "o_model.is_on_sale" is true) or on client side after the data binding (if "promotion" has a true value). ## }}
<div data-bind="css: { 'promotion': promotion }"
class="hidden {{ if o_model.is_on_sale }} promotion {{ end }}">
{{ # The promotion text is rendered on server side and will be overwritten on the client side if data binding occurs }}
<span data-bind="text: promotion" class="savings-percentage">{{ o_model.savings_percentage }}%</span>
<span class="savings-label">{{ sc_translate 'SAVINGS_LABEL' }}</span>
</div>
</a>
</div>
{{ # The <div> element contains all the product information such as the display name and price }}
<div class="product-info">
{{ # The <a> element wraps the product display name with a link to navigate to the product page }}
<a class="product-title" title="{{ displayName }}" href="{{ i_item.url }}">
{{ displayName }}
</a>
<div class="product-brand">
{{ i_item.brand }}
</div>
{{ # The <div> element contains the stock status of the product and a "Starting From" label }}
<div class="product-indicator">
{{ ## The <label> element contains the "Starting From" label.
The CSS class "price-difference" is added on server side (if "o_model.display_starting_from" is true) or on client side after the data binding (if "hasDifferentPrice" is true). ## }}
<label class="hidden {{ if o_model.display_starting_from }} price-difference {{ end }}"
data-bind="css: { 'price-difference': hasDifferentPrice }">
{{ sc_translate 'STARTING_FROM' }}
</label>
<label class="stock-status" data-bind="text: stockLabel">{{ o_model.stock_status_name }}</label>
</div>
{{ ## The <div> element contains the product price and product details link.
The CSS class "on-sale" is added on server side (if "o_model.is_on_sale" is true) or on client side after the data binding (if "promotion" has a truthy value). ## }}
<div class="product-detail {{ if o_model.is_on_sale }} on-sale {{ end }}"
data-bind="css: { 'on-sale': promotion }">
{{ # The product price text is rendered on server side and will be overwritten on the client side if data binding occurs }}
<span data-bind="text: price" class="product-price">{{ o_model.adjusted_price_with_currency }}</span>
<a class="product-link" title="{{ displayName }}" href="{{ i_item.url }}">
{{ sc_translate 'DETAILS' }}
</a>
</div>
</div>
</div>
Commerce 検索結果レンダリングは、Commerce に固有の SXA 検索結果レンダリングのクローンです。独自のデフォルトのレンダリング バリアント ルートとデフォルトのレンダリング バリアント (/sitecore/Content/<テナント>/<サイト>/Presentation/Rendering Variants/Commerce Search Results) があり、マークアップを生成するための Scriban テンプレート、在庫および価格情報を取得するための JavaScript (AJAX リクエストとして)、およびラベル翻訳用の SXA Dictionary を使用します。
Commerce 検索結果のレンダリングで使用されるラベルを変更することができます。
商品概要ビュー モデル
検索結果が処理されると、価格と在庫情報が Commerce Engine から取得され、ProductSummaryViewModel
モデルに変換されて、Scriban テンプレート (o_model
変数を通じてアクセスされる) 内でレンダリングされます。