2012-11-08 27 views
2

我的一位用戶向我發送了此鏈接,該鏈接來自我們自己的magento網站。我們有這個例外,任何想法我怎麼能解決這個問題?完整性約束違規:1052訂單子句中的列「位置」不明確

http://www.theprinterdepox.com/catalogsearch/result/index/?cat=100&q=1022&x=0&y=0

There has been an error processing your request 


SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'position' in order clause is ambiguous 

Trace: 
#0 /home/theprint/public_html/lib/Varien/Db/Statement/Pdo/Mysql.php(110): Zend_Db_Statement_Pdo->_execute(Array) 
#1 /home/theprint/public_html/lib/Zend/Db/Statement.php(300): Varien_Db_Statement_Pdo_Mysql->_execute(Array) 
#2 /home/theprint/public_html/lib/Zend/Db/Adapter/Abstract.php(479): Zend_Db_Statement->execute(Array) 
#3 /home/theprint/public_html/lib/Zend/Db/Adapter/Pdo/Abstract.php(238): Zend_Db_Adapter_Abstract->query('SELECT DISTINCT...', Array) 
#4 /home/theprint/public_html/lib/Varien/Db/Adapter/Pdo/Mysql.php(389): Zend_Db_Adapter_Pdo_Abstract->query('SELECT DISTINCT...', Array) 
#5 /home/theprint/public_html/lib/Zend/Db/Adapter/Abstract.php(791): Varien_Db_Adapter_Pdo_Mysql->query(Object(Varien_Db_Select), Array) 
#6 /home/theprint/public_html/app/code/core/Mage/Catalog/Model/Resource/Product/Collection.php(878): Zend_Db_Adapter_Abstract->fetchCol(Object(Varien_Db_Select)) 
#7 /home/theprint/public_html/app/code/core/Mage/Catalog/Model/Layer.php(291): Mage_Catalog_Model_Resource_Product_Collection->getSetIds() 
#8 /home/theprint/public_html/app/code/core/Mage/Catalog/Model/Layer.php(221): Mage_Catalog_Model_Layer->_getSetIds() 
#9 /home/theprint/public_html/app/code/core/Mage/Catalog/Block/Layer/View.php(163): Mage_Catalog_Model_Layer->getFilterableAttributes() 
#10 /home/theprint/public_html/app/code/core/Mage/Catalog/Block/Layer/View.php(122): Mage_Catalog_Block_Layer_View->_getFilterableAttributes() 
#11 /home/theprint/public_html/app/code/core/Mage/Core/Block/Abstract.php(238): Mage_Catalog_Block_Layer_View->_prepareLayout() 
#12 /home/theprint/public_html/app/code/core/Mage/Core/Model/Layout.php(430): Mage_Core_Block_Abstract->setLayout(Object(Mage_Core_Model_Layout)) 
#13 /home/theprint/public_html/app/code/core/Mage/Core/Model/Layout.php(446): Mage_Core_Model_Layout->createBlock('catalogsearch/l...', 'catalogsearch.l...') 
#14 /home/theprint/public_html/app/code/core/Mage/Core/Model/Layout.php(238): Mage_Core_Model_Layout->addBlock('catalogsearch/l...', 'catalogsearch.l...') 
#15 /home/theprint/public_html/app/code/core/Mage/Core/Model/Layout.php(204): Mage_Core_Model_Layout->_generateBlock(Object(Mage_Core_Model_Layout_Element), Object(Mage_Core_Model_Layout_Element)) 
#16 /home/theprint/public_html/app/code/core/Mage/Core/Model/Layout.php(209): Mage_Core_Model_Layout->generateBlocks(Object(Mage_Core_Model_Layout_Element)) 
#17 /home/theprint/public_html/app/code/core/Mage/Core/Controller/Varien/Action.php(345): Mage_Core_Model_Layout->generateBlocks() 
#18 /home/theprint/public_html/app/code/core/Mage/Core/Controller/Varien/Action.php(270): Mage_Core_Controller_Varien_Action->generateLayoutBlocks() 
#19 /home/theprint/public_html/app/code/core/Mage/CatalogSearch/controllers/ResultController.php(77): Mage_Core_Controller_Varien_Action->loadLayout() 
#20 /home/theprint/public_html/app/code/core/Mage/Core/Controller/Varien/Action.php(420): Mage_CatalogSearch_ResultController->indexAction() 
#21 /home/theprint/public_html/app/code/core/Mage/Core/Controller/Varien/Router/Standard.php(250): Mage_Core_Controller_Varien_Action->dispatch('index') 
#22 /home/theprint/public_html/app/code/core/Mage/Core/Controller/Varien/Front.php(176): Mage_Core_Controller_Varien_Router_Standard->match(Object(Mage_Core_Controller_Request_Http)) 
#23 /home/theprint/public_html/app/code/core/Mage/Core/Model/App.php(347): Mage_Core_Controller_Varien_Front->dispatch() 
#24 /home/theprint/public_html/app/Mage.php(640): Mage_Core_Model_App->run(Array) 
#25 /home/theprint/public_html/www.theprinterdepo.com/index.php(55): Mage::run('printerdepo', 'website') 
#26 {main} 

