Sample for loading attribute/combination images.
When there is no combination, it loads the default product image from the package.
class Product extends ProductCore { public function getImages($id_lang, Context $context = null) { $productsInPack = array(); $productsAttributeItem = array(); if (Pack::isPack((int) $this->id)) { $getProductInPack = Db::getInstance()->executeS('SELECT id_product_item, id_product_attribute_item FROM '._DB_PREFIX_.'pack WHERE id_product_pack = '.$this->id.' GROUP BY id_product_item'); if ($getProductInPack > 0){ foreach ($getProductInPack as $productPack){ if ($productPack['id_product_attribute_item']){ $getAttributeImage = Db::getInstance()->executeS('SELECT id_image FROM '._DB_PREFIX_.'product_attribute_image WHERE id_product_attribute = '.$productPack['id_product_attribute_item'].' GROUP BY id_image'); foreach ($getAttributeImage as $attributeImages){ $productsAttributeItem[] = $attributeImages['id_image']; } } if ($productPack['id_product_attribute_item'] == '0'){ $getImage = Db::getInstance()->executeS('SELECT id_image FROM '._DB_PREFIX_.'image WHERE id_product = '.$productPack['id_product_item']); foreach ($getImage as $image){ $productsAttributeItem[] = $image['id_image']; } } $productsInPack[] = $productPack['id_product_item']; } } } if ($productsInPack){ $getProducts = implode(', ', $productsInPack); } else { $getProducts = $this->id; } if ($productsAttributeItem){ $whereAttributeImages = ' AND i.id_image IN ('.implode(', ', $productsAttributeItem).')'; } else { $whereAttributeImages = ''; } $query = ' SELECT image_shop.`cover`, i.`id_image`, il.`legend`, i.`position` FROM `' . _DB_PREFIX_ . 'image` i ' . Shop::addSqlAssociation('image', 'i') . ' LEFT JOIN `' . _DB_PREFIX_ . 'image_lang` il ON (i.`id_image` = il.`id_image` AND il.`id_lang` = ' . (int) $id_lang . ') WHERE i.`id_product` IN (' . $getProducts . ')'.$whereAttributeImages.' ORDER BY `position`'; return Db::getInstance()->executeS($query); } public function __construct($id_product = null, $full = false, $id_lang = null, $id_shop = null, \Context $context = null) { parent::__construct($id_product, $full, $id_lang, $id_shop, $context); } }
FO: