这种情况发生的原因是产品列表中未加载
image
属性。通常情况下,您可以在编辑属性时更改此设置,但对于此属性,您无法编辑这些设置。我认为这是因为它是一个库存属性。
简而言之:
UPDATE catalog_eav_attribute SET used_in_product_listing = 1 WHERE attribute_id = 106;
警告,只有当你确定catalog_product
实体的image
属性ID为106时,才应执行此查询!
一些答案建议使用以下方法:
$_product = Mage::getModel('catalog/product')->load($_item->getProduct()->getId());
echo $this->helper('catalog/image')->init($_product, 'image')->resize(38, 38);
你不应该这样做!因为这将会进行完整的产品加载!这不是高效的,而且很可能在循环内部执行,这更糟糕!抱歉我刚才大声了!
通常我不赞成直接编辑数据库,但在这种情况下,这是最简单的解决方案:
# First make sure we are using all the right IDs, who knows, I have seen some fubar'ed deployments
SELECT entity_type_id FROM eav_entity_type WHERE entity_type_code = 'catalog_product';
# 10
SELECT attribute_id FROM eav_attribute WHERE attribute_code = 'image' AND entity_type_id = 10;
# 106
# Now that we know the exact attribute_id....
UPDATE catalog_eav_attribute SET used_in_product_listing = 1 WHERE attribute_id = 106;
现在,
image
属性的数据将自动加载到产品列表页面上,然后您可以像这样访问它:
echo $this->helper('catalog/image')->init($_product, 'image');
最好的部分是你不需要在循环中加载整个产品!千万不要这样做。
另外,因为我知道会有人说这不是Magento的方式,另一种选择是创建一个模块,其中包含一个运行该命令的SQL设置脚本。