TL;DR: How do I load the product images/gallery without loading the whole product?
I want to load the images on a product. What I do in the .phtml
$_popularCollection = $this->getPopularCollection();
foreach ($_popularCollection as $_product):
// the rest
$mediaGallery = $_product->getMediaGalleryImages();
endforeach;
//the rest
What I do in the Block class:
public function getPopularCollection() {
// http://magento.stackexchange.com/q/5838/3089
// no category
if ( is_null( $this->getCategoryId() ) )
return false;
/** @var Mage_Catalog_Model_Category $category */
$category = Mage::getModel('catalog/category')->load( (int)$this->getCategoryId() );
/** @var Mage_Catalog_Model_Resource_Product_Collection $_popularCollection */
$_popularCollection = Mage::getModel('catalog/product')->getResourceCollection();
$_popularCollection->addAttributeToSelect('*');
$_popularCollection->setStoreId(Mage::app()->getStore()->getId());
$_popularCollection->addCategoryFilter($category);
return $_popularCollection;
}
This works But I load everything: $_popularCollection->addAttributeToSelect(*);
I tried $_popularCollection->addAttributeToSelect('media_gallery');
But it doesn't seem to work.