1

I am adding attribute by updating sql script, like this,

$installer = $this;
$installer->startSetup();
$installer->addAttribute('customer_address', 'group_id', array(
'label'        => 'Address group',
'visible'      => true,
'required'     => false,
'type'         => 'int',
'input' => 'select',
'source' => 'address_group/address_attribute_source_group',
'user_defined' => 1,
'position'  => 100
));

.
.
.
$installer->endSetup();

I am unable to understand what is meant by following line, I am unable to find any explanation about it

'source' => 'address_group/address_attribute_source_group',

2 Answers 2

1

I am unable to comment on your post. Trying to understand if you have copied this code from somewhere. From your code I understand that you want to add a "Customer Address Attribute" named as "customer_address"

'source' => 'address_group/address_attribute_source_group'

The implication of the above is the path. You should have a folder/file path as below:

/app/code/local/Address/Group/Model/Address/Attribute/Source/Group.php

Group.php: class Address_Group_Model_Address_Attribute_Source_Group ...

Since, this attribute is of TYPE => "SELECT", you should be having the options array in this file "Group.php"

Options Array should be something very similar to:

public function toOptionsArray() {
    
    return array(
        array(
            'label' => '',
            'value' => ''
        ),
        array(
            'label' => Yes,
            'value' => 1
        ),
        array(
            'label' => No,
            'value' => 0
        )
    );
}

Let me know if you got it!

Happy to Help!

Happy Coding...

Sign up to request clarification or add additional context in comments.

5 Comments

I got it, but my class is Like this,'class Address_Group_Model_Address_Attribute_Source_Group extends Mage_Eav_Model_Entity_Attribute_Source_Table { }'
And 'Mage_Eav_Model_Entity_Attribute_Source_Table' have nothing like toOptionsArray()
You will have to create this function in Group.php with your values in that.
Because Mage_Eav_Model_Entity_Attribute_Source_Table uses database table where it keeps all options added by admin in the attribute configuration form. It uses getAllOptions to fetch them.
agreed with Zefiryn.. You can choose to use XML to add your values similar to default magento. However, DO NOT update the CORE files directly.
1

It points to the class that provides options for the attribute. As attribute uses select input it requires options to be provided. This class is created by calling Mage::getModel() and passing the value of source to it. To find the class you need to find node models/address_group in config.xml files of the available modules. This will provide class prefix. Next what comes after slash is added to that prefix in order to create class name. So in this case it will resolve to something like Company_AddressGroupModule_Model_Address_Attribute_Source_Group. This class need to implement toOptionsArray method that returns an array in the following format:

array(
    array('value' =>  'option_value', 'label' => 'option_label'),
    ...
);

1 Comment

I got it, can see my comments given bellow

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.