Monday, 9 September 2013

Adding attributes to user entity via. install script

Adding attributes to user entity via. install script

I recently got a new internship, where i have to programme with Magento,
which i have never tried before. A part of my current assignment is to add
some extra attributes to our customer entity, which will then show in the
back-end.
At this point i have managed to add an attribute, which is a textfield in
the back-end, but what i really want to do, is to add a select box with
predefined options. Whenever i try to do that, my Magento goes corrupt, to
the point where i have to reinstall the whole thing. I am running my head
against the wall at the moment.
I am doing this via. an install script, from a module i created.
Below i have pasted in my install script, but if you need to see more
code, please let me know.
mysql4-install-0.1.0.php:
<?php
$installer = $this;
$installer->startSetup();
$setup = new Mage_Eav_Model_Entity_Setup('core_setup');
$entityTypeId = $setup->getEntityTypeId('customer');
$attributeSetId = $setup->getDefaultAttributeSetId($entityTypeId);
$attributeGroupId = $setup->getDefaultAttributeGroupId($entityTypeId,
$attributeSetId);
$setup->addAttribute('customer', 'skintype', array(
'input' => 'select',
'type' => 'varchar',
'option' => array(
'optionone' => array('zero' => array(0 =>
'normal hud')),
'optiontwo' => array('one' => array(1 =>
'tør hud')),
'optionthree' => array('two' => array(2 =>
'fedtet hud')),
'optionfour' => array('three' => array(3
=> 'kombineret hud')),
'optionfive' => array('four' => array(4 =>
'sensibel hud'))
),
'default' => array('optionone'),
'label' => 'Skintype',
'visible' => 1,
'required' => 0,
'user_defined' => 1,
));
$oAttribute = Mage::getSingleton('eav/config')->getAttribute('customer',
'skintype');
$oAttribute->setData('used_in_forms', array('adminhtml_customer'));
$oAttribute->save();
$setup->endSetup();
?>

No comments:

Post a Comment