b2c-site-import-export

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Site Import/Export Skill

站点导入/导出 Skill

Use the
b2c
CLI plugin to import and export site archives on Salesforce B2C Commerce instances.
Tip: If
b2c
is not installed globally, use
npx @salesforce/b2c-cli
instead (e.g.,
npx @salesforce/b2c-cli job import
).
使用
b2c
CLI插件在Salesforce B2C Commerce实例上导入和导出站点归档。
提示: 如果未全局安装
b2c
,请使用
npx @salesforce/b2c-cli
替代(例如:
npx @salesforce/b2c-cli job import
)。

Import Commands

导入命令

Import Local Directory

导入本地目录

bash
undefined
bash
undefined

Import a local directory as a site archive

导入本地目录作为站点归档

b2c job import ./my-site-data
b2c job import ./my-site-data

Import and wait for completion

导入并等待完成

b2c job import ./my-site-data --wait
b2c job import ./my-site-data --wait

Import a local zip file

导入本地压缩文件

b2c job import ./export.zip
b2c job import ./export.zip

Keep the archive on the instance after import

导入后在实例上保留归档文件

b2c job import ./my-site-data --keep-archive
b2c job import ./my-site-data --keep-archive

Show job log if the import fails

若导入失败则显示作业日志

b2c job import ./my-site-data --wait --show-log
undefined
b2c job import ./my-site-data --wait --show-log
undefined

Import Remote Archive

导入远程归档

bash
undefined
bash
undefined

Import an archive that already exists on the instance (in Impex/src/instance/)

导入已存在于实例上的归档文件(位于Impex/src/instance/目录下)

b2c job import existing-archive.zip --remote
undefined
b2c job import existing-archive.zip --remote
undefined

Export Commands

导出命令

bash
undefined
bash
undefined

Export site data

导出站点数据

b2c job export
b2c job export

Export with specific configuration

使用特定配置导出

b2c job export --wait
undefined
b2c job export --wait
undefined

Common Workflows

常见工作流

Adding a Custom Attribute to Products

为产品添加自定义属性

  1. Create the metadata XML file:
meta/system-objecttype-extensions.xml:
xml
<?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>
        </custom-attribute-definitions>
        <group-definitions>
            <attribute-group group-id="CustomAttributes">
                <display-name xml:lang="x-default">Custom Attributes</display-name>
                <attribute attribute-id="vendorSKU"/>
            </attribute-group>
        </group-definitions>
    </type-extension>
</metadata>
  1. Create the directory structure:
my-import/
└── meta/
    └── system-objecttype-extensions.xml
  1. Import:
bash
b2c job import ./my-import --wait
  1. 创建元数据XML文件:
meta/system-objecttype-extensions.xml:
xml
<?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>
        </custom-attribute-definitions>
        <group-definitions>
            <attribute-group group-id="CustomAttributes">
                <display-name xml:lang="x-default">Custom Attributes</display-name>
                <attribute attribute-id="vendorSKU"/>
            </attribute-group>
        </group-definitions>
    </type-extension>
</metadata>
  1. 创建目录结构:
my-import/
└── meta/
    └── system-objecttype-extensions.xml
  1. 执行导入:
bash
b2c job import ./my-import --wait

Adding Site Preferences

添加站点偏好设置

  1. Create metadata for the preference:
meta/system-objecttype-extensions.xml:
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>
        </custom-attribute-definitions>
    </type-extension>
</metadata>
  1. Create preference values:
sites/MySite/preferences.xml:
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="enableFeatureX">true</preference>
        </all-instances>
    </custom-preferences>
</preferences>
  1. Directory structure:
my-import/
├── meta/
│   └── system-objecttype-extensions.xml
└── sites/
    └── MySite/
        └── preferences.xml
  1. Import:
bash
b2c job import ./my-import --wait
  1. 为偏好设置创建元数据:
meta/system-objecttype-extensions.xml:
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>
        </custom-attribute-definitions>
    </type-extension>
