Is there a function to get the image or the color of an Attribute in prestashop? when you add a product on the cart i would like to show the image of the chosen attribute instead of the principale image. When i read the $products variable it put the name of the attribute and other information but it doesn't show the id that i may use to find the correct image in the color folder (/img/co/)
You need a specific function to get the image id
public static function getProducImage($id_product_attribute,$id_product)
{
if (isset($id_product_attribute) && $id_product_attribute) {
$id_image = Db::getInstance()->getValue('
SELECT `image_shop`.id_image
FROM `'._DB_PREFIX_.'product_attribute_image` pai'.
Shop::addSqlAssociation('image', 'pai', true).'
LEFT JOIN `'._DB_PREFIX_.'image` i ON (i.`id_image` = pai.`id_image`)
WHERE id_product_attribute = '.(int)$id_product_attribute. ' ORDER by i.position ASC');
}
if (!isset($id_image) || !$id_image) {
$id_image = Db::getInstance()->getValue('
SELECT `image_shop`.id_image
FROM `'._DB_PREFIX_.'image` i'.
Shop::addSqlAssociation('image', 'i', true, 'image_shop.cover=1').'
WHERE i.id_product = '.(int)$id_product
);
}
return $id_image;
}