Magento:根据商店进行编程搜索
我正在使用 Magento 的目录搜索模块。我有2家商店。当在第一个搜索“test”时,我得到 5 个结果。当在第二个搜索“test”时,我得到 3 个结果。
当我在第一个商店中搜索时,我想添加第二个商店的结果(仅是结果数)。
我添加了一个块和一个模板,我所需要的只是检索第二个商店中结果数量的代码,这就是我陷入困境的地方。
我尝试获取控制器代码,但它总是返回第一家商店中的结果数:
私有函数 _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); } 别的 { if ($query->getId()) { $query->setPopularity($query->getPopularity()+1); } 别的 { $query->setPopularity(1); }
$query->prepare(); } Mage::helper('catalogSearch')->checkNotes(); if (!Mage::helper('catalogSearch')->isMinQueryLength())
{ $查询->保存(); } }
var_dump($query); 返回$查询; }
之前也尝试过更改商店上下文,但没有成功: 法师::app()->setCurrentStore($secondStoreId);
你有什么想法吗?谢谢
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 :
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);
}
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();
}
}var_dump($query); return $query; }
I also tried to change the store context before, but no luck:
Mage::app()->setCurrentStore($secondStoreId);
Do you have any idea? Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
第二次尝试返回第一组结果的原因可能是您正在重用
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.