我的问题是如何在magento的自动完成列表中的产品标题附近获取产品图片。
我做了很多搜索,大部分答案都是添加以下代码:
$imageUrl = Mage::helper('catalog/image')->init($item, 'image');
但它不起作用,并将我作为所有产品的网址:
catalog/product/cache/1/image/9df78eab33525d08d6e5fb8d27136e95/images/catalog/product/placeholder/image.jpg
函数getSuggestData()
:
public function getSuggestData()
{
if (!$this->_suggestData) {
$collection = $this->helper('catalogsearch')->getSuggestCollection();
$query = $this->helper('catalogsearch')->getQueryText();
$counter = 0;
$data = array();
foreach ($collection as $item) {
$imageUrl = Mage::helper('catalog/image')->init($item, 'image');
$_data = array(
'title' => $item->getQueryText(),
'row_class' => (++$counter)%2?'odd':'even',
'num_of_results' => $item->getNumResults(),
'url' => $imageUrl
);
if ($item->getQueryText() == $query) {
array_unshift($data, $_data);
}
else {
$data[] = $_data;
}
}
$this->_suggestData = $data;
}
return $this->_suggestData;
}
感谢您的帮助