检查集合是否已加载图像属性:
$productId = 1234;
$product = Mage::getModel('catalog/product')
->load($productId);
echo (string)Mage::helper('catalog/image')->init($product, 'image')->resize(75, 75);
echo (string)Mage::helper('catalog/image')->init($product, 'small_image')->resize(75, 75);
echo (string)Mage::helper('catalog/image')->init($product, 'thumbnail')->resize(75, 75);
如果这只给你一些占位符,那么集合没有加载图像。
您可以扩展您的集合,例如:
$collection = Mage::getModel('catalog/product')->getCollection()
->addAttributeToSelect('small_image')
->addAttributeToSelect('thumbnail')
->addAttributeToSelect('image');
或者使用媒体配置来处理:
$prodImage = Mage::getModel('catalog/product_media_config')->getMediaUrl($product->getThumbnail());
或使用
$prodImage = Mage::getResourceSingleton('catalog/product')->getAttributeRawValue($productId, 'image', Mage::app()->getStore());
平面表格
这可能是由于平面表格引起的。请检查您是否启用了平面表格:
系统 > 配置 > 目录 > 目录 > 前端 > 使用平面目录产品
如果是,请检查平面表格中是否包含图像属性:
describe catalog_product_flat_1; // number varies depending on store
如果图像属性不是平面表的一部分,请通过将以下代码添加到app / etc / config.xml来将其添加到表中。
<config>
<frontend>
<product>
<collection>
<attributes>
<image />
</attributes>
</collection>
</product>
</frontend>
</config>