cancel
Showing results for 
Search instead for 
Did you mean: 

New column in customer table storing and getting data

New column in customer table storing and getting data

Hi,

I have added new column in customer table using below magento way on 1.9

$installer = $this;
$installer->startSetup();
$setup = Mage::getModel('customer/entity_setup', 'core_setup');
$setup->addAttribute('customer', 'my_column', array(
'type' => 'varchar',
'input' => 'text',
'label' => 'my_column',
'global' => 1,
'visible' => 0,
'required' => 0,
'user_defined' => 1,
'visible_on_front' => 0,
));
$installer->endSetup();

Below method I think not working to set and get data from database.

 

$customer->setMycolumn($requestData['my_column']);
$customer->getMycolumn();

I can see entries in "eav_attribute","customer_eav_attribute" and "eav_entity_attribute" table for new column.

But how to check data inserted in table in database, which table holds the data.

Any idea?

 

-Thanks

2 REPLIES 2

Re: New column in customer table storing and getting data

Hi

You just create attribute in eav_attribute table.Can you tell me your exact requirement in detail

Get attribute value:- $_customer->getData('my_column');

Ref:-

http://chandanpatra.blogspot.in/2014/12/how-to-add-custom-attribute-to-customer.html

 

Re: New column in customer table storing and getting data

Hi,

 

I am able to get and set data using getData and setData method.

Suppose I want to get the data for custom attribute , how to achieve  this?

 

I want to check if my_column has value then execute some code else other code similar to getID method of customer. 

 

Below giving me big array of data.

 

 

$result = Mage::getModel('customer/customer')
    ->getCollection()
    ->addAttributeToFilter('my_column',$requestData['my_column']);

$result = Mage::getModel('customer/customer')->getCollection()->addFieldToFilter('my_column')->load();
// $customer=Mage::getModel('customer/customer')->getCollection()->addFieldToFilter('email', 'myemail@gmail.com')->load();
// $customer->load($requestData['my_column'], 'my_column');
//$products =  Mage::getModel('customer/customer')->loadByAttribute('my_column', '123456');

$customer = Mage::getModel('customer/customer')
    ->getAttribute('my_column')
    ->getSource()
    ->getOptionId('123456');

echo"<br>Customer".$customer->getId();


// $customer = $this->loadByAttribute("loadByAttribute", "123456");

echo"<pre>";
//print_r($products);
echo"</pre>";


if (is_object($result)) {
    /* Logic */
    echo"Yes";

    echo"<pre>";
   //print_r($result);
    echo"</pre>";

} else {
    echo"No";
}
}

 

Any idea?

 

-Thanks