發生這種情況的原因是因爲image
屬性未加載到產品列表中。通常,您可以在編輯屬性時更改此設置,但不能編輯這些屬性的設置。我認爲這是因爲它是一種股票屬性。
TLDR;
UPDATE catalog_eav_attribute SET used_in_product_listing = 1 WHERE attribute_id = 106;
**警告,你不應該直到你一定執行這個^^^查詢您的image
attribute_id爲catalog_product
實體是106!
一些答案表明這種方法:
$_product = Mage::getModel('catalog/product')->load($_item->getProduct()->getId());
echo $this->helper('catalog/image')->init($_product, 'image')->resize(38, 38);
你不應該這樣做!這是因爲你會做一個完整的產品負載!這是不高效的,而且很可能是在更糟的循環內完成的!對不起尖叫!
我通常不縱容直接DB編輯,但在這種情況下,對我來說是最簡單的解決方案:
# 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安裝腳本的模塊。
歡迎來到Stack Overflow。這是絕對[自行](http://meta.stackexchange.com/questions/12513/should-i-not-answer-my-own-questions/12519#12519)你自己的問題,但請張貼它作爲實際答案而不是問題本身。這使答案被投票/接受,並幫助我們保持「未答覆」清單更清晰。 – 2012-08-17 01:16:53