Magento 1.9 Database – Add Data into Database in Magento 1.9

ce-1.9.0.1magento-1.8magento-1.9magento-enterprise

I want to add new column into magento database and want to insert new data into newly created column. Basically what exact i want to do is that when new customer register in my webstore. i want to generate a temporary account number when customer click on register button. on the next page this number will be appear written as temporary account number is = ……. for this purpose i think i need to create a new column in database to store the temporary account number.

Best Answer

The customer data is based on EAV, this means you'll need to add an attribute to the attribute set instead of a table column.

There are a couple of tutorials on that, check out this one and this one. It comes down to creating your own module with an install script that has something like this

$installer = $this;
$installer->startSetup();

$installer->addAttribute('customer', 'temp_id', array(
    'type' => 'varchar',
    'input' => 'text',
    'label' => 'Temporary ID',
    'global' => 1,
    'visible' => 1,
    'required' => 0,
    'user_defined' => 0,
    'default' => '',
    'visible_on_front' => 0,
    'source' => NULL,
));

$installer->endSetup();

config.xml

<default>
    ...
    <resources>
        <your_module_identifier>
            <setup>
                <module>Your_ModuleName</module>
                <class>Mage_Customer_Model_Resource_Setup</class>
            </setup>
        </your_module_identifier >
    </resources>
    ...
</default>