Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Returning media gallery images for associated products of a configurable product. 
 
parkin_m
Jr. Member
 
Total Posts:  18
Joined:  2008-12-01
 

I have a configurable product that has 2 simple products associated with it.

1. I can get the images from the product via:

// Returns a Varien_Data_Collection of the images associated with the configurable product
$_product->getMediaGalleryImages()

2. I can pull out models for the associated products:

// Returns an array of Mage_Catalog_Model_Product's (the associated products of a configurable product)
$_product->getTypeInstance()->getUsedProducts()

What I cannot work out however is how to get the media gallery images of these simple products.

// This just fails and outputs NULL
foreach($_product>getTypeInstance()->getUsedProducts() as $product)
{
    print_r
($product->getMediaGalleryImages());
}
 
Magento Community Magento Community
Magento Community
Magento Community
 
parkin_m
Jr. Member
 
Total Posts:  18
Joined:  2008-12-01
 

*Bump*

This is a pretty normal programming question I would have thought - surprised at the lack of response :/

 
Magento Community Magento Community
Magento Community
Magento Community
 
Brandlive_br
Guru
 
Avatar
Total Posts:  653
Joined:  2008-05-19
Buenos Aires, Argentina
 

I spent a lot of time messing with that to get the images of the associated products. Fortunately it’s not that hard.
First you need to get the actual object of the associated product, here’s a way:

$prod = Mage::getModel(’catalog/product’)->load($_associatedProduct->getId());

And now you can use getGalleryImages

$prod_images = $prod->getMediaGalleryImages();

After that just use a foreach to get each image.

You will need to do all of this inside another for each of the getUsedProducts, so you get each image of each associated product.

Hope this solves your problem.

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top