I have a function to retrieve the URLs of a configurable product's simple product images in the product listing. The problem is, I am not able to retrieve both, but only small image OR thumbnail of each simple product - it seems as if the variable containing the small image url gets "overwritten" by the thumbnail variable.

Here's the relevant code (without elseif and else statements):

public function getSimpleProductImages($id, $code)
    $values = $this->_storageModel->getOptions($id, $code);

    if ($values){
        foreach ($values as $Key => $attributecolor) {
            $product = Mage::getModel('catalog/product')->load($id);
            $childIds = Mage::getModel('catalog/product_type_configurable')->getChildrenIds($product->getId());
            $simpleProducts = Mage::getModel('catalog/product_type_configurable')->getUsedProducts(null,$product);
            $SmallImage = array();
            $ThumbImage = array();

            foreach($simpleProducts as $simpleProduct) { 
            if($Key == $simpleProduct->getColorManufacturer() && $simpleProduct->getSmallImage() !='no_selection'){
                $SmallImage[$simpleProduct->getColorManufacturer()] = Mage::helper('catalog/image')->init($simpleProduct, 'small_image')->resize(160);
                $ThumbImage[$simpleProduct->getColorManufacturer()] = Mage::helper('catalog/image')->init($simpleProduct, 'thumbnail')->resize(160);

            $attributes = Mage::getModel('eav/entity_attribute_option')->getCollection()->setStoreFilter()->join('attribute','attribute.attribute_id=main_table.attribute_id', 'attribute_code');
            foreach ($attributes as $attribute) {
                if ($attribute->getOptionId() == $Key) {
                    $SmallImageUrl = $SmallImage[$attribute->getOptionId()];
                    $ThumbImageUrl = $ThumbImage[$attribute->getOptionId()];

In the end, both of the variables $smallurl and $thumburl contain the URL of the thumbnail which is retrieved after the small image URL. If I just use one variable, I get the correct URL.

Any ideas???

  • Have a look at my answer for magento.stackexchange.com/questions/8258/… this will solve your issue. May 1, 2014 at 20:38
  • Thanks David, it looks like your answer is the solution to my problem, I will try it!
    – Socrates
    May 1, 2014 at 20:41
  • David, your solution in the other post worked just fine. If you post it as anwser, I will accept it. Thanks again
    – Socrates
    May 1, 2014 at 20:51