/** * Sort the options based off their position. * * @param array $options * @return array */ protected function _sortOptions($options) { if (count($options)) { if (!$this->_read || !$this->_tbl_eav_attribute_option) { $resource = Mage::getSingleton('core/resource'); $this->_read = $resource->getConnection('core_read'); $this->_tbl_eav_attribute_option = $resource->getTableName('eav_attribute_option'); } // Gather the option_id for all our current options $option_ids = array(); foreach ($options as $option) { $option_ids[] = $option['id']; $var_name = 'option_id_' . $option['id']; ${$var_name} = $option; } $sql = "SELECT `option_id` FROM `{$this->_tbl_eav_attribute_option}` WHERE `option_id` IN('" . implode('\',\'', $option_ids) . "') ORDER BY `sort_order`"; $result = $this->_read->fetchCol($sql); $options = array(); foreach ($result as $option_id) { $var_name = 'option_id_' . $option_id; $options[] = ${$var_name}; } } return $options; }