-
-
Save LeeSaferite/6764209 to your computer and use it in GitHub Desktop.
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
<?php | |
class EcomDev_Optimization_Model_Resource_Attribute_Source_Table extends Mage_Eav_Model_Entity_Attribute_Source_Table | |
{ | |
protected static $_preloadedOptions = array(); | |
protected static function _getStoreOptions($storeId, $attributeId) | |
{ | |
if (!isset(self::$_preloadedOptions[$storeId])) { | |
$options = Mage::getResourceModel('eav/entity_attribute_option_collection') | |
->setPositionOrder('asc') | |
->setStoreFilter($storeId) | |
->getData(); | |
foreach ($options as $option) { | |
self::$_preloadedOptions[$storeId][$option['attribute_id']]['default'][] = array( | |
'value' => $option['option_id'], | |
'label' => $option['value'] | |
); | |
self::$_preloadedOptions[$storeId][$option['attribute_id']]['store'][] = array( | |
'value' => $option['option_id'], | |
'label' => $option['default_value'] | |
); | |
} | |
} | |
if (isset(self::$_preloadedOptions[$storeId][$attributeId])) { | |
return self::$_preloadedOptions[$storeId][$attributeId]; | |
} | |
return array( | |
'default' => array(), | |
'store' => array() | |
); | |
} | |
public function getAllOptions($withEmpty = true, $defaultValues = false) | |
{ | |
$storeId = $this->getAttribute()->getStoreId(); | |
if (!is_array($this->_options)) { | |
$this->_options = array(); | |
} | |
if (!is_array($this->_optionsDefault)) { | |
$this->_optionsDefault = array(); | |
} | |
if (!isset($this->_options[$storeId])) { | |
$options = self::_getStoreOptions($storeId, $this->getAttribute()->getId()); | |
$this->_options[$storeId] = $options['store']; | |
$this->_optionsDefault[$storeId] = $options['default']; | |
} | |
$options = ($defaultValues ? $this->_optionsDefault[$storeId] : $this->_options[$storeId]); | |
if ($withEmpty) { | |
array_unshift($options, array('label' => '', 'value' => '')); | |
} | |
return $options; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment