views:

39

answers:

1

Hi, 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

+1  A: 

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);
clockworkgeek
I think it is indeed the problem, but your tip does not resolve it.
frinux
Here is the content of the collection: http://pastebin.com/BwiFEQbiAnd when I try to iterate over it, it crashes Magento (page stops loading):foreach ($collection as $col) { var_dump($col); }The database contains also only one query (the one on store 1)
frinux
When I try the same thing I get this http://pastebin.com/nVKQPSky. If I search for something that doesn't exist the collection is empty and nothing crashes. In short, I cannot recreate what you are seeing.
clockworkgeek
Now I think about it, if it crashes when doing a dump it must be returning too much data on each object. I would use `var_dump($col->debug())` or `echo $col->getNumResults()`
clockworkgeek