英文:
Import and sort media for an article in shopware 6
问题
以下是您要翻译的内容:
在某些产品上,图像的顺序不正确。管理员不想通过管理界面浏览所有媒体,而是希望通过导入来对它们进行排序。
我创建了一个像这里提到的那样的配置文件:
https://docs.shopware.com/en/shopware-en/settings/importexport#import-of-media
但结果是,在导入先前导出的文件时(仅减少为一个测试商品且没有进一步更改)出现错误:
已存在文件名为 "xxx-yyy-zzz.jpg" 的文件。
然后产品上的媒体会重复,但它们不存在(在管理界面和商店前端上都有红叉标记)。
是否有适当的方法来导出现有的媒体,重新排序它们,然后再次导入文件?
如果这不起作用,是否有其他正确完成此任务的方法?
英文:
at some products the images are not in the right order. instead of going through all of the media from the admin, the adminstrator want to sort them via import.
i created a profile like mentioned here:
https://docs.shopware.com/en/shopware-en/settings/importexport#import-of-media
but as a result it gives me an error when importing the previously exported file (reduced to only one testarticle and without any further changes):
> A file with the name "xxx-yyy-zzz.jpg" already exists.
and then i have the media double on the product, but they are non-existing (redcrossed in admin and storefront).
is there a proper way to export the existing media, resort them and import the file again?
if that does not work, is there another way to complete that task properly?
答案1
得分: 1
以下是翻译好的部分:
快速的方式是通过管理 API。
首先,通过产品编号过滤器获取给定产品的媒体映射。
示例响应:
{
"total": 2,
"data": [
{
"productId": "01dbf9f74b964383b1a5ef931ea39b1e",
"position": 1,
"media": {
"fileExtension": "jpg",
"fileName": "foo",
"id": "5164cb0e69ad487a92c1fc1f1d4a7505",
"apiAlias": "media"
},
"id": "3fd590d1e27d425aba6ce4cabd96c4d5",
"apiAlias": "product_media"
},
{
"productId": "01dbf9f74b964383b1a5ef931ea39b1e",
"position": 2,
"media": {
"fileExtension": "jpg",
"fileName": "bar",
"id": "eec8195fb1cf4ae69f1d7ded85c39111",
"apiAlias": "media"
},
"id": "4cb8c195612b40d68da0130d48037b99",
"apiAlias": "product_media"
}
],
"aggregations": []
}
然后,您可以获取data
属性中的整个数组,根据您的需求更改position
属性,并使用它来更新具有productId
的产品。只需删除有效载荷中的嵌套media
属性。
// PATCH /api/product/01dbf9f74b964383b1a5ef931ea39b1e
{
"media": [
{
"productId": "01dbf9f74b964383b1a5ef931ea39b1e",
"position": 2,
"id": "3fd590d1e27d425aba6ce4cabd96c4d5"
},
{
"productId": "01dbf9f74b964383b1a5ef931ea39b1e",
"position": 1,
"id": "4cb8c195612b40d68da0130d48037b99"
}
]
}
英文:
Fastest way would be via the admin API.
First fetch the media mappings for a given product, e.g. via a product number filter.
// POST /api/search/product-media
// Accept: application/json
{
"includes": {
"product_media": ["id", "media", "position", "productId"],
"media": ["id", "fileName", "fileExtension"]
},
"associations": {
"media": []
},
"filter": [
{
"type": "equals",
"field": "product.productNumber",
"value": "EXAMPLE123"
}
]
}
Example response:
{
"total": 2,
"data": [
{
"productId": "01dbf9f74b964383b1a5ef931ea39b1e",
"position": 1,
"media": {
"fileExtension": "jpg",
"fileName": "foo",
"id": "5164cb0e69ad487a92c1fc1f1d4a7505",
"apiAlias": "media"
},
"id": "3fd590d1e27d425aba6ce4cabd96c4d5",
"apiAlias": "product_media"
},
{
"productId": "01dbf9f74b964383b1a5ef931ea39b1e",
"position": 2,
"media": {
"fileExtension": "jpg",
"fileName": "bar",
"id": "eec8195fb1cf4ae69f1d7ded85c39111",
"apiAlias": "media"
},
"id": "4cb8c195612b40d68da0130d48037b99",
"apiAlias": "product_media"
}
],
"aggregations": []
}
You can then take that entire array from the data
property, change the position
properties according to your needs, and use it to update the product with the productId
. Just remove the nested media
properties in the payload.
// PATCH /api/product/01dbf9f74b964383b1a5ef931ea39b1e
{
"media": [
{
"productId": "01dbf9f74b964383b1a5ef931ea39b1e",
"position": 2,
"id": "3fd590d1e27d425aba6ce4cabd96c4d5"
},
{
"productId": "01dbf9f74b964383b1a5ef931ea39b1e",
"position": 1,
"id": "4cb8c195612b40d68da0130d48037b99"
}
]
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论