Last active
August 29, 2015 14:00
-
-
Save herveguetin/11228111 to your computer and use it in GitHub Desktop.
Bugfix - Make sure to sort filter options by sort order set in Magento attribute option edit
This file contains 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
<?php | |
/** | |
* @return array | |
*/ | |
public function getAllFilterableOptionsAsHash() | |
{ | |
if (is_null($this->_optionsHash)) { | |
$hash = array(); | |
$attributes = $this->getFilterableAttributes(); | |
/* @var $helper Amasty_Shopby_Helper_Url */ | |
$helper = Mage::helper('amshopby/url'); | |
$options = $this->getAllOptions(); | |
foreach ($attributes as $a){ | |
$code = $a->getAttributeCode(); | |
$code = str_replace(array('_', '-'), Mage::getStoreConfig('amshopby/seo/special_char'), $code); | |
$hash[$code] = array(); | |
foreach ($options as $o){ | |
if ($o['value'] && $o['attribute_id'] == $a->getId()) { // skip first empty | |
$unKey = $helper->createKey($o['value']); | |
while(isset($hash[$code][$unKey])){ | |
$unKey .= '_'; | |
} | |
// Hervé Guétin --> Bugfix - Make sure options are sorted by position set in admin | |
//$hash[$code][$unKey] = $o['option_id']; | |
$hash[$code][$unKey] = array('option_id' => $o['option_id'], 'sort_order' => $o['sort_order']); | |
// [end] Hervé Guétin | |
/* | |
* Keep original label for further use | |
*/ | |
$this->_optionsLabels[$o['option_id']] = $o['value']; | |
} | |
} | |
} | |
// Hervé Guétin --> Bugfix - Make sure options are sorted by position set in admin | |
//$this->_optionsHash = $hash; | |
$newHash = array(); | |
foreach($hash as $attributeCode => $hash) { | |
uasort($hash, function($a, $b) { | |
if ($a['sort_order'] == $b['sort_order']) return 0; | |
return ($a['sort_order'] > $b['sort_order'] ? 1 : -1); | |
}); | |
foreach($hash as $optionLabel => $option) { | |
$newHash[$attributeCode][$optionLabel] = $option['option_id']; | |
} | |
} | |
$this->_optionsHash = $newHash; | |
// [end] Hervé Guétin | |
} | |
return $this->_optionsHash; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment