Integrity constraint violation: 1052 Column ‘position’ in order clause is ambiguous

Tuesday, 30. August 2011

This is a small bug on core file located here:

~/app/code/core/Mage/Catalog/Model/Layer.php

The error will usually happen when you perform a simple search on your Magento site. To locate and fix the bug do the following:

Search for method getFilterableAttributes() and look for something relating to the code below.

public function getFilterableAttributes() {
....
        $collection->getSelect()->distinct(true);
        $collection
            ->setAttributeSetFilter($setIds)
            ->addStoreLabel(Mage::app()->getStore()->getId())
            ->setOrder('position', 'ASC');
.....
}

The setOrder needs to look something like code below:

public function getFilterableAttributes() {
....
        $collection->getSelect()->distinct(true);
        $collection
            ->setAttributeSetFilter($setIds)
            ->addStoreLabel(Mage::app()->getStore()->getId())
            ->setOrder('main_table.position', 'ASC');
.....
}

NOTE

I would NEVER recommend you edit core files directly. If you can not create a custom extension to override this method you should at least copy and edit this file in your local Mage folder.

So you should have something like:

~/app/code/local/Mage/Catalog/Model/Layer.php

Then do the changes here as explained above.

Leave a Reply

You must be logged in to post a comment.