I use an import script to create products with associated images that are assigned to roles thumbnail and small image.

It works well, products and images are imported and they display as thumbnail and small image on the front-end website.

But when I try to edit one of those products via Magento admin, the roles thumbnail and small image are not selected in the UI and saving the product will make this image's roles to be lost.

Why may cause effective thumbnail to not be detected as one when loading the Edit product page? Did I do something the bad way in this import script?

Any clue of what the source of this problem can be?

Here is the import code:

                                  'images' => array(),
                                  'values' => array()

    foreach ($product['pictures'] as $key => $picture)
        $image_url = $picture['picture'];
        $image_ext = pathinfo($image_url, PATHINFO_EXTENSION);
        $imageData = base64_encode(file_get_contents($image_url));
        $image = $this->_imageContentFactory->create()
            ->setName($sku . '-' . $key . '.' . $image_ext)

        $entry = $this->_productAttributeMediaGalleryEntryFactory->create();
        if (0 == $key)
            $entry->setTypes(['image', 'small_image', 'thumbnail']);


        $entries[] = $entry;



EDIT: after more investigation, it appears roles are only lost for 'all store views', in any other store views, the image rules are correctly detected.

  • I am facing this exact issue! Only difference is we are using default Magento import
    – Hashid
    Apr 7, 2018 at 6:56

2 Answers 2


you need to used this to import product with images.

// Adding Image to product
$imagePath = $entries[0]->getFile(); // path of the image
$product->addImageToMediaGallery($imagePath, array('image', 'small_image', 'thumbnail'), false, false);
  • Thanks for your help Dhiren, but I think this is not a good thing to use the almost deprecated $product->save() method, that's why i use repositories to save my product, and I never manage to got it work with addImageToMediaGallery(), i added the line where I save the product to the code snippet for info
    – Gael COAT
    Oct 28, 2016 at 14:41

Just execute the SQL command in your database:

SELECT *  FROM `catalog_product_entity_varchar` WHERE `value` LIKE 'no_selection'

For more info check this support page out.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.