cancel
Showing results for 
Search instead for 
Did you mean: 

Unique nickname on Customer data

Unique nickname on Customer data

hi there all  Smiley Very Happy

 

i need a UNIQUE Nickname Field in custumers ... and i found this code on internet ....  

 

//define('MAGENTO', realpath('path_donde_este_instalado_magento'));
define('MAGENTO', realpath(dirname(__FILE__)));

ini_set('memory_limit', '128M');
 
require_once MAGENTO.'/app/Mage.php';
umask(0);
Mage::app();
 
$setup = new Mage_Eav_Model_Entity_Setup('core_setup');
$setup->startSetup();
 
$entityTypeId     = $setup->getEntityTypeId('customer');
$attributeSetId   = $setup->getDefaultAttributeSetId($entityTypeId);
$attributeGroupId = $setup->getDefaultAttributeGroupId($entityTypeId, $attributeSetId);
 
$setup->addAttribute('customer', 'nickname', array(
    'input'         => 'text',
    'type'          => 'text',
    'label'         => 'Nickname',
    'visible'       => 1,
    'required'      => 1,
    'user_defined'  => 1,
    'admin_html'    => 1,
    'unique'        => 1
));
 
$setup->addAttributeToGroup(
    $entityTypeId,
    $attributeSetId,
    $attributeGroupId,
    'nickname',
    '1000'  //sort_order
);
 
$oAttribute = Mage::getSingleton('eav/config')->getAttribute('customer', 'nickname');
$oAttribute->setData('used_in_forms', array('adminhtml_customer'));
$oAttribute->save();

 

i put my codes in REGISTER.phtml  and EDIT.phtml ... 

 

this works perfect.. but when i go to register a new user ..

 

1.- the field dont save anything in my database --- same in EDIT.phtml when the user is already registered.

 

2.- in my admin panel ... in custumer -> clients -> acount information..  the NICKNAME appear .. but when i save one NICKNAME then go to other customer ...  and put the SAME NICKNAME... the record its saved and no message of other client with the same NICKNAME is showed!!!!

 

 

with this code i have this TABLE in my DB "customer_entity_varchar" ... 

 

how can i make this field UNIQUE in mysql ... and get a error message in FRONTEND and BACKEND?