1

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();

?>
Teilmann
  • 2,146
  • 7
  • 28
  • 57
  • duplicate at http://stackoverflow.com/questions/19826786/cant-save-multiselect-attribute-on-magento/19830674 – Deependra Singh Dec 01 '13 at 13:21
  • 2
    Ehm, this is not the same problem as the one you posted. if you would actually read the question you posted, the answer to it was, that the type was wrong. Mine is not. – Teilmann Dec 01 '13 at 13:22
  • What about http://stackoverflow.com/questions/5961290/adding-attributes-to-customer-entity – Meetai.com Jul 09 '14 at 09:16
  • Goood example! Thanks! Usually I set - 'source' as custom source model This is more useful – Alex Nov 30 '16 at 19:26

0 Answers0