我正在Magento商店上实现谷歌标签管理器,我需要在数据层中为搜索词和搜索结果的数量添加一个标签。
我可以使用获取搜索文本
Mage::helper('catalogsearch')->getQueryText();
但我不知道如何获得返回的结果数。我试过使用
$search = Mage::getSingleton('catalogsearch/advanced')->getProductCollection();
但这并不奏效。有人能给我指正确的方向吗?
试试这个:
$size = Mage::getSingleton('catalogsearch/advanced')->getProductCollection()->getSize();
以下是允许我获取搜索结果集合的代码。
$term = Mage::helper('catalogsearch')->getQueryText();
$collection = Mage::getResourceModel('catalogsearch/query_collection')->setQueryFilter($term)->getData();
$results = $collection[0]['num_results'];
return json_encode($results);