我有这段代码:
//to-do
public function searchVehicles($terms, $offset=1, $order='ASC')
{
if (trim($terms) == '') {
return array();
}
$query = $this->_getQuery($terms);
$query->setStoreId(1);
if ($query->getId()) {
$query->setPopularity($query->getPopularity()+1);
}
else {
$query->setPopularity(1);
}
$query->prepare();
$query->save();
$collection = Mage::getResourceModel('catalog/product_collection');
$collection->getSelect()->joinInner(
array('search_result' => $collection->getTable('catalogsearch/result')),
$collection->getConnection()->quoteInto(
'search_result.product_id=e.entity_id AND search_result.query_id=?',
$query->getId()
),
array('relevance' => 'relevance')
);
$collection->setStore(1);
//Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($collection);
//Mage::getSingleton('catalog/product_visibility')->addVisibleInSearchFilterToCollection($collection);
return $this->_listProductCollection($collection, $offset, $order);
}
它位于Resource类中,可通过SOAP访问。
在我们开始之前:是的,我记得要进行缓存刷新和重新编译过程 - 我澄清一下,因为这对像我这样的新手xDDD来说是个常见问题。
现在:我可以访问这样的方法但返回[] 。
特别注意:$this->_listProductCollection($collection, $offset, $order);
工作,因为我在同一资源中从其他方法获取的其他集合中使用相同的方法,并且没问题。
让我回顾一下我的代码的用意,因为我是Magento的新手(我使用的是1.6.2版本)。
indexAction()
方法,并尝试了解它。网站中只有一个商店(id = 1),搜索查询的创建方式如下:
private function _getQuery($terms)
{
$query = Mage::getModel('catalogsearch/query')->loadByQuery($terms);
if (!$query->getId()) {
$query->setQueryText($terms);
}
return $query;
}
查询增加了它的受欢迎程度(我从控制器获取此代码。我认为这仅用于统计目的。)
(queryId, matchedProductId)
。我只保留匹配结果中的ID和商店1的产品。然而,当我点击这个API入口点时,返回的列表是[](空列表),虽然在通常的搜索栏中搜索给了我预期的结果。
问题:我错过了什么?我在这个过程中误解了什么?