Data.php

<?php 
class Mage_CatalogSearch_Helper_Data extends Mage_Core_Helper_Abstract 
{ 
    const QUERY_VAR_NAME = 'q'; 
    const MAX_QUERY_LEN = 200; 

    /** 
    * Query object 
    * 
    * @var Mage_CatalogSearch_Model_Query 
    */ 
    protected $_query; 

    /** 
    * Query string 
    * 
    * @var string 
    */ 
    protected $_queryText; 

    /** 
    * Note messages 
    * 
    * @var array 
    */ 
    protected $_messages = array(); 

    /** 
    * Is a maximum length cut 
    * 
    * @var bool 
    */ 
    protected $_isMaxLength = false; 

    /** 
    * Search engine model 
    * 
    * @var Mage_CatalogSearch_Model_Resource_Fulltext_Engine 
    */ 
    protected $_engine; 

    /** 
    * Retrieve search query parameter name 
    * 
    * @return string 
    */ 
    public function getQueryParamName() 
    { 
     return self::QUERY_VAR_NAME; 
    } 

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

    /** 
    * Is a minimum query length 
    * 
    * @return bool 
    */ 
    public function isMinQueryLength() 
    { 
     if (Mage::helper('core/string')->strlen($this->getQueryText()) < $this->getMinQueryLength()) { 
      return true; 
     } 
     return false; 
    } 

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

