Automatically add four stars on the results page, products page, for all products that do have an image. (Use the database direct to update the stars for the SKUs that have image_count = true)

Use the image_count column in Magento to sort for products that have an image.

image_count is a boolean, 'true' or' 'false'. Any help. Thank in advance.


In Your Module try this in



namespace Vendor\HelloWorld\Model;
use Magento\Framework\Model\AbstractModel;
class ProductReviews extends AbstractModel{

    protected $_ratingFactory;
    protected $_productFactory;
    protected $_ratingFactory;
    protected $_reviewFactory;

    public function __construct(
            \Magento\Store\Model\StoreManagerInterface $storeManager,
            \Magento\Catalog\Model\ProductFactory $productFactory,
            \Magento\Review\Model\RatingFactory $ratingFactory,
            \Magento\Review\Model\ResourceModel\Review\CollectionFactory $reviewFactory,
        ) {
            $this->_storeManager = $storeManager;
            $this->_productFactory = $productFactory;
            $this->_ratingFactory = $ratingFactory;
            $this->_reviewFactory = $reviewFactory;

    public function getReviewCollection($productId){
        $collection = $this->_reviewFactory->create()


    public function getRatingCollection(){
        $ratingCollection = $this->_ratingFactory->create()

        return $ratingCollection->getData();


Approve it, if it helps You, Thanks

  • Thank for the answer. How can I get image_count in database. – MichaelHa Oct 19 '19 at 3:05
  • here is your answer below, if it these two answer usefull to you approve then, Thanks – Munesh Jalwani Oct 21 '19 at 8:40

The following query returns the number of images per product:

SELECT sku,count(*) FROM `catalog_product_entity` AS a 
LEFT JOIN `catalog_product_entity_media_gallery_value_to_entity` AS b ON a.entity_id = b.entity_id 
group by sku

I am not sure if it works properly in case of complex products or bundle. But it gives you an idea about how to proceed.

More generally, you should use the following Magento tables:

  • catalog_product_entity (for product ids)
  • catalog_product_entity_media_gallery_value_to_entity (for image and product relationship)
  • catalog_product_entity_media_gallery (for images path)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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