9个版本 (重大更改)
新版本 0.8.0 | 2024年8月20日 |
---|---|
0.7.1 | 2024年7月15日 |
0.6.0 | 2024年7月4日 |
0.5.0 | 2024年6月30日 |
0.1.0 | 2024年6月22日 |
#1080 in 开发工具
每月117次下载
105KB
2.5K SLoC
sw-sync-cli
一个CLI工具,通过Shopware管理API(通过集成)将数据导出到(CSV)文件或从(CSV)文件导入数据。
[!WARNING]
此工具处于实验阶段,目前仅是一个概念验证。
概述
功能
- 速度快,注重性能
- Shopware API中可用的每个实体和字段都可以导出/导入
- 支持使用API条件进行数据过滤和排序
- 导入/导出配置文件是
.yaml
文件- 定义数据导入和导出时的处理方式
- 可以自由复制、修改和共享
- 包括一个用于任意数据转换的脚本引擎
- 目前仅支持CSV数据文件
安装
使用Cargo (Rust工具链)
cargo install sw-sync-cli
相同的命令可以用于更新。请参阅crate
手册
前往GitHub发行版下载适用于您的操作系统的正确二进制文件。然后可以直接执行二进制文件或将它放在您的PATH
中。
从此仓库构建
- 克隆此仓库
- 安装最新的Rust工具链
- 在仓库根目录下运行
cargo build --release
- 您的可执行文件将在这里
./target/release/sw-sync-cli
使用
- 在 shopware 中设置一个 集成
- 使用所需的参数(凭证)调用
sw-sync-cli auth
[!WARNING]
这将在您的当前工作目录中创建一个.credentials.toml
文件。此文件包含您的凭证(纯文本),您可能希望在同步完成后将其删除。
- 以
-m import
或-m export
模式调用sw-sync-cli sync
,并带有配置文件(profile.yaml
)和数据文件data.csv
[!注意]
您可以在任何时候调用sw-sync-cli help
以获取更多信息
配置文件
配置文件用于定义(CSV)文件列与 Shopware 实体字段之间的映射,以及导入/导出时的附加配置。要开始,请查看此存储库中的配置文件。配置文件 .yaml
的结构如下
entity: product
# optional filtering, only applied on export
filter:
# export main products (parentId = NULL) only
- type: "equals"
field: "parentId"
value: null
# optional sorting, only applied on export
sort:
- field: "name"
order: "ASC"
# optional additional associations (that you need in your deserialization script)
# note: entity_path associations are already added by default
# only applied on export
associations:
- "cover"
# mappings can either be
# - by entity_path
# - by key
# the latter needs to be resolved by custom scripts
mappings:
- file_column: "id"
entity_path: "id"
- file_column: "name (default language)"
entity_path: "name"
- file_column: "product number"
entity_path: "productNumber"
- file_column: "stock"
entity_path: "stock"
- file_column: "tax id"
entity_path: "taxId"
- file_column: "tax rate"
# entity path can resolve "To-One-Associations" of any depth
entity_path: "tax.taxRate"
- file_column: "manufacturer name"
# They can also use the optional chaining '?.' operator to fall back to null
# if the association is null
entity_path: "manufacturer?.name"
- file_column: "manufacturer id"
# for importing, you also need the association id in the association object
entity_path: "manufacturer?.id"
- file_column: "gross price EUR"
key: "gross_price_eur"
- file_column: "net price EUR"
key: "net_price_eur"
# optional serialization script, which is called once per entity
serialize_script: |
// See https://rhai.rs/book/ for scripting language documentation
// you receive an entity object, which consists of the whole entity API response for that single entity
// you also receive an empty row object where the specified keys above are missing (you need to set them)
// the other simple mappings are executed (added to the row object) after this script
// debugging utils
// debug(entity); // contains the full entity object from the API (can be huge!)
// print(row); // will be empty
// Use 'get_default' to look up a value equivalent to Defaults.php
let default_currency = get_default("CURRENCY");
let price = entity.price.find(|p| p.currencyId == default_currency);
row.gross_price_eur = price.gross;
row.net_price_eur = price.net;
# optional deserialization script, which is called once per entity
deserialize_script: |
// See https://rhai.rs/book/ for scripting language documentation
// you receive 'row' as an object that has all the keys defined above with the corresponding value
// you also receive an empty entity object, where you need to resolve your keys
// the other simple mappings are executed (added to the entity object) after this script
// print(entity); // will be empty
// debug(row); // will contain only the specified keys + their values
entity.price = [];
entity.price.push(#{
gross: row.gross_price_eur,
net: row.net_price_eur,
linked: true,
currencyId: get_default("CURRENCY"),
});
// You can get the default language or a specific language id by their ISO code
// Default language is used here and will return the default language id
let default_language_id = get_default("LANGUAGE_SYSTEM");
// For a specific language id you can use the get_language_by_iso function:
let specific_language_id = get_language_by_iso("de-DE"); // It will return the language id for "de-DE"
// You can also get different currencies by their ISO code
// Default currency is used here and will return the default currency id
let default_currency_id = get_default("CURRENCY");
// For a specific currency id you can use the get_currency_by_iso function:
let eur_currency_id = get_currency_by_iso("EUR"); // It will return the currency id for "EUR"
许可证
sw-sync-cli
在 MIT 许可证的条款下分发。
有关详细信息,请参阅 LICENSE 文件。
依赖项
~12–24MB
~364K SLoC