2015-11-04 124 views
0

现在我试图循环浏览每个产品图像,并输出其全尺寸图像url以及图像大小。获取产品的所有Magento图像(原始尺寸)

PHP代码

<?php foreach ($this->getGalleryImages() as $_image): ?> 
    <?php echo $this->helper('catalog/image')->init($this->getProduct(), 'image', $_image->getFile()); ?> 
    <?php echo $this->helper('catalog/image')->init($this->getProduct(), 'image')->getOriginalHeight(); ?> 
    <?php echo $this->helper('catalog/image')->init($this->getProduct(), 'image')->getOriginalWidth(); ?> 
<?php endforeach; ?> 

试图找出为什么这个返回主图像大小为每个图像。

此代码不会在所有

<?php echo $this->helper('catalog/image')->init($this->getProduct(), 'image', $_image->getFile())->getOriginalWidth(); ?> 

工作也不做这个...

<?php echo $this->helper('catalog/image')->init($this->getProduct(), 'image', $_image->getOriginalWidth()); ?> 

任何想法?

回答

0

想通了!显然 - > getOriginalWidth和 - > getOriginalHeight不适用于其他主要图像。

用这个变通办法,

PHP

<?php foreach ($this->getGalleryImages() as $_image): ?> 
    <?php $fullImage = new Varien_Image($_image->getPath()); ?> 
     <?php echo $this->helper('catalog/image')->init($_product, 'image', $_image->getFile()); ?>' 
     <?php echo $fullImage->getOriginalWidth(); ?> 
     <?php echo $fullImage->getOriginalHeight(); ?> 
<?php endforeach; ?> 
+0

我感兴趣的反馈这个解决方案。这不是有效的吗?迄今似乎没有影响到性能。 – Xander