shopify-admin-collection-reorganization
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChinesePurpose
用途
Reorders products in a manual Shopify collection by inventory level without navigating the Shopify admin UI. This skill queries all products in the collection, computes the desired sort order by , and applies it in a single mutation. Note: only works on manual (custom) collections — smart collections managed by Shopify rules are not supported.
totalInventorycollectionReorderProducts无需操作Shopify管理后台UI,即可按库存水平对Shopify手动集合中的产品进行重新排序。本技能会查询集合中的所有产品,根据计算预期排序,然后通过单次 mutation应用排序。注意:仅适用于手动(自定义)集合——不支持由Shopify规则管理的智能集合。
totalInventorycollectionReorderProductsPrerequisites
前置要求
- Authenticated Shopify CLI session:
shopify auth login --store <domain> - API scopes: ,
read_productswrite_products
- 已认证的Shopify CLI会话:
shopify auth login --store <domain> - API权限:、
read_productswrite_products
Parameters
参数
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
| store | string | yes | — | Store domain (e.g., mystore.myshopify.com) |
| format | string | no | human | Output format: |
| dry_run | bool | no | false | Preview operations without executing mutations |
| collection_id | string | yes | — | GID of the manual collection (e.g., |
| sort_by | string | no | inventory_desc | |
| 参数 | 类型 | 是否必填 | 默认值 | 描述 |
|---|---|---|---|---|
| store | string | 是 | — | 商店域名(例如:mystore.myshopify.com) |
| format | string | 否 | human | 输出格式: |
| dry_run | bool | 否 | false | 预览操作但不执行mutation |
| collection_id | string | 是 | — | 手动集合的GID(例如: |
| sort_by | string | 否 | inventory_desc | |
Safety
安全提示
⚠️ Step 2 executeswhich changes the product display order immediately. The sort is reversible — run again with the oppositecollectionReorderProductsto restore previous order — but the original custom order cannot be recovered once overwritten. Thesort_byarray passed to the mutation must be complete; partial moves produce undefined ordering. Always run withmovesfirst to review the computed sort order before committing.dry_run: true
collectionReorderProductssortOrderMANUAL⚠️ 步骤2执行的会立即更改产品展示顺序。排序是可撤销的——使用相反的collectionReorderProducts参数再次运行即可恢复之前的顺序,但原始自定义顺序一旦被覆盖就无法恢复。传递给mutation的sort_by数组必须完整;部分移动会导致未定义的排序。提交前请务必先使用moves运行,预览计算出的排序结果。dry_run: true
collectionReorderProductssortOrderMANUALWorkflow Steps
工作流步骤
-
OPERATION:— query Inputs:
collection,id: <collection_id>, pagination cursor Expected output: Collection metadata (title,first: 250) and all product nodes withsortOrder; verifytotalInventory— abort if not; paginate until all products fetchedsortOrder == "MANUAL" -
OPERATION:— mutation Inputs:
collectionReorderProducts,id: <collection_id>array sorted bymovespertotalInventoryparameter — each move issort_by(0-indexed string) Expected output:{id: <product_id>, newPosition: "<index>"}andjob.id;job.doneuserErrors
-
操作:— 查询 输入:
collection、id: <collection_id>、分页游标 预期输出: 集合元数据(标题、first: 250)以及所有带sortOrder的产品节点;验证totalInventory——不满足则中止;分页直到拉取到所有产品sortOrder == "MANUAL" -
操作:— mutation 输入:
collectionReorderProducts、根据id: <collection_id>参数按sort_by排序的totalInventory数组——每个移动项为moves(0索引的字符串) 预期输出:{id: <product_id>, newPosition: "<index>"}和job.id;job.doneuserErrors
GraphQL Operations
GraphQL 操作
graphql
undefinedgraphql
undefinedcollection:query — validated against api_version 2025-01
collection:query — validated against api_version 2025-01
query CollectionProducts($id: ID!, $first: Int!, $after: String) {
collection(id: $id) {
id
title
sortOrder
products(first: $first, after: $after) {
edges {
node {
id
title
totalInventory
variants(first: 100) {
edges {
node {
inventoryQuantity
}
}
}
}
}
pageInfo {
hasNextPage
endCursor
}
}
}
}
```graphqlquery CollectionProducts($id: ID!, $first: Int!, $after: String) {
collection(id: $id) {
id
title
sortOrder
products(first: $first, after: $after) {
edges {
node {
id
title
totalInventory
variants(first: 100) {
edges {
node {
inventoryQuantity
}
}
}
}
}
pageInfo {
hasNextPage
endCursor
}
}
}
}
```graphqlcollectionReorderProducts:mutation — validated against api_version 2025-01
collectionReorderProducts:mutation — validated against api_version 2025-01
mutation CollectionReorderProducts($id: ID!, $moves: [MoveInput!]!) {
collectionReorderProducts(id: $id, moves: $moves) {
job {
id
done
}
userErrors {
field
message
}
}
}
undefinedmutation CollectionReorderProducts($id: ID!, $moves: [MoveInput!]!) {
collectionReorderProducts(id: $id, moves: $moves) {
job {
id
done
}
userErrors {
field
message
}
}
}
undefinedSession Tracking
会话跟踪
Claude MUST emit the following output at each stage. This is mandatory.
On start, emit:
╔══════════════════════════════════════════════╗
║ SKILL: collection-reorganization ║
║ Store: <store domain> ║
║ Started: <YYYY-MM-DD HH:MM UTC> ║
╚══════════════════════════════════════════════╝After each step, emit:
[N/TOTAL] <QUERY|MUTATION> <OperationName>
→ Params: <brief summary of key inputs>
→ Result: <count or outcome>If , prefix every mutation step with and do not execute it.
dry_run: true[DRY RUN]On completion, emit:
For (default):
format: human══════════════════════════════════════════════
OUTCOME SUMMARY
Collection: <title>
Products reordered: <n>
Sort order: <inventory_desc|inventory_asc>
Errors: 0
Output: none
══════════════════════════════════════════════For , emit:
format: jsonjson
{
"skill": "collection-reorganization",
"store": "<domain>",
"started_at": "<ISO8601>",
"completed_at": "<ISO8601>",
"dry_run": false,
"steps": [
{ "step": 1, "operation": "CollectionProducts", "type": "query", "params_summary": "collection_id: <gid>, first: 250", "result_summary": "<n> products fetched", "skipped": false },
{ "step": 2, "operation": "CollectionReorderProducts", "type": "mutation", "params_summary": "sort_by: inventory_desc, <n> moves", "result_summary": "job submitted", "skipped": false }
],
"outcome": {
"collection_title": "<title>",
"products_reordered": 0,
"sort_by": "inventory_desc",
"errors": 0,
"output_file": null
}
}Claude 必须在每个阶段输出以下内容,这是强制要求。
启动时,输出:
╔══════════════════════════════════════════════╗
║ SKILL: collection-reorganization ║
║ Store: <store domain> ║
║ Started: <YYYY-MM-DD HH:MM UTC> ║
╚══════════════════════════════════════════════╝每步完成后,输出:
[N/TOTAL] <QUERY|MUTATION> <OperationName>
→ Params: <brief summary of key inputs>
→ Result: <count or outcome>如果,在每个mutation步骤前加上且不执行该步骤。
dry_run: true[DRY RUN]完成时,输出:
对于(默认):
format: human══════════════════════════════════════════════
OUTCOME SUMMARY
Collection: <title>
Products reordered: <n>
Sort order: <inventory_desc|inventory_asc>
Errors: 0
Output: none
══════════════════════════════════════════════对于,输出:
format: jsonjson
{
"skill": "collection-reorganization",
"store": "<domain>",
"started_at": "<ISO8601>",
"completed_at": "<ISO8601>",
"dry_run": false,
"steps": [
{ "step": 1, "operation": "CollectionProducts", "type": "query", "params_summary": "collection_id: <gid>, first: 250", "result_summary": "<n> products fetched", "skipped": false },
{ "step": 2, "operation": "CollectionReorderProducts", "type": "mutation", "params_summary": "sort_by: inventory_desc, <n> moves", "result_summary": "job submitted", "skipped": false }
],
"outcome": {
"collection_title": "<title>",
"products_reordered": 0,
"sort_by": "inventory_desc",
"errors": 0,
"output_file": null
}
}Output Format
输出格式
No CSV output. The skill reports the new sort order in the session completion summary. Use to preview the computed position list without committing.
dry_run: true不提供CSV输出。本技能会在会话完成摘要中报告新的排序顺序。使用可预览计算出的位置列表而不提交更改。
dry_run: trueError Handling
错误处理
| Error | Cause | Recovery |
|---|---|---|
| Collection is a smart/automated collection | Switch collection to manual ordering in Shopify admin |
| Invalid product ID or position | Check all product IDs belong to the collection |
| Collection not found | Invalid collection GID | Verify the GID in Shopify admin |
| Rate limit (429) | Too many paginated requests | Reduce |
| 错误 | 原因 | 解决方案 |
|---|---|---|
| 集合是智能/自动集合 | 在Shopify管理后台将集合切换为手动排序 |
mutation中的 | 产品ID或位置无效 | 检查所有产品ID是否属于该集合 |
| 集合未找到 | 集合GID无效 | 在Shopify管理后台验证GID |
| 速率限制(429) | 分页请求过多 | 将 |
Best Practices
最佳实践
- Always run first — the skill will print the proposed product order so you can verify before committing.
dry_run: true - is asynchronous —
collectionReorderProductsmay bejob.doneimmediately. The sort completes within a few seconds; refresh the storefront to verify.false - Use to push out-of-stock products to the bottom of the collection page, reducing customer frustration.
sort_by: inventory_asc - For large collections (250+ products), pagination is automatic but increases execution time. Consider running during off-peak hours.
- This skill only reads from the products node — it does not aggregate per-location. If you need location-specific sorting, use the
totalInventoryskill to identify which products to prioritize.low-inventory-restock
- 始终先使用运行——技能会打印拟议的产品顺序,你可以在提交前进行验证。
dry_run: true - 是异步的——
collectionReorderProducts可能会立即返回job.done。排序会在数秒内完成;刷新店铺前端即可验证。false - 使用可将无货产品推送到集合页面底部,减少客户不满。
sort_by: inventory_asc - 对于大型集合(250+产品),分页会自动执行但会增加执行时间,建议在非高峰时段运行。
- 本技能仅读取产品节点的——不会按位置聚合。如果你需要按特定位置排序,请使用
totalInventory技能来确定要优先处理的产品。low-inventory-restock