herveguetin
4/7/2014 - 2:55 PM

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

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;
    }
}