I have a script to import a list of product from xls. It works fine except for the image; I use the following bits of code:
...
if(file_exists(Mage::getBaseDir('media') . DS . 'import' . DS . $gallery_img)){
$product->addImageToMediaGallery(Mage::getBaseDir('media') . DS . 'import' . DS . $gallery_img, null, false, false);
}
...
The image is actually added to the product but it's not selected, so it does not show in the frontend:
How can I "select" it programmatically?
Thanks
Best Answer
If you check Magento's
addImageToMediaGallery
function located at app\code\core\Mage\Catalog\Model\Product.php file,You will see that second attribute is code of attribute with type 'media_image'. This attribute will define which image will be set as which media image.
By default there are three.
So you need to pass value to your second argument as below
to set them as main image, small image and thumbnail image.