3
votes

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

1 Answers

1
votes

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);