A Product is the heart of any e-Commerce system, A product contains multiple information like Title, SKU, Price, Inventory, Images and so more details.
Let’s start with the Main point, A product has multiple images, and I will just explore how each product is stored in the database. Your confusion will be clear after reading the below details of the image saved in the database.
catalog_product_entity_varchar used for store product image value.
Look at Example, Suppose Product has a single image with a role like base, thumbnail, and small_image, All the value of the images is stored under the
value field separately.
If the product image value is abc.jpg then the value is stored as
catalog_product_entity_varchar table looks like,
In the above image with the attribute_id column,
87 is attribute_id for a base,
88 is attribute_id for thumbnail and
89 is for small_image attribute_id and product id is 2.
You can check each image’s Role (image, small_image, thumbnail, swatch_image, etc…) attribute id value under the eav_attribute table.
All the images value for a product are also stored under the given tables,
catalog_product_entity_media_gallery catalog_product_entity_media_gallery_value catalog_product_entity_media_gallery_value_to_entity
Once you add any images for a product, one entry is generated under a catalog_product_entity_media_gallery table. if you have added multiple images for a product, multiple entries are generated in a table.
catalog_product_entity_media_gallery table stored the value of the images as attribute_id with image value. when you check the above table, you can see attribute_id value as 88 (88 is attribute_id of
small_image in my case) and value field is /a/b/abc.jpg
catalog_product_entity_media_gallery_value table used to store values of store id, Image Label, image position, Hide from Product Page (disabled column), and link with product id value stored as row_id.
catalog_product_entity_media_gallery_value_to_entity used for mapping product entity id with
PHYSICAL LOCATION OF IMAGES:
All the images are stored under the pub/media/catalog/product folder in the Magento root.
If the product image name is abc.jpg then it’s stored under the above folder with an a/b/abc.jpg path with the first folder name is the first character of the image and the second folder is the second character of the image name.
If an image has only one character like a.jpg then it’s stored under a/_/a.jpg path under pub/media/catalog/product
A final path for image name
abc.jpg is pub/media/catalog/product/a/b/abc.jpg
Get Media image collection from the Specific product by Gallery Image Collection
Fetch Image Roles types by link Get Image roles types from the product.
- How Magento Save/Delete Media Images after Create/Update Product from Admin Panel?
Magento 2 Backend Product Images Saved Logic will be available in the
Magento_Catalog module with Model class
execute() the method that handles the image saves operation.