Hello,
sharing a "hacky way" that works on ps 1.5 & ps 1.6. I Hope it will lead someone to making it as a nice solution for a client.
This should not be used as a permanent solution. If the blocklayered module gets update, the code will get overwritten. P.S. the particular code works with all of the attributes, not only the color.
Edit /modules/blocklayered/blocklayered.php
1. Put this in the function ajaxCall() after the line $this->getProducts(...)
if (isset($selected_filters['id_attribute_group']) && $selected_filters['id_attribute_group']) {
$this->switchProductImages($selected_filters, $products);
}
}
2. Put these at the very end of the file (before closing curly brace)
private function switchProductImages($selected_filters, &$products) {
foreach ($products as &$product) {
foreach($selected_filters['id_attribute_group'] as $key => $value) {
$attributeImageId = $this->getProductImage($product['id_product'], $key);
if((int)($attributeImageId) > 0) {
$product['id_image'] = $product['id_product'].'-'.$attributeImageId;
}
}
}
}
private function getProductImage($id_product, $id_attribute) {
$query = 'SELECT `id_image` FROM `ps_product_attribute_combination`
INNER JOIN `ps_product_attribute` ON `ps_product_attribute`.`id_product_attribute` = `ps_product_attribute_combination`.`id_product_attribute`
INNER JOIN `ps_product_attribute_image` ON `ps_product_attribute_image`.`id_product_attribute` = `ps_product_attribute`.`id_product_attribute`
WHERE `id_attribute` = \''.$id_attribute.'\' AND `id_product` = \''.$id_product.'\'';
return DB::getInstance()->getValue($query);
}