如何在magento

时间:2015-09-08 06:26:56

标签: php magento

我希望获得每个产品相关的图像,这些图像不是分配给产品,而是想要在前端显示所有相关图像。

enter image description here

<?php
foreach ($data['product'] as $product) { 

                            $product_id                 =   $product->getId();
                            $product_name               =   $product->getName();
                            $product_description        =   $product->getDescription();
                            $product_price        =   $product->getPrice();

                            $isporductImage     =   $product->getImage();
                            $product_image      =   Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB, true) . "media/catalog/product" . $product->getImage();
                            $isproductthumbnail = $product->getThumbnail();
                            $product_thumbnail  =   Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB, true) . "media/catalog/product" . $product->getThumbnail();
                            $collectionimage    = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB, true) . "media/catalog/category/thumb/" . $data['collection']['image'];
                            $productplaceholderImage = $this->getSkinUrl() . "whi/assets/images/whi_placeholder.png";


                        ?>

                        <?php if ($isproductthumbnail != "") { ?>
                                  <div class="image-div" style="background: url('<?php echo $product_thumbnail;?>');">
                                    <img src="<?php echo $product_thumbnail; ?>" alt="celeb" />
                                  </div>

                          <?php }elseif ($isporductImage != "") { ?>
                                  <div class="image-div" style="background: url('<?php echo $product_image;?>');">
                                    <img src="<?php echo $product_image; ?>" alt="celeb" />
                                  </div>
                            <?php } else { ?>
                                    <div class="image-div" style="background: url('<?php echo $productplaceholderImage;?>');">     
                                      <img src="<?php echo $productplaceholderImage ?>" alt="celeb" />
                                    </div>

                            <?php } ?>

我想在此列表中显示所有相关产品图片。

 <ul class="outfit-images-cmt">
                <li><img src="<?php echo $this->getSkinUrl() ?>whi/assets/images/doll.png"></li>
                <li><img src="<?php echo $this->getSkinUrl() ?>whi/assets/images/doll.png"></li>
                <li><img src="<?php echo $this->getSkinUrl() ?>whi/assets/images/doll.png"></li>
                <li><img src="<?php echo $this->getSkinUrl() ?>whi/assets/images/doll.png"></li>
                </ul>

1 个答案:

答案 0 :(得分:0)

尝试使用以下代码获取所有图库图片:

$product_image_url_gallery = $product->getMediaGalleryImages();
$galleryURL = '';
echo '<ul class="outfit-images-cmt">';

foreach ($product_image_url_gallery as $image) {
  $galleryImage = Mage::helper('catalog/image')->init($product, 'image', $image->getFile());
   echo '<li><img src="'.$galleryURL.'"></li>'
}

echo '</ul>';