       if (Mage::helper('core/string')->strlen($this->_queryText) > $this->getMaxQueryLength()) { 
        $this->_queryText = Mage::helper('core/string')->substr(
         $this->_queryText, 
         0, 
         $this->getMaxQueryLength() 
        ); 
        $this->_isMaxLength = true; 
       } 
      } 
     } 
     return $this->_queryText; 
    } 

    /** 
    * Retrieve HTML escaped search query 
    * 
    * @return string 
    */ 
    public function getEscapedQueryText() 
    { 
     return $this->htmlEscape($this->getQueryText()); 
    } 

    /** 
    * Retrieve suggest collection for query 
    * 
    * @return Mage_CatalogSearch_Model_Resource_Query_Collection 
    */ 
    public function getSuggestCollection() 
    { 
     return $this->getQuery()->getSuggestCollection(); 
    } 

    /** 
    * Retrieve result page url and set "secure" param to avoid confirm 
    * message when we submit form from secure page to unsecure 
    * 
    * @param string $query 
    * @return string 
    */ 
    public function getResultUrl($query = null) 
    { 
     return $this->_getUrl('catalogsearch/result', array(
      '_query' => array(self::QUERY_VAR_NAME => $query), 
      '_secure' => Mage::app()->getFrontController()->getRequest()->isSecure() 
     )); 
    } 

    /** 
    * Retrieve suggest url 
    * 
    * @return string 
    */ 
    public function getSuggestUrl() 
    { 
     return $this->_getUrl('catalogsearch/ajax/suggest', array(
      '_secure' => Mage::app()->getFrontController()->getRequest()->isSecure() 
     )); 
    } 

    /** 
    * Retrieve search term url 
    * 
    * @return string 
    */ 
    public function getSearchTermUrl() 
    { 
     return $this->_getUrl('catalogsearch/term/popular'); 
    } 

    /** 
    * Retrieve advanced search URL 
    * 
    * @return string 
    */ 
    public function getAdvancedSearchUrl() 
    { 
     return $this->_getUrl('catalogsearch/advanced'); 
    } 

    /** 
    * Retrieve minimum query length 
    * 
    * @param mixed $store 
    * @return int 
    */ 
    public function getMinQueryLength($store = null) 
    { 
     return Mage::getStoreConfig(Mage_CatalogSearch_Model_Query::XML_PATH_MIN_QUERY_LENGTH, $store); 
    } 

    /** 
    * Retrieve maximum query length 
    * 
    * @param mixed $store 
    * @return int 
    */ 
    public function getMaxQueryLength($store = null) 
    { 
     return Mage::getStoreConfig(Mage_CatalogSearch_Model_Query::XML_PATH_MAX_QUERY_LENGTH, $store); 
    } 

    /** 
    * Retrieve maximum query words count for like search 
    * 
    * @param mixed $store 
    * @return int 
    */ 
    public function getMaxQueryWords($store = null) 
    { 
     return Mage::getStoreConfig(Mage_CatalogSearch_Model_Query::XML_PATH_MAX_QUERY_WORDS, $store); 
    } 

    /** 
    * Add Note message 
    * 
    * @param string $message 
    * @return Mage_CatalogSearch_Helper_Data 
    */ 
    public function addNoteMessage($message) 
    { 
     $this->_messages[] = $message; 
     return $this; 
    } 

    /** 
    * Set Note messages 
    * 
    * @param array $messages 
    * @return Mage_CatalogSearch_Helper_Data 
    */ 
    public function setNoteMessages(array $messages) 
    { 
     $this->_messages = $messages; 
     return $this; 
    } 

    /** 
    * Retrieve Current Note messages 
    * 
    * @return array 
    */ 
    public function getNoteMessages() 
    { 
     return $this->_messages; 
    } 

    /** 
    * Check query of a warnings 
    * 
    * @param mixed $store 
    * @return Mage_CatalogSearch_Helper_Data 
    */ 
    public function checkNotes($store = null) 
    { 
     if ($this->_isMaxLength) { 
      $this->addNoteMessage($this->__('Maximum Search query length is %s. Your query was cut.', $this->getMaxQueryLength())); 
     } 

     $stringHelper = Mage::helper('core/string'); 
     /* @var $stringHelper Mage_Core_Helper_String */ 

     $searchType = Mage::getStoreConfig(Mage_CatalogSearch_Model_Fulltext::XML_PATH_CATALOG_SEARCH_TYPE); 
     if ($searchType == Mage_CatalogSearch_Model_Fulltext::SEARCH_TYPE_COMBINE || 
      $searchType == Mage_CatalogSearch_Model_Fulltext::SEARCH_TYPE_LIKE) { 

      $wordsFull = $stringHelper->splitWords($this->getQueryText(), true); 
      $wordsLike = $stringHelper->splitWords($this->getQueryText(), true, $this->getMaxQueryWords()); 

      if (count($wordsFull) > count($wordsLike)) { 
       $wordsCut = array_diff($wordsFull, $wordsLike); 

       $wordsCut = array_map(array($this, 'htmlEscape'), $wordsCut); 
       $this->addNoteMessage(
        $this->__('Maximum words count is %1$s. In your search query was cut next part: %2$s.', 
         $this->getMaxQueryWords(), 
         join(' ', $wordsCut) 
        ) 
       ); 
      } 
     } 
    } 

    /** 
    * Join index array to string by separator 
    * Support 2 level array gluing 
    * 
    * @param array $index 
    * @param string $separator 
    * @return string 
    */ 
    public function prepareIndexdata($index, $separator = ' ') 
    { 
     $_index = array(); 
     foreach ($index as $key => $value) { 
      if (!is_array($value)) { 
       $_index[] = $value; 
      } 
      else { 
       $_index = array_merge($_index, $value); 
      } 
     } 
     return join($separator, $_index); 
    } 

    /** 
    * Get current search engine resource model 
    * 
    * @return object 
    */ 
    public function getEngine() 
    { 
     if (!$this->_engine) { 
      $engine = Mage::getStoreConfig('catalog/search/engine'); 

      /** 
      * This needed if there already was saved in configuration some none-default engine 
      * and module of that engine was disabled after that. 
      * Problem is in this engine in database configuration still set. 
      */ 
      if ($engine && Mage::getConfig()->getResourceModelClassName($engine)) { 
       $model = Mage::getResourceSingleton($engine); 
       if ($model && $model->test()) { 
        $this->_engine = $model; 
       } 
      } 
      if (!$this->_engine) { 
       $this->_engine = Mage::getResourceSingleton('catalogsearch/fulltext_engine'); 
      } 
     } 

     return $this->_engine; 
    } 
} 

ResultController.php

<?php 