</metadata>
  1. 创建偏好设置值:
sites/MySite/preferences.xml:
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="enableFeatureX">true</preference>
        </all-instances>
    </custom-preferences>
</preferences>
  1. 目录结构:
my-import/
├── meta/
│   └── system-objecttype-extensions.xml
└── sites/
    └── MySite/
        └── preferences.xml
  1. 执行导入:
bash
b2c job import ./my-import --wait

Creating a Custom Object Type

创建自定义对象类型

  1. Define the custom object:
meta/custom-objecttype-definitions.xml:
xml
<?xml version="1.0" encoding="UTF-8"?>
<metadata xmlns="http://www.demandware.com/xml/impex/metadata/2006-10-31">
    <custom-type type-id="APIConfiguration">
        <display-name xml:lang="x-default">API Configuration</display-name>
        <staging-mode>source-to-target</staging-mode>
        <storage-scope>site</storage-scope>
        <key-definition attribute-id="configId">
            <display-name xml:lang="x-default">Config ID</display-name>
            <type>string</type>
            <min-length>1</min-length>
        </key-definition>
        <attribute-definitions>
            <attribute-definition attribute-id="endpoint">
                <display-name xml:lang="x-default">API Endpoint</display-name>
                <type>string</type>
            </attribute-definition>
            <attribute-definition attribute-id="apiKey">
                <display-name xml:lang="x-default">API Key</display-name>
                <type>password</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>
    </custom-type>
</metadata>
  1. Import:
bash
b2c job import ./my-import --wait
  1. 定义自定义对象:
meta/custom-objecttype-definitions.xml:
xml
<?xml version="1.0" encoding="UTF-8"?>
<metadata xmlns="http://www.demandware.com/xml/impex/metadata/2006-10-31">
    <custom-type type-id="APIConfiguration">
        <display-name xml:lang="x-default">API Configuration</display-name>
        <staging-mode>source-to-target</staging-mode>
        <storage-scope>site</storage-scope>
        <key-definition attribute-id="configId">
            <display-name xml:lang="x-default">Config ID</display-name>
            <type>string</type>
            <min-length>1</min-length>
        </key-definition>
        <attribute-definitions>
            <attribute-definition attribute-id="endpoint">
                <display-name xml:lang="x-default">API Endpoint</display-name>
                <type>string</type>
            </attribute-definition>
            <attribute-definition attribute-id="apiKey">
                <display-name xml:lang="x-default">API Key</display-name>
                <type>password</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>
    </custom-type>
</metadata>
  1. 执行导入:
bash
b2c job import ./my-import --wait

Importing Custom Object Data

导入自定义对象数据

customobjects/APIConfiguration.xml:
xml
<?xml version="1.0" encoding="UTF-8"?>
<custom-objects xmlns="http://www.demandware.com/xml/impex/customobject/2006-10-31">
    <custom-object type-id="APIConfiguration" object-id="payment-gateway">
        <object-attribute attribute-id="endpoint">https://api.payment.com/v2</object-attribute>
        <object-attribute attribute-id="isActive">true</object-attribute>
    </custom-object>
</custom-objects>
customobjects/APIConfiguration.xml:
xml
<?xml version="1.0" encoding="UTF-8"?>
<custom-objects xmlns="http://www.demandware.com/xml/impex/customobject/2006-10-31">
    <custom-object type-id="APIConfiguration" object-id="payment-gateway">
        <object-attribute attribute-id="endpoint">https://api.payment.com/v2</object-attribute>
        <object-attribute attribute-id="isActive">true</object-attribute>
    </custom-object>
</custom-objects>

Site Archive Structure

站点归档结构

