【发布时间】:2011-12-14 23:49:09
【问题描述】:
我在 Magento 中有一系列产品,我希望能够从中获取媒体库图像。但是我发现我必须遍历我的收藏并再次加载产品才能使 getMediaGalleryImages() 函数正常工作。
$products = Mage::getModel('catalog/product')
->getCollection()
->addAttributeToSelect('*')
->addAttributeToFilter('visibility', 4)
->addAttributeToFilter('status', 1);
foreach($products as $product) {
$_product = Mage::getModel('catalog/product')->load($product->getId());
$product->getMediaGalleryImages(); // This returns nothing
$_product->getMediaGalleryImages(); // Returns the Collection of Images
}
显然我可以继续每次只重新加载产品,但这会增加运行此代码所需的时间的相当多的开销。
有没有办法将媒体库图像添加到集合中?
【问题讨论】:
-
你可以加入:mediagallerycollection -> join productcollection where productId -s in(id,id,id,id)。由于每个产品通常有多个图像,因此您不能只将它们加入 productcollection
-
这个问题在另一个帖子中得到了回答:stackoverflow.com/questions/5900522/…