class Mage_CatalogSearch_ResultController extends Mage_Core_Controller_Front_Action 
{ 
    /** 
    * Retrieve catalog session 
    * 
    * @return Mage_Catalog_Model_Session 
    */ 
    protected function _getSession() 
    { 
     return Mage::getSingleton('catalog/session'); 
    } 
    /** 
    * 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(); 
     } 
    } 
} 
+1

「位置」將在不止一個連接表,所以你需要告訴通過table1.position要使用即哪一個查詢... ORDER ... – 2012-11-08 22:00:32

+0

什麼是查詢什麼樣子的?這個錯誤似乎很清楚,你可能會加入一些表格,並且「位置」出現在多個表格中。 – jeroen

+0

我沒有加入任何東西,這是標準的magento功能,我從不碰magento代碼。 :( –

回答

1

如果您一般不會觸摸Magento代碼,那麼基於修復代碼的答案不會對您有很大幫助。所以我會試圖找到一個不需要直接更正代碼的解決方案。

正如您已經注意到的,在搜索1022(與模型代碼相匹配)後單擊翻新打印機,可以重複此錯誤。但是,也可以通過點擊任何類別進行搜索。

如果你做一個高級搜索它不會發生,如 http://www.theprinterdepox.com/catalogsearch/advanced/result/?name=1022&sku=&price%5Bfrom%5D=&price%5Bto%5D=&free_shipping=&category=100

作爲速戰速決,您可以將問題的URL重定向到高級搜索當量。是的,這有點亂,但它比錯誤信息要好。

我建議你停用這兩個在上面的高級搜索翻了起來,然後又重新啓用,但產品顯示在符合這些產品,其他的搜索優良的產品。

我認爲Magento的唯一原因將無法在一個搜索,而不是另一種是,如果失敗的組合以某種方式緩存。嘗試清除緩存。

+0

我試着清除緩存並重新定向,但它沒有起作用,但是我對重定向感興趣,我怎麼能在magento內做到這一點?或者你是否想用php.ini來做到這一點? –

+0

感謝信息btw –

+0

感謝您的接受。Y您可以從Magento內部重定向,請參閱: http://indiestechtips.wordpress.com/2012/04/21/url-redirection-in-magento/應該可以工作。如果沒有,您需要將規則添加到.htaccess文件中。 –

1

試試這個。

轉到magentoroot /應用/代碼/核心/法師/目錄/型號/ Layer.php

做搜索「公共職能getFilterableAttributes()」

內部的,尋找這些行:

->setAttributeSetFilter($setIds) 
->addStoreLabel(Mage::app()->getStore()->getId()) 
->setOrder('position', 'ASC'); 

更改爲以下:

->setAttributeSetFilter($setIds) 
->addStoreLabel(Mage::app()->getStore()->getId()); 
//->setOrder('position', 'ASC'); 

你會想將其保存在本地文件夾(/ app/code/local/Mage/Catalog/Model)中,以免覆蓋核心Magento文件。 您可能必須清除緩存。

+0

任何想法爲什麼它只發生在特定的搜索字詞而不是其他字符? –

+0

因爲我看到這是一個列名稱衝突。 。可以處理產品類型,是的,但是關鍵字..找不到邏輯解釋,如果你想找到確切的原因,你只需要仔細調試它。順便說一下,我的pos至少給你帶來一些幫助?我不是100%確定它會解決這個問題。 –

+0

它沒有工作,任何想法 –

2

該錯誤指出您的搜索查詢中有多個表的'位置'作爲列名稱。

你應該做的是打印出查詢和分析師。

1-打開文件:/home/theprint/public_html/app/code/core/Mage/Catalog/Model/Resource/Product/Collection.php(線878)
2-從方法getAllIds內側( $ limit = null,$ offset = null)返回語句之前。

 
/* remember to make this output to you only */ 

echo $idsSelect; /* print out the query string */ 

var_dump($this->_bindParams); /* query parameters values */ 
die; 

3-然後將查詢發佈到您的問題。

+0

我這樣做,但我看不到頁面輸出的變化。我也檢查了/ var/reports,並且它顯示了幾乎與它在頁面上顯示的文本相同的文本,而不是打印出的查詢 –

+0

我在頂部看到這個:a:5:{i:0; s:100:「SQLSTATE [23000 ]:完整性約束違規:1052列順序子句中的'位置'不明確「; i:1; s:3600:」#0 /home/theprint/public_html/lib/Varien/Db/Statement/Pdo/Mysql.php 110):Zend_Db_Statement_Pdo - > _執行(陣列) –

+0

順便說一句,當我添加的那些行中,ADMIN目錄,停止工作,我的意思是所述搜索 –

0

我的Magento知識沒有是最好的,我在我的Magento商店1.6.2.0試圖通過一個價格範圍來搜索項,改變順序,和過濾器和工程確定。

,如果你不具有適用修改分層導航的任何分機這是非常奇怪的,你沒有作出任何改變的核心。你使用的是舊的magento版本嗎?如果在您的版本中存在錯誤,您是否檢查了magento bug?

可能是一個失去的時間,但你已嘗試重新索引全部刪除了var /緩存文件?

相關問題