Magento : How to get small images of all items in bundled product
Question
I want to show all images of item(product) of bundled product on product listing page ,is there any Magento function to do so, please guide me way to do it.
I created bundled product with 4 items say a,b,c,d
Now on product listing page I want to show all 4 small_images of these product .
How can I do it ?
Solution
Try this:
$model= Mage::getModel('catalog/product');
//$product is a product object
if($product->getTypeId() == 'bundle'){
$bundles = $product->getTypeInstance(true)->getChildrenIds($product->getId(), false);
$item = array();
foreach($bundles as $index => $items){
foreach($items as $id){
$item[] = $id;
//break; //only get first item
//un-comment above line if you want only one (first) item.
}
}
if($item){
$child = $model
->getCollection()
->addAttributeToSelect(array('name', 'price', 'image', 'small_image'))
->addAttributeToFilter('entity_id', array('in' => $item))
->setOrder('price', 'DESC')
->load()
;
}
foreach($child as $item){
echo $item->getName();
echo "<br>";
echo '<img id="image" src="'.$this->helper('catalog/image')->init($item, 'small_image')->keepAspectRatio(true)->keepFrame(false)->resize(120, 100).'" alt="'.$_helper->productAttribute($item, $item->getName(), 'name').'"/>';
echo "<br>";
echo "<br>";
}
}
Key Points
$product
is a product object.
This should work. Good luck.
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange