简体   繁体   English

违反完整性约束:1052 order子句中的“位置”列不明确

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

One of my users sent me this link from our own magento website. 我的一位用户从我们自己的magento网站向我发送了此链接。 And we have this exception, any idea how can I fix this? 而且我们有这个例外,任何想法我该如何解决?

http://www.theprinterdepox.com/catalogsearch/result/index/?cat=100&q=1022&x=0&y=0 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 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 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();
        }
    }
}

The error states that there are more than one table in your search query that has 'position' as a column name. 该错误表明您的搜索查询中有多个表以“ position”作为列名。

What you should do is to print out the query and analyst. 您应该做的是打印出查询和分析师。

1- Open the file: /home/theprint/public_html/app/code/core/Mage/Catalog/Model/Resource/Product/Collection.php ( line 878) 1-打开文件:/home/theprint/public_html/app/code/core/Mage/Catalog/Model/Resource/Product/Collection.php(第878行)
2- From inside the method getAllIds($limit = null, $offset = null) before the return statement. 2-从return语句之前的方法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- Then post the query into your question. 3-然后将查询发布到您的问题中。

Try this. 尝试这个。

Go to magentoroot/app/code/core/Mage/Catalogue/Model/Layer.php 转到magentoroot / app / code / core / Mage / Catalogue / Model / Layer.php

Do a search for “public function getFilterableAttributes()” 搜索“ public function getFilterableAttributes()”

Inside that, look for these lines: 在其中寻找以下行:

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

Change to the following: 更改为以下内容:

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

You'll want to save this and place it in your local folder (/app/code/local/Mage/Catalog/Model) so it doesn't overwrite core Magento files. 您需要保存该文件并将其放置在本地文件夹(/ app / code / local / Mage / Catalog / Model)中,以免覆盖Magento核心文件。 You may have to clear cache. 您可能需要清除缓存。

If you don't generally touch the Magento code, then an answer based around fixing the code is not going to help you greatly. 如果您通常不触摸Magento代码,那么基于修复代码的答案将不会对您有很大帮助。 So I'm going to attempt to find you a solution that does not require directly correcting the code. 因此,我将尝试为您找到不需要直接更正代码的解决方案。

As you have noticed, the error can be repeated by clicking Refurbished Printers after a search for 1022 (which matches a model code). 如您所注意到的,在搜索1022(与型号代码匹配)之后,单击“翻新打印机”可以重复出现此错误。 It also appears however by clicking any category with this search. 但是,也可以通过单击此搜索中的任何类别来显示。

It does not happen if you do an advanced search, eg http://www.theprinterdepox.com/catalogsearch/advanced/result/?name=1022&sku=&price%5Bfrom%5D=&price%5Bto%5D=&free_shipping=&category=100 如果您进行高级搜索,例如http://www.theprinterdepox.com/catalogsearch/advanced/result/?name=1022&sku=&price%5Bfrom%5D=&price%5Bto%5D=&free_shipping=&category=100 ,则不会发生这种情况

As a quick fix, you could redirect the problem URLs to equivalents in Advanced Search. 作为快速解决方案,您可以将问题URL重定向到“高级搜索”中的等效URL。 Yes, that's a little messy, but it's better than an error message. 是的,这有点混乱,但是比错误消息要好。

I would suggest that you deactivate both the products that turn up in the above Advanced Search, and then reactivate them in turn, but the products show up fine in other searches that match these products. 我建议您停用上述高级搜索中出现的两种产品,然后依次将它们重新激活,但是在与这些产品匹配的其他搜索中,这些产品显示得很好。

The only reason I can think of that Magento would fail on one search and not another is if the failing combination is cached in some way. 我能想到的是,Magento一次搜索就会失败,而并非另一次失败,是因为失败的组合是以某种方式缓存的。 Try clearing your cache. 尝试清除缓存。

my magento knowledge no is the best, I was tried in my magento store 1.6.2.0 to search a term, change the order, and filter by a price range and works ok. 我的magento知识不是最好,我曾在我的magento商店1.6.2.0中进行过尝试,以搜索术语,更改顺序并按价格范围进行过滤,然后可以正常工作。

it's very strange if you don't have any extension that apply modifications to the layered navigation and you don't made any core changes. 如果您没有任何将修改应用于分层导航的扩展并且没有进行任何核心更改,这将非常奇怪。 Are you using an old magento version? 您使用的是旧的magento版本吗? you was checked in the magento bugs if is a bug in your version? 您是否已通过magento错误检查,如果您的版本中存在错误?

probably is a lose of time, but you was tried to reindex all and delete the var/cache files? 可能是浪费时间,但是您试图重新建立所有索引并删除var / cache文件?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 完整性约束违规:1052 order order子句中的列&#39;position&#39;不明确(PHP,MySQL) - Integrity constraint violation: 1052 Column 'position' in order clause is ambiguous (PHP, MySQL) 完整性约束违规:1052 where子句中的列&#39;id&#39;不明确 - Integrity constraint violation: 1052 Column 'id' in where clause is ambiguous Laravel 完整性约束违规:1052 列 'id' in where 子句不明确 - Laravel Integrity constraint violation: 1052 Column 'id' in where clause is ambiguous SQLSTATE [23000]:完整性约束违规:1052 order order中的&#39;created_at&#39;列不明确Laravel 5.5 - SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'created_at' in order clause is ambiguous Laravel 5.5 Yii2 GridView:SQLSTATE[23000]:违反完整性约束:1052 order 子句中的列“id”不明确 - Yii2 GridView: SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'id' in order clause is ambiguous SQLSTATE [23000]:完整性约束违规:1052 列“created_at”在 order 子句中不明确 Laravel 8 - SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'created_at' in order clause is ambiguous Laravel 8 违反完整性约束:1052 where子句不明确的列&#39;prof_id&#39;Laravel - Integrity constraint violation: 1052 Column 'prof_id' in where clause is ambiguous Laravel Laravel Eloquent:违反完整性约束:where 子句中的 1052 列“id”不明确 - Laravel Eloquent: Integrity constraint violation: 1052 Column 'id' in where clause is ambiguous 如何解决完整性约束违规:1052 列 &#39;id&#39; in where 子句在 laravel 中不明确 - How to solve Integrity constraint violation: 1052 Column 'id' in where clause is ambiguous in laravel SQLSTATE [23000]:违反完整性约束:1052 where 子句中的列“值”不明确 - SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'value' in where clause is ambiguous
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM