b2c-metadata について
b2c-metadata は、Salesforce B2C Commerce のサイトメタデータ XML を扱う開発者向けのスキルです。システムオブジェクト拡張、カスタムオブジェクト、サイト設定を解説し、バージョン依存のスキーマや API は公式ドキュメントで確認するよう案内します。
主な機能
- 01メタデータ XML ファイル構造の説明
- 02システムオブジェクトのカスタム属性定義
- 03カスタムオブジェクト定義の解説
- 04サイト設定の構成
- 05公式ドキュメントによるバージョン依存情報の確認
活用シーン
- 01商品や注文への属性追加
- 02カスタムデータオブジェクトの定義作成
- 03サイト固有の設定値の指定
- 04メタデータスキーマと API 詳細の確認
MCP 対応
現行のスキーマや API の詳細を確認するため、`b2c docs search` と `b2c docs read`、または MCP 経由の `docs_search` と `docs_read` の利用を勧めています。
インストール
コマンドをコピーしてターミナルで実行します。
npx skills add https:/ / github.com/ salesforcecommercecloud/ b2c-developer-tooling --skill b2c-metadataインストール後、Claude Code で/b2c-metadataを入力して読み込まれたか確認します。
同梱ファイル
SKILL.md と一緒にインストールされる参考資料やスクリプト。
evals/trigger-evals.jsonreferences/SYSTEM-OBJECTS.mdXML-EXAMPLES.md詳細
メタデータスキル
このスキルでは、カスタム属性、カスタムオブジェクト、サイト設定を含む、Salesforce B2C Commerce のサイトメタデータ XML の操作方法を説明します。
対象範囲と根拠
このスキルでは、B2C Commerce のメタデータ XML システム(metadata.xsd 名前空間 http://www.demandware.com/xml/impex/metadata/2006-10-31)を扱い、system-objecttype-extensions.xml、custom-objecttype-definitions.xml、preferences.xml のファイル構造を対象とします。例では、属性の型、列挙値のパターン、dw.system.Site および ExtensibleObject.custom を使った Script API によるカスタム属性へのアクセスを示します。特定の B2C バージョン、XSD スキーマの制約、またはユーザーが実行するコードに関する質問に回答する前に、b2c docs search と b2c docs read(CLI)、または docs_search/docs_read(MCP)を使用して、現在の API の形式とスキーマのルールを確認してください。メタデータスキーマの変更、Script API のシグネチャ、プラットフォームのオブジェクト型については、B2C Commerce の公式ドキュメントを根拠としてください。
公式ドキュメント:
metadata- メタデータ XML のスキーマと構造dw.system.Site- サイト設定の Script APIdw.system.SitePreferences- サイト設定へのアクセスに関する Script APIdw.object.CustomAttributes- カスタム属性へのアクセスに関する Script APIb2c-commerce/b2c-create-impex-folder-structure-ds- サイトアーカイブのフォルダー構造b2c-commerce/b2c-exporting-active-data- エクスポートガイドb2c-commerce/creatingcustombusinessobjectswithdemandwarebusinessmanager- カスタムオブジェクトの作成b2c-commerce/b2c-business-manager-extension-points- Business Manager の拡張ポイント
概要
メタデータは、B2C Commerce データの構造を定義します。
| メタデータの種類 | 目的 |
|---|---|
| システムオブジェクト拡張 | Product、Order、Customer などにカスタム属性を追加します |
| カスタムオブジェクト | まったく新しいデータ型を定義します |
| サイト設定 | サイト固有の設定値を定義します |
サイトアーカイブの構造
メタデータはサイトアーカイブ内に整理されます。
/site-archive
/meta
system-objecttype-extensions.xml # Custom attributes on system objects
custom-objecttype-definitions.xml # Custom object definitions
/sites
/MySite
preferences.xml # Site preferences
システムオブジェクト拡張
既存のシステムオブジェクトにカスタム属性を追加します。
基本構造
<?xml version="1.0" encoding="UTF-8"?>
<metadata xmlns="http://www.demandware.com/xml/impex/metadata/2006-10-31">
<type-extension type-id="Product">
<custom-attribute-definitions>
<attribute-definition attribute-id="myCustomAttribute">
<display-name xml:lang="x-default">My Custom Attribute</display-name>
<type>string</type>
<mandatory-flag>false</mandatory-flag>
<externally-managed-flag>false</externally-managed-flag>
</attribute-definition>
</custom-attribute-definitions>
<group-definitions>
<attribute-group group-id="MyCustomGroup">
<display-name xml:lang="x-default">My Custom Group</display-name>
<attribute attribute-id="myCustomAttribute"/>
</attribute-group>
</group-definitions>
</type-extension>
</metadata>
一般的なシステムオブジェクト
参考例です。現在のプラットフォームのオブジェクト型については、
b2c docs read b2c-commerce/creatingcustombusinessobjectswithdemandwarebusinessmanagerと Business Manager のオブジェクトリファレンスで確認してください。
| オブジェクト型 | 用途 |
|---|---|
Product | 商品属性 |
Order | 注文のメタデータ |
Profile | 顧客プロファイルデータ |
Basket | カートデータ |
SitePreferences | サイト設定 |
Category | カテゴリー属性 |
Content | コンテンツアセットの属性 |
その他の型については、システムオブジェクトリファレンスを参照してください。拡張可能なシステムオブジェクトの全種類は B2C プラットフォームによって定義されます。バージョンごとの提供状況については、Business Manager および公式ドキュメントを確認してください。
属性の型
metadata.xsd の simpleType.AttributeType に基づいています。現在のスキーマは
b2c docs schema metadataで確認してください。
| 型 | 説明 | 例 |
|---|---|---|
string | テキスト(最大 4000 文字) | SKU、説明 |
text | 長文テキスト(長さ無制限) | リッチコンテンツ |
int | 整数 | 数量、順位 |
double | 小数 | 割合、重量 |
boolean | true/false | フラグ |
date | 日付のみ | 生年月日 |
datetime | 日付と時刻 | タイムスタンプ |
email | メールアドレス | 連絡先メールアドレス |
password | 暗号化 | API キー |
html | HTML コンテンツ | リッチテキスト |
enum-of-string | 単一選択 | ステータス |
enum-of-int | 数値の列挙型 | 優先度 |
set-of-string | 複数選択 | タグ |
set-of-int | 数値の複数選択 | カテゴリー |
image | 画像参照 | サムネイル |
列挙値の定義
列挙型の構造を示す例です。スキーマの現在の順序制約は
b2c docs schema metadataで確認してください。
列挙型(enum-of-string、enum-of-int、set-of-string、set-of-int)には、表示値と値のペアを含む value-definitions が必要です。
要素の順序が重要です。 metadata.xsd スキーマでは、各
<value-definition>内で<display>を<value>より先に記述する必要があります。現在のスキーマ制約についてはb2c docs schema metadataを参照してください。
<attribute-definition attribute-id="warrantyType">
<display-name xml:lang="x-default">Warranty Type</display-name>
<type>enum-of-string</type>
<mandatory-flag>false</mandatory-flag>
<value-definitions>
<value-definition>
<display xml:lang="x-default">No Warranty</display>
<value>none</value>
</value-definition>
<value-definition>
<display xml:lang="x-default">Limited Warranty</display>
<value>limited</value>
</value-definition>
<value-definition>
<display xml:lang="x-default">Full Warranty</display>
<value>full</value>
</value-definition>
</value-definitions>
</attribute-definition>
| 要素 | 目的 |
|---|---|
<display> | Business Manager に表示される、人が読みやすいラベル(最初に記述する必要があります) |
<value> | 保存される値/API の値(小文字で、スペースを含めないでください) |
商品のカスタム属性の例
<?xml version="1.0" encoding="UTF-8"?>
<metadata xmlns="http://www.demandware.com/xml/impex/metadata/2006-10-31">
<type-extension type-id="Product">
<custom-attribute-definitions>
<attribute-definition attribute-id="vendorSKU">
<display-name xml:lang="x-default">Vendor SKU</display-name>
<type>string</type>
<mandatory-flag>false</mandatory-flag>
<externally-managed-flag>true</externally-managed-flag>
</attribute-definition>
<attribute-definition attribute-id="productCondition">
<display-name xml:lang="x-default">Product Condition</display-name>
<type>enum-of-string</type>
<mandatory-flag>false</mandatory-flag>
<value-definitions>
<value-definition>
<display xml:lang="x-default">New</display>
<value>new</value>
</value-definition>
<value-definition>
<display xml:lang="x-default">Refurbished</display>
<value>refurbished</value>
</value-definition>
<value-definition>
<display xml:lang="x-default">Used</display>
<value>used</value>
</value-definition>
</value-definitions>
</attribute-definition>
<attribute-definition attribute-id="isHazardous">
<display-name xml:lang="x-default">Hazardous Material</display-name>
<type>boolean</type>
<mandatory-flag>false</mandatory-flag>
<default-value>false</default-value>
</attribute-definition>
<attribute-definition attribute-id="productFeatures">
<display-name xml:lang="x-default">Product Features</display-name>
<type>set-of-string</type>
<mandatory-flag>false</mandatory-flag>
<value-definitions>
<value-definition>
<display xml:lang="x-default">Waterproof</display>
<value>waterproof</value>
</value-definition>
<value-definition>
<display xml:lang="x-default">Recyclable</display>
<value>recyclable</value>
</value-definition>
</value-definitions>
</attribute-definition>
</custom-attribute-definitions>
<group-definitions>
<attribute-group group-id="CustomProductInfo">
<display-name xml:lang="x-default">Custom Product Information</display-name>
<attribute attribute-id="vendorSKU"/>
<attribute attribute-id="productCondition"/>
<attribute attribute-id="isHazardous"/>
<attribute attribute-id="productFeatures"/>
</attribute-group>
</group-definitions>
</type-extension>
</metadata>
カスタムオブジェクトの定義
まったく新しいデータ型を作成します。
<?xml version="1.0" encoding="UTF-8"?>
<metadata xmlns="http://www.demandware.com/xml/impex/metadata/2006-10-31">
<custom-type type-id="StoreLocations">
<display-name xml:lang="x-default">Store Locations</display-name>
<description xml:lang="x-default">Physical store information</description>
<staging-mode>source-to-target</staging-mode>
<storage-scope>site</storage-scope>
<key-definition attribute-id="storeId">
<display-name xml:lang="x-default">Store ID</display-name>
<type>string</type>
<min-length>1</min-length>
</key-definition>
<attribute-definitions>
<attribute-definition attribute-id="storeName">
<display-name xml:lang="x-default">Store Name</display-name>
<type>string</type>
<mandatory-flag>true</mandatory-flag>
</attribute-definition>
<attribute-definition attribute-id="latitude">
<display-name xml:lang="x-default">Latitude</display-name>
<type>double</type>
</attribute-definition>
<attribute-definition attribute-id="longitude">
<display-name xml:lang="x-default">Longitude</display-name>
<type>double</type>
</attribute-definition>
<attribute-definition attribute-id="phone">
<display-name xml:lang="x-default">Phone</display-name>
<type>string</type>
</attribute-definition>
<attribute-definition attribute-id="isActive">
<display-name xml:lang="x-default">Active</display-name>
<type>boolean</type>
<default-value>true</default-value>
</attribute-definition>
</attribute-definitions>
<group-definitions>
<attribute-group group-id="StoreInfo">
<display-name xml:lang="x-default">Store Information</display-name>
<attribute attribute-id="storeId" system="true"/>
<attribute attribute-id="storeName"/>
<attribute attribute-id="latitude"/>
<attribute attribute-id="longitude"/>
<attribute attribute-id="phone"/>
<attribute attribute-id="isActive"/>
</attribute-group>
</group-definitions>
</custom-type>
</metadata>
サイトプリファレンス
SitePreferences のカスタム属性を使用した、サイト固有の設定です。
メタデータ(system-objecttype-extensions.xml)
<?xml version="1.0" encoding="UTF-8"?>
<metadata xmlns="http://www.demandware.com/xml/impex/metadata/2006-10-31">
<type-extension type-id="SitePreferences">
<custom-attribute-definitions>
<attribute-definition attribute-id="enableFeatureX">
<display-name xml:lang="x-default">Enable Feature X</display-name>
<type>boolean</type>
<default-value>false</default-value>
</attribute-definition>
<attribute-definition attribute-id="apiEndpoint">
<display-name xml:lang="x-default">API Endpoint</display-name>
<type>string</type>
</attribute-definition>
<attribute-definition attribute-id="maxItemsPerPage">
<display-name xml:lang="x-default">Max Items Per Page</display-name>
<type>int</type>
<default-value>20</default-value>
</attribute-definition>
</custom-attribute-definitions>
<group-definitions>
<attribute-group group-id="CustomSettings">
<display-name xml:lang="x-default">Custom Settings</display-name>
<attribute attribute-id="enableFeatureX"/>
<attribute attribute-id="apiEndpoint"/>
<attribute attribute-id="maxItemsPerPage"/>
</attribute-group>
</group-definitions>
</type-extension>
</metadata>
値(sites/MySite/preferences.xml)
プリファレンスは、インスタンスの種類(開発、ステージング、本番)ごとに設定することも、すべてのインスタンスに設定することもできます。
<?xml version="1.0" encoding="UTF-8"?>
<preferences xmlns="http://www.demandware.com/xml/impex/preferences/2007-03-31">
<custom-preferences>
<all-instances>
<preference preference-id="maxItemsPerPage">25</preference>
</all-instances>
<development>
<preference preference-id="enableFeatureX">true</preference>
<preference preference-id="apiEndpoint">https://dev-api.example.com/v1</preference>
</development>
<staging>
<preference preference-id="enableFeatureX">true</preference>
<preference preference-id="apiEndpoint">https://staging-api.example.com/v1</preference>
</staging>
<production>
<preference preference-id="enableFeatureX">false</preference>
<preference preference-id="apiEndpoint">https://api.example.com/v1</preference>
</production>
</custom-preferences>
</preferences>
コードでのアクセス
コード例です。現在の API シグネチャと戻り値の型は
b2c docs read dw.system.Siteで確認してください。
// See dw.system.Site Script API docs for full method signatures and return types
var Site = require('dw/system/Site');
var enableFeatureX = Site.current.getCustomPreferenceValue('enableFeatureX');
var apiEndpoint = Site.current.getCustomPreferenceValue('apiEndpoint');
var maxItems = Site.current.getCustomPreferenceValue('maxItemsPerPage');
属性定義のオプション
利用可能なフラグの例です。現在のスキーマ要素と非推奨の状況は
b2c docs schema metadataで確認してください。
<attribute-definition attribute-id="myAttribute">
<display-name xml:lang="x-default">Display Name</display-name>
<description xml:lang="x-default">Description for BM tooltip</description>
<type>string</type>
<localizable-flag>false</localizable-flag>
<site-specific-flag>false</site-specific-flag>
<mandatory-flag>false</mandatory-flag>
<searchable-flag>false</searchable-flag>
<visible-flag>true</visible-flag>
<externally-managed-flag>false</externally-managed-flag>
<order-required-flag>false</order-required-flag>
<min-length>0</min-length>
<field-length>256</field-length>
<unit xml:lang="x-default">kg</unit>
<default-value>default</default-value>
</attribute-definition>
| フラグ | 目的 |
|---|---|
localizable-flag | ロケールごとに異なる値を設定できます |
mandatory-flag | BM で必須になります |
externally-managed-flag | BM で読み取り専用になります |
visible-flag | BM に表示されます |
site-specific-flag | サイトごとに異なる値を設定できます |
order-required-flag | 注文のエクスポートに必須です |
searchable-flag | 検索用にインデックス化されます(metadata.xsd により非推奨。代わりに search2.xsd の SearchableAttributes を使用してください) |
ベストプラクティス
- 属性グループを使用して Business Manager で整理します
- カスタム属性には組織名を接頭辞として付けます(例:
acme_myAttribute) - 外部システムからインポートしたデータには、externally-managed を設定します
- 値が制限された語彙には、文字列ではなく列挙型を使用します
- 説明を記載します - ツールチップとして表示されます
クイックリファレンス
正式なドキュメントについては、上記の「スコープとグラウンディング」セクションを参照してください。以下のファイルは、そこから派生したクイックリファレンスの要約です。
- システムオブジェクトのリファレンス - すべてのシステムオブジェクト型
- XML の例 - インポート/エクスポートの完全な例