Magento:取决于商店的程序化搜索 [英] Magento: programmatic search depending on store
问题描述
我正在使用Magento的商品目录搜索模块.我有2家商店.在第一个搜索"test"时,我得到5个结果.在第二个上搜索测试"时,我得到3个结果.
I'm using the catalogsearch module of Magento. I have 2 stores. When searching "test" on the first one, I get 5 results. When searching "test" on the second one, I get 3 results.
当我在第一个商店中搜索时,我想添加第二个商店的结果(只是结果数).
I'd like to add the results of the second store (just the number of results) when I search in the first one.
我添加了一个块和一个模板,我所需要的只是用于在第二家商店中检索结果数量的代码,这就是我要坚持的地方.
I added a block and a template, all I need is the code to retrieve the number of the results in the second store, and that's where I'm stucked.
我试图获取控制器代码,但是它总是向我返回第一个存储中的结果数:
I tried to get the controller code, but it always returns me the number of results in the first store :
私有功能 _getStoreQuery($ storeId){
private function _getStoreQuery($storeId) {
$query = Mage::helper('catalogSearch')->getQuery();
$query->setStoreId(7);
if ($query->getQueryText()) {
if (Mage::helper('catalogSearch')->isMinQueryLength())
{ $ query-> setId(0) -> setIsActive的(1) -> setIsProcessed(1); } 别的 { 如果($ query-> getId()){ $ query-> setPopularity($ query-> getPopularity()+ 1); } 别的 { $ query-> setPopularity(1); }
{ $query->setId(0) ->setIsActive(1) ->setIsProcessed(1); } else { if ($query->getId()) { $query->setPopularity($query->getPopularity()+1); } else { $query->setPopularity(1); }
$query->prepare();
}
Mage::helper('catalogSearch')->checkNotes();
if (!Mage::helper('catalogSearch')->isMinQueryLength())
{ $ query-> save(); } }
{ $query->save(); } }
var_dump($query);
return $query;
}
我之前也尝试过更改商店上下文,但是没有运气: 法师:: app()-> setCurrentStore($ secondStoreId);
I also tried to change the store context before, but no luck: Mage::app()->setCurrentStore($secondStoreId);
你有什么主意吗?谢谢
推荐答案
第二次尝试返回第一组结果的原因可能是因为您正在重用Mage_Catalogsearch_Model_Query
对象.您需要创建一组新的结果.在这里,集合将创建它们,您只需要遍历$collection
即可获取它们.
Probably the reason the first set of results is returned on your second try is because you are reusing the Mage_Catalogsearch_Model_Query
object. You need to create a new set of results instead. Here the collection will create those, you just need to iterate through $collection
to get them.
$queryText = Mage::helper('catalogSearch')->getQueryText();
$collection = Mage::getResourceModel('catalogsearch/query_collection')
->setStoreId($storeId)
->setQueryFilter($queryText);
这篇关于Magento:取决于商店的程序化搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!