我想要显示所有带有名称和图片的产品。请检查我的代码,
这是我的控制者:
$model = Mage::getModel('catalog/product')->getCollection()
->addAttributeToSelect(array('name', 'descryption'))
->setPageSize(10);
$numberOfPages = $model->getLastPageNumber();
$data['products'] = $model->setCurPage($i)->load();
这是我的观点:
<?php
foreach ($data['products'] as $product) {
$productName = $product->getName();
?>
<div class="celeb-post" id="products-listing">
<img src="<?php ?>" alt="celeb" />
<div style="clear:both; height:10px;"></div>
<div class="celeb-name-title ucase clearfix" style="text-align:center;"><?php echo $productName ?></div>
</div>
<?php
}
?>
产品名称正在显示,但我如何获得图像?任何人都可以帮助查找产品图片并在视图中显示?
答案 0 :(得分:1)
请尝试以下代码:
$products = Mage::getModel('catalog/product')
->getCollection()
->addAttributeToSelect('*');
foreach($products as $product)
{
$image = $product->getImageUrl();
$product_image_url_gallery = $product->getMediaGalleryImages();
$galleryURL = '';
foreach ($product_image_url_gallery as $image) {
$galleryURL .= Mage::helper('catalog/image')->init($product, 'image', $image->getFile()).'<br>';
}
echo $product->getName().'<br>';
echo $image.'<br>';
echo $galleryURL.'<br>';
}