Question

In Prestashop I want to know by which pattern prestashop shows the product default image? I mean lets say I have a mysql query for prestashop like this

SELECT ps_product.id_product,ps_product.id_category_default,description_short,ps_product_lang.name FROM ps_product_lang,ps_product WHERE ps_product_lang.id_lang=1 AND ps_product.id_product=ps_product_lang.id_product

Now here I will get the product id, product category, description, and name. Now according to prestashop default products and database I have for the product iPod Nano the database fields are like

id_product  id_category_default
  1               3       

Now if I want to get the product image I will use

img/p/id_product/id_category_default/id_product.id_category_default

This will make the img src like

img/p/1/3/13.jpg

Now when I used that I got the image for Belkin Leather Folio for iPod

but with the same condition I got the exact image for ipod shuffle. So can someone kindly tell me how to get the exact default image for the product name? Any help and suggestions will be really appreciable.

Was it helpful?

Solution

You can use this query to get the image id of the cover image (image displayed in category view) for a product:

SELECT id_image FROM ps_image WHERE cover = 1 AND id_product = $idProduct

Then you can generate the image path with the following code:

$imgPath = 'img/p/';
for ($i = 0; $i < strlen($idImage); $i++) {
  $imgPath .= $idImage[$i] . '/';
}
$imgPath .= $idImage . '.jpg';

If you want to get the image id of the default thumbnail displayed in the product view then you can use this query:

SELECT id_image FROM ps_image WHERE position = 1 AND id_product = $idProduct
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top