TL; DR:如何在不加载整个产品的情况下加载产品图像/图库?
我想将图像加载到产品上。我在.phtml中做什么
$_popularCollection = $this->getPopularCollection();
foreach ($_popularCollection as $_product):
// the rest
$mediaGallery = $_product->getMediaGalleryImages();
endforeach;
//the rest
我在Block课上做什么:
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;
}
这有效,但我加载了所有内容: $_popularCollection->addAttributeToSelect(*);
我尝试过,$_popularCollection->addAttributeToSelect('media_gallery');
但是似乎没有用。