I am using the code below to show some custom image attributes for all the simple products that are attached to the configurable product.
This works fine when the product only has one variation e.g colour. The problem is when the product has multiple variations so for example:
- Size: M / Colour: Red
- Size: L / Colour: Red
Size: XL / Colour: Red
Size: M / Colour: Green
- Size: L / Colour: Green
- Size: XL / Colour: Green
So when the product is like this it shows the custom image attributes 3 times, I need it to only show each custom colour attribute once so the red one once and the Green one once at the moment there would be six which is not right.
<?php
$conf = Mage::getModel('catalog/product_type_configurable')->setProduct($_product);
$col = $conf->getUsedProductCollection()->addAttributeToSelect('*')->addFilterByRequiredOptions(); ?>
<div class="relative">
<?php
foreach($col as $simple_product){ ?>
<div class="container-swatch">
<img width="35" height="35" src="<?php echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA) . 'catalog/product' . $simple_product->getSwatch() ?>">
<div class="content">
<img src="<?php echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA) . 'catalog/product' . $simple_product->getLargeSwatch() ?>">
<div class="inside-swatch-name"><?php echo $simple_product->getAttributeText('real_colour'); ?></div>
</div>
</div>
<?php } ?>