Rápli András
Rápli András

Reputation: 3923

Change Magento's default search results by passing result ids

I've customized the catalog advanced search page which now has a special visual search engine, that finds the desired products and returns their ids (via ajax). Given these ids I want to create a list of search results based on Magento's default search results page layout. Any ideas how to do that?

UPDATE Can't get it work for a while now, so I'll paste what I'm trying, maybe some of you can help.

   public function getIdsFromSearchUrl($value){
      $c = explode(',',$value);
      if(count($c) > 1){ return $c; } else { return $value; }
   }

   // THE FOLLOWING FUNCTION'S ORIGINAL VERSION IS COMMENTED OUT UP ABOVE

    public function getSearchCriterias()
    {
        $search = $this->_searchCriterias;
        /* display id filtering criteria */

        var_dump($search);

        $search = array();

        if(isset($_GET['productid'])) {
            $value = $this->getIdsFromSearchUrl($_GET['productid']);
            if(is_array($value)){
              foreach($value as $v){
                if(is_numeric($v)){
                  $product = Mage::getModel('catalog/product')->load($v);
                  var_dump($product->getId());
                  $search[] = array('name'=>'Name','value'=>$product->getName());
                }
              }
            } else {
              if(is_numeric($value)){
               $product = Mage::getModel('catalog/product')->load($value);
               $search[] = array('name'=>'Name','value'=>$product->getName());
              }
            }
        }

        var_dump($search);

        $this->_searchCriterias = $search;

        return $search;
    }
                Mage::getSingleton('catalog/product_visibility')->addVisibleInSearchFilterToCollection($this->_productCollection);
            if(isset($_GET['productid'])){
              $value = $this->getIdsFromSearchUrl($_GET['productid']);
              if(is_array($value)){
                foreach($value as $v){ if(is_numeric($v)){ $this->_productCollection->addProductFilter(Mage::getModel('catalog/product')->load($v),true); } }
              } else { if(is_numeric($value)){ $this->_productCollection->addProductFilter(Mage::getModel('catalog/product')->load($value),true); } }
            }
        }

        return $this->_productCollection;
    }

It is syntactically correct, but shows no results. And it still requires one other field to be completed, which I have no idea where to change.

Upvotes: 0

Views: 192

Answers (1)

Related Questions