2013-07-23 67 views
2

返回NULL我们已经扩展主页滑块的客户,使他们能够拥有的产品在这个领域。getGalleryImages在Magento主页

作为其中的一部分,还有,我们希望得到的产品的主图像三个图像插槽,然后两个图像从媒体库(理想随机但如果在世界末日的ID)。

为了得到更好的理解,请看一下我们至今截图: -

featprodslider

我们使用以下建设集此模块: -

$featured_products = Mage::getModel('catalog/product') 
->getCollection() 
->addAttributeToSelect('*') 
->AddAttributeToFilter('featured', array('eq' => 1)); 

获取产品的主要形象是没有问题的,这是完美的与以下内容: -

<img class="gallery" src="<?php echo $this->helper('catalog/image')->init($product, 'small_image')->resize(225); ?>" alt="<?php echo $this->stripTags($this->getImageLabel($product, 'small_image'), null, true) ?>" /> 

而且这是很简单的让所有三个图像插槽使用主图像,如下图所示以上。

当我们试图但是调用getGalleryImages,这总是返回NULL(例如如): -

<?php if (count($this->getGalleryImages()) > 0): ?> 
<?php foreach ($this->getGalleryImages() as $_image): ?> 
<img class="gallery" src="<?php echo $this->helper('catalog/image')->init($this->getProduct(), 'thumbnail', $_image->getFile())->resize(100); ?>" width="100" height="100" alt="<?php echo $this->htmlEscape($_image->getLabel()) ?>" /> 
<?php endforeach; ?> 
<?php endif; ?> 

请可以在最好的办法有人提醒打电话主页上的画廊图像。有什么我们可以包括到集合构建,否则我们将需要添加一个观察者。

在此先感谢。

回答

2

终于设法得到这个工作...

<?php $_images = Mage::getModel('catalog/product')->load($product->getId())->getMediaGalleryImages(); ?>  
<?php if($_images){?>    
    <?php $i=0; foreach($_images as $_image) if ($i++ < 5) { $i++; ?> 
     <img class="gallery" src="<?php echo $this->helper('catalog/image')->init($product, 'thumbnail', $_image->getFile())->resize(255); ?>" alt="<?php echo $this->htmlEscape($_image->getLabel());?>" title="<?php $this->htmlEscape($_image->getLabel());?>" /> 
    <?php } ?> 
<?php } ?> 

我们列入foreach循环的if声明,以确保我们最多只有产品的媒体库图像的3回。

最终的结果,相比于原始图像,看起来像: -

featprodslider2

0

它看起来像你的块上直接调用getGalleryImages()。称它为产品对象(的例如$product->getGalleryImages()代替$this->getGalleryImages())上。

+0

这还出现了返回'NULL'。如有必要,我可以提供更多使用的代码。谢谢。 – zigojacko