Created
November 15, 2012 23:41
-
-
Save colinmollenhour/4082426 to your computer and use it in GitHub Desktop.
Fix Magento product list sort order for 'select' type attributes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- a/app/code/core/Mage/Catalog/Block/Product/List.php | |
+++ b/app/code/core/Mage/Catalog/Block/Product/List.php | |
@@ -157,6 +157,19 @@ class Mage_Catalog_Block_Product_List extends Mage_Catalog_Block_Product_Abstrac | |
// set collection to tollbar and apply sort | |
$toolbar->setCollection($collection); | |
+ // Redo order to sort based on attribute label sort order | |
+ if ($order = $toolbar->getCurrentOrder()) { | |
+ $eavConfig = Mage::getSingleton('eav/config'); /* @var $eavConfig Mage_Eav_Model_Config */ | |
+ $attribute = $eavConfig->getAttribute('catalog_product', $order); | |
+ if ($attribute && $attribute->getFrontendInput() == 'select' && $attribute->getSourceModel() == 'eav/entity_attribute_source_table') { | |
+ $collection->getSelect()->reset(Zend_Db_Select::ORDER); | |
+ $dir = strtoupper($toolbar->getCurrentDirection()); | |
+ $collection->getSelect() | |
+ ->joinLeft('eav_attribute_option AS eao', "eao.option_id=IF({$order}_t2.value_id > 0, {$order}_t2.value, {$order}_t1.value)", array()) | |
+ ->order(new Zend_Db_Expr('eao.sort_order '.$dir)); | |
+ } | |
+ } | |
+ | |
$this->setChild('toolbar', $toolbar); | |
Mage::dispatchEvent('catalog_block_product_list_collection', array( | |
'collection' => $this->_getProductCollection() |
Hey,
Any update to the above? when I apply the patch and try to sort everything just hangs.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi, Mate. Thanks for the patch.
Just checking your solution - but am receiving an SQL error.
Where does this come from: {$order}_t2?
The *_t2 table?
Thanks.