Jump to content

How to get a product's image in a specific color ?


gama

Recommended Posts

Hello everyone !

 

I was wondering if anyone knows what is the link between an attribute product and its image in the prestashop database. For example, if I want to select all the images of products which are blue what is the request that I have to make ?

 

I hope you understand my question, English is not my native language, sorry for any mistake.

Link to comment
Share on other sites

By blue I mean a product feature, I found it in the table attribute_lang in the database as name but I can find the link with the corresponding image for a product.

 

Thanks for answering me so quickly :)

Link to comment
Share on other sites

Hello,

 

Getting images is complex due to several changes in Prestashop versions.

 

What do you mean by blue, is it a product feature, a combination or the most present color in an image ?

 

Regards

The version which I used is 1.5.6.2

Link to comment
Share on other sites

Ok then if you have 1.5.6.2 images are dispatched like this for one id product :

- several id_image

 

To get one id_product/id_image :

 

$link = new Link();
 
$id_product =1;
$id_image = 4;
 $product = new Product($id_product);
 $url = $link->getImageLink($product->link_rewrite, "$id_product-$id_image");

 

Of course first you have to do sql query to get product with feature blue to then try to get image.

 

Regards

  • Like 1
Link to comment
Share on other sites

$sql='SELECT '._DB_PREFIX_.'product_attribute.id_product, '._DB_PREFIX_.'attribute.color, id_image
from '._DB_PREFIX_.'product_attribute
join '._DB_PREFIX_.'product_attribute_image on ('._DB_PREFIX_.'product_attribute.id_product_attribute = '._DB_PREFIX_.'product_attribute_image.id_product_attribute)
join '._DB_PREFIX_.'product_attribute_combination on ('._DB_PREFIX_.'product_attribute.id_product_attribute = '._DB_PREFIX_.'product_attribute_combination.id_product_attribute)
join '._DB_PREFIX_.'attribute on ('._DB_PREFIX_.'attribute.id_attribute = '._DB_PREFIX_.'product_attribute_combination.id_attribute)
where color <> ""';

I finally get it, the link is in the table product_attribute_image !

Thank you very much for your help.

 

Have a nice day !

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...