1

I have a Magento website configured with 1 website and 2 stores. Each store products are separated with root category, means each store has their own root category.

I want the products from store A not searchable from store B. How to override search to do such thing? which method should I look into?

Note: I don't want to use Visibility setting due to some reasons such as it will make a product from another store not clickable in cart/mini cart.

2

unassign products of Store A that you don't want to be shown in Store B, and they won't be searchable. ( Websites Tab in Product Edit mode)

3
  • how to "unassign" them in particural store? i have products assigned to root category for store B searchable from store A that has another root category. – Doni Wibowo Oct 16 '14 at 4:58
  • in backend Catalog->Manage Products-> Edit a product Websites Tab, uncheck the site you don't want that product to appear in. – Aftab Naveed Oct 16 '14 at 5:44
  • it's multi store, not multi website. Multi website will make it harder to manage the session (login, cart, etc) between websites. and our site shares the cart and login session between stores. – Doni Wibowo Oct 16 '14 at 6:50
1

To override the search you should rewrite the ResultController from catalogsearch module in magento core. It would be nice to override helper also.

1
  • already looked into it and i need to put addAttributeToFilter on the collection. where should i put it? – Doni Wibowo Oct 14 '14 at 9:38
1

I put addAttributeToFilter by rewriting Mage_CatalogSearch_Model_Layer::getProductCollection()

app/code/local/Vela/CatalogSearch/etc/config.xml

<?xml version="1.0"?>
<config>
    <modules>
    <Vela_CatalogSearch>
        <version>0.0.1</version>
    </Vela_CatalogSearch>
    </modules>
    <global>
    <models>
        <catalogsearch>
        <rewrite>
            <layer>Vela_CatalogSearch_Model_Layer</layer>
        </rewrite>
        </catalogsearch>
    </models>
    </global>
</config>

Then in my app/code/local/Vela/CatalogSearch/Model/Layer.php file

<?php

class Vela_CatalogSearch_Model_Layer extends Mage_CatalogSearch_Model_Layer
{
public function getProductCollection()
{
  if (isset($this->_productCollections[$this->getCurrentCategory()->getId()])) {
      $collection = $this->_productCollections[$this->getCurrentCategory()->getId()];
  } else {
      $collection = Mage::getResourceModel('catalogsearch/fulltext_collection');
      $this->prepareProductCollection($collection);
      $this->_productCollections[$this->getCurrentCategory()->getId()] = $collection;
  }

  // start modification
  $store_id = Mage::app()->getStore()->getId();
  $store_code =  Mage::app()->getStore()->getCode();

  $_product = Mage::getModel('catalog/product');
  $_attr = $_product->getResource()->getAttribute('universo_store');
  if ($_attr->usesSource()) {
      $_attr_option_id_seafolly = $_attr->getSource()->getOptionId("seafolly");
      $_attr_option_id_havaianas = $_attr->getSource()->getOptionId("seafolly");
  }

  if(stripos('seafolly',$store_code) !== FALSE){ // seafolly
      $store_id = $_attr_option_id_seafolly;
  } else {//havaianas
      $store_id = $_attr_option_id_havaianas;
  }

  $collection->addAttributeToFilter('universo_store', array('eq'=>$store_id));
  // end modification

  return $collection;
}
}
1
  • i will, i am waiting for the timer to go off – Doni Wibowo Oct 16 '14 at 6:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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