我必须把产品从一个Shopify商店转移到另一个商店。要做到这一点,我使用Shopify GraphQL管理API。在移动数据之前,我正在转换数据,所以我不能让Shopify帮助我。
无论如何,我从Shopify的API中获取产品,并将它们存储在JSON文件中。每个产品大约3000行,包含所有的变体类型。
我必须定义查询字段和变量吗?我希望只是传递Shopify返回的整个JSON对象并将其提供给GraphQL。目前,我必须手动定义字段(NodeJS):
const addProduct = (product) => axios.post(apiPath, {
query: `
mutation productCreate($input: ProductInput!) {
productCreate(input: $input) {
userErrors {
field
message
}
product {
title
handle
descriptionHtml
...
}
}
}
`,
variables: {
input: {...product}
}
})
但是以这种方式定义查询字段将是一个非常长的过程,有没有办法不定义查询?
这里有一个例子从Shopify从产品对象。我不得不限制行数:
{
"body_html": " The Air Jordan 3 Retro 'UNC' arrives in March 2020 as an homage to Michael Jordan's alma mater. The special edition presents university-inspired colors on its dual-textured leather upper and eyestays, with elephant print panels granting an iconic touch. Valor Blue hits both Jumpman logos on the tongue and heel while the visible Air unit in the midsole and rubber outsole wrap up the styling. ",
"price_min_usd": 0,
"compare_at_price_max_usd": null,
"available": false,
"review_count": 0,
"percent_sale_min_aud": 0,
"variants": [
{
"merged_options": [
"size:3 UK"
],
"price_cad": "0.00",
"price_usd": "0.00",
"presentment_prices": [
{
"compare_at_price": null,
"price": {
"amount": "0.00",
"currency_code": "AED"
}
},
{
"compare_at_price": null,
"price": {
"amount": "0.00",
"currency_code": "AUD"
}
},
{
"compare_at_price": null,
"price": {
"amount": "0.00",
"currency_code": "CAD"
}
},
{
"compare_at_price": null,
"price": {
"amount": "0.00",
"currency_code": "DKK"
}
},
{
"compare_at_price": null,
"price": {
"amount": "0.00",
"currency_code": "EUR"
}
},
{
"compare_at_price": null,
"price": {
"amount": "0.00",
"currency_code": "GBP"
}
},
{
"compare_at_price": null,
"price": {
"amount": "0.00",
"currency_code": "ILS"
}
},
{
"compare_at_price": null,
"price": {
"amount": "0",
"currency_code": "JPY"
}
},
{
"compare_at_price": null,
"price": {
"amount": "0.00",
"currency_code": "QAR"
}
},
{
"compare_at_price": null,
"price": {
"amount": "0.00",
"currency_code": "SAR"
}
},
{
"compare_at_price": null,
"price": {
"amount": "0.00",
"currency_code": "USD"
}
}
],
"inventory_management": "shopify",
"available": false,
"title": "UK 3 | EU 35.5 | US 3.5",
"price": "0.00",
"price_aed": "0.00",
"id": 40807884062909,
"sku": "CT8532-104.3UK",
"price_eur": "0.00",
"barcode": null,
"price_dkk": "0.00",
"inventory_quantity": 0,
"image": null,
"compare_at_price": null,
"fulfillment_service": "manual",
"price_aud": "0.00",
"price_ils": "0.00",
"price_jpy": "0",
"inventory_policy": "deny",
"price_gbp": "0.00",
"price_qar": "0.00",
"price_sar": "0.00"
},
{
"merged_options": [
"size:3.5 UK"
],
"price_cad": "0.00",
"price_usd": "0.00",
"presentment_prices": [
{
"compare_at_price": null,
"price": {
"amount": "0.00",
"currency_code": "AED"
}
},
{
"compare_at_price": null,
"price": {
"amount": "0.00",
"currency_code": "AUD"
}
},
{
"compare_at_price": null,
"price": {
"amount": "0.00",
"currency_code": "CAD"
}
},
{
"compare_at_price": null,
"price": {
"amount": "0.00",
"currency_code": "DKK"
}
},
{
"compare_at_price": null,
"price": {
"amount": "0.00",
"currency_code": "EUR"
}
},
{
"compare_at_price": null,
"price": {
"amount": "0.00",
"currency_code": "GBP"
}
},
{
"compare_at_price": null,
"price": {
"amount": "0.00",
"currency_code": "ILS"
}
},
{
"compare_at_price": null,
"price": {
"amount": "0",
"currency_code": "JPY"
}
},
{
"compare_at_price": null,
"price": {
"amount": "0.00",
"currency_code": "QAR"
}
},
{
"compare_at_price": null,
"price": {
"amount": "0.00",
"currency_code": "SAR"
}
},
{
"compare_at_price": null,
"price": {
"amount": "0.00",
"currency_code": "USD"
}
}
],
"inventory_management": "shopify",
"available": false,
"title": "UK 3.5 | EU 36 | US 4",
"price": "0.00",
"price_aed": "0.00",
"id": 40807884095677,
"sku": "CT8532-104.3.5UK",
"price_eur": "0.00",
"barcode": null,
"price_dkk": "0.00",
"inventory_quantity": 0,
"image": null,
"compare_at_price": null,
"fulfillment_service": "manual",
"price_aud": "0.00",
"price_ils": "0.00",
"price_jpy": "0",
"inventory_policy": "deny",
"price_gbp": "0.00",
"price_qar": "0.00",
"price_sar": "0.00"
},
{
"merged_options": [
"size:4 UK"
],
"price_cad": "0.00",
"price_usd": "0.00",
"presentment_prices": [
{
"compare_at_price": null,
"price": {
"amount": "0.00",
"currency_code": "AED"
}
},
{
"compare_at_price": null,
"price": {
"amount": "0.00",
"currency_code": "AUD"
}
},
{
一个简单的方法是下载一个产品,在那里你可以得到有效的Shopify产品JSON。现在删除所有id键。将该对象发送到新店中的Product Create。在循环中重复
你也可以批量下载产品,给你JSON,然后迭代,并以这种方式构建产品,并调用create。
无论哪种方式,执行此任务的代码都很简短,很简单。
@BugHunterUK -根据我的理解,您正在使用JSON文件将产品数据从一个商店移动到另一个商店,但您不必这样做。您可以要求Shopify支持这样做。他们会把你所有的产品从A店搬到b店。