I am working on one website - multi store functionality and facing issue in catalog search module. I am getting all store products when i search how i can fetch results on basis of store alloted category only.

1 Answer 1


You could edit your search template file and hardcode the cat for each storeview as you can filter your searches using the following:


Or have alook and see how you can grab which storeview has which cats assigned and modify the search form on the fly.

Another option you could have is to edit the products per storeview and exclude from searchresults for storeviews in which it should not be found.

You could probably also do this with a script.

Create a new file in your magento root

// load the mage file 

// load magento 

Mage::app(); // not run() because you just want to load Magento, not run it.

You have to load the product collection by storeId, so ..


Then ..

// load all products from category
$products = Mage::getSingleton('catalog/category')->load($categoryId)

then loop through each product setting things the way you want .. especially the visibility

try {
      // website ID the product is assigned to, as an array

    // set the visibility to only catagory ( 1 - not visible, 2 - category, 3 - search, 4 - vat & search)

and finally save it ..

        // now save the product

This is a rough outline, you'd have to modify the logic exactly to your needs and test it thouroughly.

Don't forget that you need to reindex, if you have a lot of products I'd also make sure you disable the automatic indexer before editing 10000 of products to avoid lock timeouts and server overloads.

Here is a quick function to do that:

// set the indexing modus in magento 
function setIndexingManual($value = TRUE) { 

    // set the magento indexing status to auto
    $pCollection = Mage::getSingleton('index/indexer')->getProcessesCollection();

    if($value) { // TRUE
        $mode = Mage_Index_Model_Process::MODE_REAL_TIME;
    } else {    
        $mode = Mage_Index_Model_Process::MODE_MANUAL;

    foreach ($pCollection as $process) {

and run it with

// set the magento indexing status to manual

before running your script and re-enable with

// set the magento indexing status to back to auto


Make sure you test your script on a test server and definately not on the live server. And always make a backup!

  • How can this achieve by script.
    – Mathew
    Sep 11, 2015 at 11:47
  • I know modifications done in fulltext.php but dont know how to do this.
    – Mathew
    Sep 11, 2015 at 11:48
  • I've edited my answer with a rough outline.
    – tecjam
    Sep 11, 2015 at 12:01
  • In which file i have to make all changes, i am not getting this code because i am new in magento....
    – Mathew
    Sep 11, 2015 at 12:03
  • Do not change any files! Its magento rule # 1 - never change core files!! I would simply create a new file in the magento root, ive edited my answer. It;s probably not very easy for a newcomer, but test and make sure you print stuff out so you know what it's doing in the script and to find errors ..
    – tecjam
    Sep 11, 2015 at 12:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.