Magento 2.2.x
I want to set product image role programmatically not using product csv import
so please let us know how can i do that using script?
Thanks in advance !!!
You can load the products and then you can set like this, this is example to set small image
foreach ($products as $product){ $smallImage = $product->getSmallImage(); $imagePath = '/catalog/product' . $product->getImage(); if( $smallImage == 'no_selection' ){ $product->addImageToMediaGallery( $imagePath, array( 'small_image' ), false, false ); $product->save(); } }
Thanks for reply,
I had tried all solutions available in stack overflow or other magento community regarding this but it's not working.
Using your solution, if product image already exists than add another image working well but it it's role was not set.
I need to set product image role into existing product image not want to add new image.
Hello,
Please if anyone know solution for this then please give me suggestion