我该如何修复这个错误,或者我应该如何更改格式?
产品是这样来的mongoDB。
{
_id: new ObjectId("64db3748a42f997c0544eda0"),
id: 'LORENZO-CAM_COBALTO',
shopifyId: 'none',
site: 'Brands Distribution',
whichStore: 'uk',
title: 'Duca di Morrone LORENZO CAM COBALTO',
body_html: '<p>Made in: Italy<br/>Collection: Spring/Summer<br/>Gender: Man<br/>Type: Loafers<br/>Upper: suede<br/>Internal lining: leather<br/>Sole: rubber<br/>Details: round toe</p>',
vendor: 'Duca di Morrone',
product_type: 'Shoes',
variants: [
{
option1: 'EU 40',
option2: 'Blue',
title: 'Bodies',
price: 29,
inventory_management: 'shopify',
inventory_quantity: 9
},
{
option1: 'EU 41',
option2: 'Blue',
title: 'Bodies',
price: 29,
inventory_management: 'shopify',
inventory_quantity: 18
},
{
option1: 'EU 42',
option2: 'Blue',
title: 'Bodies',
price: 29,
inventory_management: 'shopify',
inventory_quantity: 37
},
{
option1: 'EU 43',
option2: 'Blue',
title: 'Bodies',
price: 29,
inventory_management: 'shopify',
inventory_quantity: 48
},
{
option1: 'EU 44',
option2: 'Blue',
title: 'Bodies',
price: 29,
inventory_management: 'shopify',
inventory_quantity: 43
},
{
option1: 'EU 45',
option2: 'Blue',
title: 'Bodies',
price: 29,
inventory_management: 'shopify',
inventory_quantity: 33
},
{
option1: 'EU 46',
option2: 'Blue',
title: 'Bodies',
price: 29,
inventory_management: 'shopify',
inventory_quantity: 11
},
{
option1: 'EU 40',
option2: 'Brown',
title: 'Bodies',
price: 29,
inventory_management: 'shopify',
inventory_quantity: 12
},
{
option1: 'EU 41',
option2: 'Brown',
title: 'Bodies',
price: 29,
inventory_management: 'shopify',
inventory_quantity: 18
},
{
option1: 'EU 42',
option2: 'Brown',
title: 'Bodies',
price: 29,
inventory_management: 'shopify',
inventory_quantity: 36
},
{
option1: 'EU 43',
option2: 'Brown',
title: 'Bodies',
price: 29,
inventory_management: 'shopify',
inventory_quantity: 44
},
{
option1: 'EU 44',
option2: 'Brown',
title: 'Bodies',
price: 29,
inventory_management: 'shopify',
inventory_quantity: 43
},
{
option1: 'EU 45',
option2: 'Brown',
title: 'Bodies',
price: 29,
inventory_management: 'shopify',
inventory_quantity: 30
},
{
option1: 'EU 46',
option2: 'Brown',
title: 'Bodies',
price: 29,
inventory_management: 'shopify',
inventory_quantity: 13
}
],
images: [
{
src: 'https://www.brandsdistribution.com/prod/product-133457-1511628552.jpg/large.jpg'
},
{
src: 'https://www.brandsdistribution.com/prod/product-133457-1658920071.jpg/large.jpg'
},
{
src: 'https://www.brandsdistribution.com/prod/product-133457-1208489454.jpg/large.jpg'
},
{
src: 'https://www.brandsdistribution.com/prod/product-133457-223769419.jpg/large.jpg'
},
{
src: 'https://www.brandsdistribution.com/prod/product-133457-1617393261.jpg/large.jpg'
}
],
__v: 3
}
我的职位:
let response = await modules.axios.post(`https://${datas.config[findProduct.whichStore].shop}.myshopify.com/admin/api/2023-07/products.json`, {
product: {
...findProduct._doc,
variants: variantsArr
}
}, {
headers: {
'X-Shopify-Access-Token': datas.config[findProduct.whichStore].api
}
})
findProduct.shopifyId = response.data.product.id
findProduct.save()
functions.log(`${response.data.product.id} is added!`, 0, datas.config[findProduct.whichStore].shop)
return response.data
错误在这里:{ errors:{ base:[“变体'EU 40'已存在。”] } }
我在将产品上传到我的Shopify商店时收到了上面提到的错误。我的目标是能够将每个品种的颜色、尺寸和库存数量添加到商店中。当我阅读API文档时,我找不到任何有用的东西。
1条答案
按热度按时间zynd9foi1#
我可以给你一些建议,你听不听随你。首先,你正在使用非常旧的代码风格来设置Shopify中的API,这是不推荐的。你的代码很快就会停止工作。首先,库存管理现在是一个单独的部分,当创建产品(库存项目),它处理一个位置。其次,对你来说更重要的是,在处理选项时,首先,你要提供它们的名称,如下所示:
这让Shopify知道你的选择是什么。其次,当添加新的变量时,您需要提供这些选项的值,如“EU40”等,以确保每对都是唯一的。同样,使用选项,但这次是在变量数组中:
试试看,很管用我已经用GQL调用做了成千上万的产品,当我做这些简单的设置时,它们总是工作的。