简体   繁体   English

在prestashop中获取属性的图像和颜色

[英]Get image and color of an attribute in prestashop

Is there a function to get the image or the color of an Attribute in prestashop? 是否有一个函数来获取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/) 当我读取$ products变量时,它会放置属性的名称和其他信息,但它不会显示我可能用于在颜色文件夹中找到正确图像的ID(/ img / co /)

You need a specific function to get the image id 您需要一个特定的函数来获取图像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;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM