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

?>
4
  • duplicate at stackoverflow.com/questions/19826786/… Commented Dec 1, 2013 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. Commented Dec 1, 2013 at 13:22
  • What about stackoverflow.com/questions/5961290/… Commented Jul 9, 2014 at 9:16
  • Goood example! Thanks! Usually I set - 'source' as custom source model This is more useful Commented Nov 30, 2016 at 19:26

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.