Magento custom customer dropdown attribute not populated

1.9k views Asked by At

I have created a custom Customer attribute, called Hairtype. Its a drop down select box, but it doesnt get populated with the Options i define in my install script.

Can anyone help me out?

config.xml:

<?xml version="1.0" encoding="UTF-8" ?>
<config>    
    <modules>
        <Ezzence_Clinic>
            <version>0.1.0</version>
        </Ezzence_Clinic>
    </modules>
    <global>
        <resources>
            <clinic_setup>
                <setup>
                    <module>Ezzence_Clinic</module>
                    <class>Ezzence_Clinic_Model_Resource_Mysql4_Setup</class>
                </setup>
            </clinic_setup>
        </resources>
    </global>
</config>  

setup.php:

<?php
    class Ezzence_Clinic_Model_Resource_Mysql4_Setup extends Mage_Eav_Model_Entity_Setup{

        /**
         * This method returns true if the attribute exists.
         * 
         * @param string|int $entityTypeId
         * @param string|int $attributeId
         * @return bool
         */
        public function attributeExists($entityTypeId, $attributeId){
            try{
                $entityTypeId = $this->getEntityTypeId($entityTypeId);
                $attributeId = $this->getAttributeId($entityTypeId, $attributeId);
                return !empty($attributeId);
            } catch(Exception $e){
                return FALSE;
            }
        }

    }

?>

mysql4-install-0.1.0.php:

<?php

    $this->startSetup();

    /* Get the customer entity type Id */
    $entity = $this->getEntityTypeId('customer');
    $attributeSetId   = $this->getDefaultAttributeSetId($entity);
    $attributeGroupId = $this->getDefaultAttributeGroupId($entity, $attributeSetId);

    /* If the attribute exists */
    if(!$this->attributeExists($entity, 'hairtype')) 
    {
        /* delete it */
        $this->removeAttribute($entity, 'hairtype');
    }

    $this->addAttribute('customer', 'hairtype', array(
    'input'         => 'select',
    'type'          => 'varchar',
    'position'      => 1,
    'option'        => array(
                'value' => array(
                                'optionone' => 'normal hud',
                                'optiontwo' => 'tør hud',
                                'optionthree' => 'fedtet hud',
                                'optionfour' => 'kombineret hud',
                                'optionfive' => 'sensibel hud'
                            )), 
    'default'       => 'normal hud',
    'label'         => 'Hairtype',
    'source' => 'eav/entity_attribute_source_table',
    'visible'       => 1,
    'required'      => 0,
    'user_defined' => 1,
    ));


    /* create the new attribute 
    $this->addAttribute($entity, 'hairtype', array(
            'type' => 'text',           
            'label' => 'Hairtype',
            'input' => 'text',          
            'visible' => 1,         
            'required' => 0,    
            'user_defined' => 1,
            'default_value' => 'default'    
    ));
    */


    $attribute = Mage::getSingleton('eav/config')->getAttribute($this->getEntityTypeId('customer'), 'hairtype');
    $attribute->setData('used_in_forms', array('customer_account_edit', 'customer_account_create', 'adminhtml_customer', 'checkout_register'));
    $attribute->save(); 

    /* save the setup */
    $this->endSetup();

?>
0

There are 0 answers