通过传递结果ID来更改Magento的默认搜索结果

时间:2015-01-29 11:38:05

标签: magento

我已经定制了目录高级搜索页面,该页面现在有一个特殊的可视化搜索引擎,可以找到所需的产品,返回它们的ID (通过ajax)。鉴于这些ID,我想基于Magento的默认搜索结果页面布局创建搜索结果列表。任何想法如何做到这一点?

更新 现在不能让它工作一段时间,所以我会粘贴我正在尝试的东西,也许你们中的一些人可以提供帮助。

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

语法正确,但没有显示结果。它仍然需要完成另一个领域,我不知道在哪里改变。

相关问题