php – 从Magento的产品系列中获取产品媒体库图像

前端之家收集整理的这篇文章主要介绍了php – 从Magento的产品系列中获取产品媒体库图像前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我在Magento有一系列产品,我希望能够从中获取媒体库图像.但是我发现我必须迭代我的集合并再次加载产品以使getMediaGallery Images()函数正常工作.
$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
}

显然,我每次都可以继续重新加载产品,但这会增加运行此代码所需时间的开销.

有没有办法将媒体库图像添加到集合中?

您可以使用
$product->load('media_gallery');

在getMediaGalleryImages之前(关于您在集合中加载的产品).

原文链接:https://www.f2er.com/php/135928.html

猜你在找的PHP相关文章