Skip to content

Instantly share code, notes, and snippets.

@herveguetin
Last active August 29, 2015 13:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save herveguetin/10021882 to your computer and use it in GitHub Desktop.
Save herveguetin/10021882 to your computer and use it in GitHub Desktop.
Save an attribute with a select input type with values that are not of "int" type and create correct column type in flat catalog tables (in Magento)
<?php
class Your_Module_Model_Catalog_Attribute_Source_Product_[Attribute] extends Mage_Eav_Model_Entity_Attribute_Source_Table
{
public function getAllOptions()
{
if (!$this->_options) {
$this->_options = array(
'option_1' => array('value' => 'value_1', 'label' => Mage::helper('adminhtml')->__('-- Not Selected --')),
'option_2' => array('value' => 'value_2', 'label' => 'Label 2'),
'option_3' => array('value' => 'value_3', 'label' => 'Label 3'),
);
}
return $this->_options;
}
/**
* Update column type in order to use varchar for main column
*
* @return array
*/
public function getFlatColums()
{
$columns = parent::getFlatColums(); // We get columns as generated by Magento
// We force flat column type
if (Mage::helper('core')->useDbCompatibleMode()) {
$columns[$this->getAttribute()->getAttributeCode()]['type'] = 'varchar(255)';
}
else {
$columns[$this->getAttribute()->getAttributeCode()]['type'] = Varien_Db_Ddl_Table::TYPE_TEXT;
}
return $columns;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment