Skip to content

Instantly share code, notes, and snippets.

@LeeSaferite
Forked from IvanChepurnyi/Table.php
Created September 30, 2013 13:57
Show Gist options
  • Save LeeSaferite/6764209 to your computer and use it in GitHub Desktop.
Save LeeSaferite/6764209 to your computer and use it in GitHub Desktop.
<?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