2017-12-28 17 views
1

Ich kann derzeit Produkte über die Magento 2 REST API (Magento 2.2.1) hinzufügen, habe aber ein großes Problem.Magento 2 REST API Zuweisen von Vorschaubildern zu konfigurierbaren Produkten

Mit einzelnen Produkten funktioniert alles super und ich kann sie mit Bildern erstellen und Bilder als Miniaturbilder usw. zuweisen. Jedoch werden bei konfigurierbaren Produkten die Bilder nicht als Miniaturbilder zugewiesen, aber trotzdem erfolgreich hochgeladen.

Hier ist ein Single Product REST Aufruf, der gut arbeitet:

{ 
"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 
} 

Und hier ist ein konfigurierbares Produkt, wo aus irgendeinem Grund das Miniaturbild, Bild, small_image und Swatch sind nicht gesetzt werden:

{ 
"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 
} 

Sie können sehen, dass "types" für beide Aufrufe gleich eingestellt ist, aber scheinbar nur für das konfigurierbare Produkt ignoriert wird. Es gibt auch keine Spuren in den Magento 2-Protokollen.

Dies geschieht ständig mit jedem konfigurierbaren Produkt, das wir haben, aber alle Einzelprodukte funktionieren großartig. Bei Child Products sind keine Bilder wie gewünscht eingestellt. Ich habe auch getestet, ein konfigurierbares Produkt ohne Kinderprodukte hinzuzufügen und die Ergebnisse sind die gleichen.

Ich kann das Thumbnail, etc. im Magento 2 Admin manuell einstellen, aber ich muss dies über diese REST-Aufrufe automatisieren. Ich habe alles Mögliche ausprobiert und kann einfach nicht feststellen, was falsch läuft.

Antwort

0

Ich hatte das gleiche Problem.

Lösung:

I catalogProductAttributeMediaGalleryManagementV1 verwendet, um alle Artikel Mediengalerie zur Liste (via GET ".../V1/products/TEST_SKU/media": Liste "id" und andere Bereiche).

Nach Auswahl des ersten Bildes (mit "media_type" = "image") habe ich ein neues JSON-Objekt erstellt.

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

Nach dem Senden PUT (z.B.“.../V1/products/TEST_SKU/Medium/1086") das Bild korrekt gespeichert.

Verwandte Themen