site-archive/
├── services.xml                           # Service configurations (credentials, profiles, services)
├── meta/
│   ├── system-objecttype-extensions.xml   # Custom attributes on system objects
│   └── custom-objecttype-definitions.xml  # Custom object type definitions
├── sites/
│   └── {SiteID}/
│       ├── preferences.xml                # Site preference values
│       └── library/
│           └── content/
│               └── content.xml            # Content assets
├── catalogs/
│   └── {CatalogID}/
│       └── catalog.xml                    # Products and categories
├── pricebooks/
│   └── {PriceBookID}/
│       └── pricebook.xml                  # Price definitions
├── customobjects/
│   └── {ObjectTypeID}.xml                 # Custom object instances
└── inventory-lists/
    └── {InventoryListID}/
        └── inventory.xml                  # Inventory records
site-archive/
├── services.xml                           # 服务配置(凭据、配置文件、服务)
├── meta/
│   ├── system-objecttype-extensions.xml   # 系统对象的自定义属性
│   └── custom-objecttype-definitions.xml  # 自定义对象类型定义
├── sites/
│   └── {SiteID}/
│       ├── preferences.xml                # 站点偏好设置值
│       └── library/
│           └── content/
│               └── content.xml            # 内容资产
├── catalogs/
│   └── {CatalogID}/
│       └── catalog.xml                    # 商品与分类
├── pricebooks/
│   └── {PriceBookID}/
│       └── pricebook.xml                  # 价格定义
├── customobjects/
│   └── {ObjectTypeID}.xml                 # 自定义对象实例
└── inventory-lists/
    └── {InventoryListID}/
        └── inventory.xml                  # 库存记录

Tips

技巧

Checking Job Status

检查作业状态

bash
undefined
bash
undefined

Search for recent job executions

搜索最近的作业执行记录

b2c job search
b2c job search

Wait for a specific job execution

等待特定作业执行完成

b2c job wait <execution-id>
b2c job wait <execution-id>

View job logs on failure

查看失败作业的日志

b2c job import ./my-data --wait --show-log
undefined
b2c job import ./my-data --wait --show-log
undefined

Best Practices

最佳实践

  1. Test imports on sandbox first before importing to staging/production
  2. Use
    --wait
    to ensure import completes before continuing
  3. Use
    --show-log
    to debug failed imports
  4. Keep archives organized by feature or change type
  5. Version control your metadata XML files
  1. 先在沙箱环境测试导入,再导入到预发布/生产环境
  2. 使用
    --wait
    参数
    ,确保导入完成后再继续后续操作
  3. 使用
    --show-log
    参数
    ,调试失败的导入任务
  4. 按功能或变更类型整理归档文件
  5. 对元数据XML文件进行版本控制

Configuring External Services

配置外部服务

For service configurations (HTTP, FTP, SOAP services), see the
b2c:b2c-webservices
skill which includes:
  • Complete services.xml examples
  • Credential, profile, and service element patterns
  • Import/export workflows
Quick example:
bash
undefined
有关服务配置(HTTP、FTP、SOAP服务),请查看
b2c:b2c-webservices
技能文档,其中包含:
  • 完整的services.xml示例
  • 凭据、配置文件和服务元素模板
  • 导入/导出工作流
快速示例:
bash
undefined

Import service configuration

导入服务配置

b2c job import ./services-folder

Where `services-folder/services.xml` follows the patterns in the `b2c:b2c-webservices` skill.
b2c job import ./services-folder

其中`services-folder/services.xml`需遵循`b2c:b2c-webservices`技能文档中的模板规范。

Detailed Reference

详细参考

  • Metadata XML Patterns - Common XML patterns for imports
  • 元数据XML模板 - 导入操作常用的XML模板

Related Skills

相关技能

  • b2c:b2c-webservices
    - Service configurations (HTTP, FTP, SOAP), services.xml format
  • b2c:b2c-metadata
    - System object extensions and custom object definitions
  • b2c-cli:b2c-job
    - Running jobs and monitoring import status
  • b2c:b2c-webservices
    - 服务配置(HTTP、FTP、SOAP)、services.xml格式
  • b2c:b2c-metadata
    - 系统对象扩展与自定义对象定义
  • b2c-cli:b2c-job
    - 运行作业与监控导入状态