I've written an interface for Magento 2 admin that allows creation and editing of key product attributes from a phone.

Once a product is created and it's images attached to the product, I have been looking for a quick way to select from a gallery which is the main image.

For each store view and attribute I found running the following immediate changes the image in the admin panel.

INSERT INTO `catalog_product_entity_varchar` (`attribute_id`, `store_id`, `entity_id`, `value`) VALUES (?,?,?,?) ON DUPLICATE KEY UPDATE `value` = ?

I'm entering the correct attribute values for swatch, image, small_image and thumbnail, for all stores the product is present in and adding the filepath accordingly.

The frontend image however, remains unchanged and worse still, the image then doesn't change from the admin panel unless i clear all the cache's and reindex.

I'm not using flat products so I'm a bit stumped as to what could be stopping the image from changing.

1 Answer 1


On further checking this is actually working as intended, with the Admin and Catalog grid thumbnails, swatch images etc being changed. However to make it the first image on the product page, you need to change the order of the items in the catalog_product_entity_media_gallery_value table.

UPDATE `catalog_product_entity_media_gallery_value` SET `position` = '0' WHERE `entity_id` = ? AND `value_id` = ? 
SET @i:=0; UPDATE `catalog_product_entity_media_gallery_value` SET `position` = @i:=(@i+1) WHERE `entity_id` = ? ORDER BY `position` ASC

Now the selected image is also the first image the user sees when visiting the page

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.