Magento 2 REST API在可配置的产品上分配缩略图图像



我当前能够通过Magento 2 Rest API(Magento 2.2.1)添加产品,但有1个主要问题。

使用单个产品,一切都很好,我能够用图像创建它们,并将图像分配为缩略图等。但是,使用可配置的产品,图像并未将其分配为缩略图,但仍然成功上传。p>这是一个单一的产品休息调用,可以正常工作:

{
"product": {
    "sku": "08130056-DARKNAVY",
    "name": "Dakine Campus 25L Backpack - Dark Navy",
    "price": "44.9900",
    "status": "1",
    "visibility": "4",
    "type_id": "simple",
    "weight": "1.0000",
    "extension_attributes": {
        "stock_item": {
            "manage_stock": 1,
            "qty": "1.0000",
            "is_in_stock": true
        }
    },
    "options": [],
    "tier_prices": [],
    "media_gallery_entries": [{
        "media_type": "image",
        "label": "Dakine Campus 25L Backpack - Dark Navy",
        "position": "0",
        "disabled": 0,
        "types": [],
        "file": "/media/catalog/product/i//i/m/image_8735.jpg",
        "content": {
            "base64_encoded_data": "IMAGE BASE64 HERE",
            "type": "image/jpeg",
            "name": "08130056 DARKNAVY"
        }
    }, {
        "media_type": "image",
        "label": "Dakine Campus 25L Backpack - Dark Navy",
        "position": "0",
        "disabled": 0,
        "types": ["image", "small_image", "thumbnail", "swatch_image"],
        "file": "/media/catalog/product/i//i/m/image_8736.jpg",
        "content": {
            "base64_encoded_data": "IMAGE BASE64 HERE",
            "type": "image/jpeg",
            "name": "08130056 DARKNAVY"
        }
    }],
    "attribute_set_id": 62,
    "custom_attributes": [{
        "attribute_code": "manufacturer",
        "value": "503"
    }, {
        "attribute_code": "color",
        "value": "452"
    }, {
        "attribute_code": "short_description",
        "value": "<span>The Campus 25 litre follows the lead of our popular Campus 33 litre back-to-school backpack with a slightly smaller volume-great for smaller students or smaller workloads. Packed with all the same features including a large top compartment with a padded laptop sleeve and room for books and binders, a fleece lined pocket for sunglasses, a slim organiser pocket, and a handy insulated pocket to keep lunch and snacks cool. Padded shoulder straps and an adjustable sternum strap ensure a perfect fit. Dimensions =&nbsp;</span>18.5 x 12 x 9" [ 47 x 31 x 23cm ]<div><ul><li>Limited Lifetime Warranty</li><li>600D Polyester</li><li>Fits most 14" laptops</li><li>Insulated cooler pocket</li><li>Organiser pocket</li><li>Fleece lined pocket for sunglasses</li><li>Mesh side pockets</li><li>Adjustable sternum strap</li></ul></div><br>"
    }, {
        "attribute_code": "barcode",
        "value": "610934177053"
    }, {
        "attribute_code": "category_ids",
        "value": [350]
    }, {
        "attribute_code": "meta_title",
        "value": "Dakine Campus 25L Backpack - Dark Navy"
    }, {
        "attribute_code": "meta_keyword",
        "value": "dakine,campus,25l,backpack,-,dark,navy,urbansurfer,urban,surfer,mens,backpacks"
    }, {
        "attribute_code": "meta_description",
        "value": "Dakine Campus 25L Backpack - Dark Navy - Shop online for a large range of  including Dakine with fast, free shipping from an official stockist."
    }, {
        "attribute_code": "news_from_date",
        "value": "2017-12-22 10:56:59"
    }, {
        "attribute_code": "news_to_date",
        "value": "2018-01-22 10:56:59"
    }]
},
"save_options": true
}

这是一个可配置的产品,由于某种原因,没有设置缩略图,图像,small_image和swatch:

{
"product": {
    "sku": "226787-705-29",
    "name": "Levis Dawson Lace Up Boots - Dark Brown",
    "price": "99.9900",
    "status": "1",
    "visibility": "4",
    "type_id": "configurable",
    "weight": 1,
    "extension_attributes": {
        "stock_item": {
            "manage_stock": 1,
            "qty": "0.0000",
            "is_in_stock": true
        }
    },
    "options": [],
    "tier_prices": [],
    "media_gallery_entries": [{
        "media_type": "image",
        "label": "Levis Dawson Lace Up Boots - Dark Brown",
        "position": "0",
        "disabled": 0,
        "types": [],
        "file": "/media/catalog/product/i//i/m/image_8637.jpg",
        "content": {
            "base64_encoded_data": "IMAGE BASE64 HERE",
            "type": "image/jpeg",
            "name": "226787 705 29"
        }
    }, {
        "media_type": "image",
        "label": "Levis Dawson Lace Up Boots - Dark Brown",
        "position": "0",
        "disabled": 0,
        "types": [],
        "file": "/media/catalog/product/i//i/m/image_8638.jpg",
        "content": {
            "base64_encoded_data": "IMAGE BASE64 HERE",
            "type": "image/jpeg",
            "name": "226787 705 29"
        }
    }, {
        "media_type": "image",
        "label": "Levis Dawson Lace Up Boots - Dark Brown",
        "position": "0",
        "disabled": 0,
        "types": ["image", "small_image", "thumbnail", "swatch_image"],
        "file": "/media/catalog/product/i//i/m/image_8639.jpg",
        "content": {
            "base64_encoded_data": "IMAGE BASE64 HERE",
            "type": "image/jpeg",
            "name": "226787 705 29"
        }
    }],
    "attribute_set_id": 44,
    "custom_attributes": [{
        "attribute_code": "manufacturer",
        "value": "537"
    }, {
        "attribute_code": "color",
        "value": "453"
    }, {
        "attribute_code": "short_description",
        "value": "<span>Levis Dawson Lace Up Boots Dark Brown from Levi's are a great style option for your off-duty look. Featuring a soft leather outer, this pair has padded ankles for comfort and will team well with denim.</span><br><ul><li>Leather Comfort Insole</li><li>Anatomical Design</li><li>High Shock Absorption</li><li>Genuine Leather Coating</li></ul>"
    }, {
        "attribute_code": "barcode",
        "value": ""
    }, {
        "attribute_code": "category_ids",
        "value": [347]
    }, {
        "attribute_code": "meta_title",
        "value": "Levis Dawson Lace Up Boots - Dark Brown"
    }, {
        "attribute_code": "meta_keyword",
        "value": "levis,dawson,lace,up,boots,-,dark,brown,urbansurfer,urban,surfer,levi's,mens,shoes"
    }, {
        "attribute_code": "meta_description",
        "value": "Levis Dawson Lace Up Boots - Dark Brown - Shop online for a large range of  including Levi's with fast, free shipping from an official stockist."
    }, {
        "attribute_code": "news_from_date",
        "value": "2017-12-15 14:56:33"
    }, {
        "attribute_code": "news_to_date",
        "value": "2018-01-15 14:56:33"
    }]
},
"save_options": true
}

您可以看到两个呼叫的"类型"设置相同,但对于可配置的产品似乎被忽略了,Magento 2 log中也没有任何内容。

我们拥有的每种可配置产品都始终发生,但是所有单个产品都运行良好。儿童产品根本没有任何图像。我还测试了添加一个没有子产品的可配置产品,结果是相同的。

我可以在Magento 2管理员中手动设置缩略图等,但是我需要通过这些休息呼叫对此进行自动化。我尝试了各种各样的事情,只是无法固定出什么问题。

我也有同样的问题。

解决方案:

我使用catalogproductattributemediagallerymanagementv1列出所有媒体库项目(通过get" .../v1/products/products/testrongku/media":列表" id"和其他字段。

)。

选择第一个图像(使用" Media_type" =" Image")后,我创建了一个新的JSON对象。

{ 
    "entry":
    {
        "id": 1086,
        "media_type": "image",
        "label": "This is my image description",
        "position": 1,
        "disabled": false,
        "types": [ "image", "small_image", "thumbnail" ]
    }
}

使用put发送(例如" .../v1/products/testrongku/media/1086")图像正确保存。

最新更新