magento2: Can't add product images roles with $product->addImageToMediaGallery
I tried To Upload Images by using
$imagePath = $mediapath."image_upload/tmp/products/".$value['image_path'];// path of the image
$product->addImageToMediaGallery($imagePath, ['image', 'small_image', 'thumbnail', 'swatch_image'], true, false);
Images are uploded success, but Images roles are not assign to this uploded Image

About this issue
- Original URL
- State: open
- Created 4 years ago
- Comments: 34 (4 by maintainers)
Facing same issue with version 2.4.6 @engcom-Hotel
Hi @vasilii-b, here is your Magento Instance: https://0fffdb6612a3f7f18332d599477958b9-2-4-develop.instances.magento-community.engineering Admin access: https://0fffdb6612a3f7f18332d599477958b9-2-4-develop.instances.magento-community.engineering/admin_bfa1 Login: 6833e7de Password: ab4b3607716c
I also had issues importing images with proper roles. I figured out the product must be loaded again after it was saved with the ProductRepositoryInterface - otherwise the image is saved but the roles are set to “no_selection”:
Hope this helps someone.