Magento无法导航到搜索结果页面

时间:2015-05-13 02:32:46

标签: magento search

知道为什么我的magento搜索根本没有导航到搜索结果页面。它只是在每次点击提交时刷新页面。

以下是网站http://remas.com.au

的链接

提前致谢!

1 个答案:

答案 0 :(得分:0)

您的表单操作是http://remas.com.au/catalogsearch/result/?q=neoguri(当查询是neoguri时)。提交表单时,会向Mage_CatalogSearch_ResultController的indexAction发出GET请求:

/**
 * Display search result
 */
public function indexAction()
{
    $query = Mage::helper('catalogsearch')->getQuery();
    /* @var $query Mage_CatalogSearch_Model_Query */

    $query->setStoreId(Mage::app()->getStore()->getId());

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

            if ($query->getRedirect()){
                $query->save();
                $this->getResponse()->setRedirect($query->getRedirect());
                return;
            }
            else {
                $query->prepare();
            }
        }

        Mage::helper('catalogsearch')->checkNotes();

        $this->loadLayout();
        $this->_initLayoutMessages('catalog/session');
        $this->_initLayoutMessages('checkout/session');
        $this->renderLayout();

        if (!Mage::helper('catalogsearch')->isMinQueryLength()) {
            $query->save();
        }
    }
    else {
        $this->_redirectReferer();
    }
}

看起来$ query-> getQueryText()为null或空

if ($query->getQueryText() != '') {
    ...
}
else {
    $this->_redirectReferer();
}

因此操作会重定向回其提交的页面。如果您有调试器,请在方法顶部设置断点

$query = Mage::helper('catalogsearch')->getQuery();

并检查$ query对象。您也可以转储该对象。如果这没有告诉你任何事情,继续挖掘。这是catalogsearch帮助器的getQuery方法(Mage_CatalogSearch_Helper_Data):

/**
 * Retrieve query model object
 *
 * @return Mage_CatalogSearch_Model_Query
 */
public function getQuery()
{
    if (!$this->_query) {
        $this->_query = Mage::getModel('catalogsearch/query')
            ->loadByQuery($this->getQueryText());
        if (!$this->_query->getId()) {
            $this->_query->setQueryText($this->getQueryText());
        }
    }
    return $this->_query;
}

和getQueryText方法:

/**
 * Retrieve search query text
 *
 * @return string
 */
public function getQueryText()
{
    if (!isset($this->_queryText)) {
        $this->_queryText = $this->_getRequest()->getParam($this->getQueryParamName());
        if ($this->_queryText === null) {
            $this->_queryText = '';
        } else {
            /* @var $stringHelper Mage_Core_Helper_String */
            $stringHelper = Mage::helper('core/string');
            $this->_queryText = is_array($this->_queryText) ? ''
                : $stringHelper->cleanString(trim($this->_queryText));

            $maxQueryLength = $this->getMaxQueryLength();
            if ($maxQueryLength !== '' && $stringHelper->strlen($this->_queryText) > $maxQueryLength) {
                $this->_queryText = $stringHelper->substr($this->_queryText, 0, $maxQueryLength);
                $this->_isMaxLength = true;
            }
        }
    }
    return $this->_queryText;
}

在这两种方法中的一种方法中,有些方法将查询文本设置为空。