Jump to content

Sql query for counting images for all products


satkauskas

Recommended Posts

Hi, there is a nice sql query to count images of all products in database. Nice for database analysis / manual cleansing.



select b.id_product, reference, supplier_reference, active, photo_qty from
(SELECT id_image, id_product, count(id_image) as photo_qty
FROM ps_image 
WHERE 1 
group by id_product
) as a join ps_product as b on a.id_product=b.id_product

order by photo_qty desc


Why not to pre-include a bundle of "useful" sql queries into later PS versions in SQL manager menu?

  • Like 1
Link to comment
Share on other sites

Try with something like that

  if ($id_product = (int)Tools::getValue('id_product')) {
   $product = new Product($id_product, true, $this->context->language->id, $this->context->shop->id);
   $images = $product->getImages((int)$this->context->language->id);
   $this->context->smarty->assign('nb_images', count($images));
    }
  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...