I have many product custom attributes all have same type dropdown for brand like


They have lot of options. i want to make a new attribute name product_brand and want to merge all above attribute options in it is there any way in magento to do this programmatically. I have searched alot but didn't find any solution.

1 Answer 1


I have solved this issue its not the best way but it fixed my issue may be it helps someone as well so what i have done i made a function that is fetching all the options of brand attributes in my project

public function mergeAttributeOtionsAction(){
    $brands = array();
    $attSet = Mage::getModel('eav/entity_type')->getCollection()->addFieldToFilter('entity_type_code','catalog_product')->getFirstItem(); // This is because the you adding the attribute to catalog_products entity ( there is different entities in magento ex : catalog_category, order,invoice... etc ) 
    $attSetCollection = Mage::getModel('eav/entity_type')->load($attSet->getId())->getAttributeSetCollection(); // this is the attribute sets associated with this entity 
  foreach ($attSetCollection as $a)
        if(preg_match('/cosmetic/i', $a->getAttributeSetName())){
            $set = Mage::getModel('eav/entity_attribute_set')->load($a->getId());
            $setId = $set->getId();
            $atrr_ = Mage::getModel('catalog/product_attribute_api')->items($setId);
            foreach($atrr_ as $atrr){

                $attribute = Mage::getModel('eav/config')->getAttribute('catalog_product',$atrr['code']);
                if(preg_match('/brand/i', $attribute->getFrontendLabel())){
                    $options = $attribute->getSource()->getAllOptions();
                    foreach ($options as $option){
                        if($option['label'] == 'Not Specified'){
                        $brands[] = $option['label'];
    echo '<pre>'; var_dump(implode(',', $brands));echo '</pre>';
    foreach ($brands as $brand){
        echo $brand; echo '<br>';


the next step is to make an excel file in this format enter image description here

than goto admin > system > import/export > DataFlow - Advanced Profiles Add new Profile enter name like "Import Product Attributes" and add this XML and save

<action type="dataflow/convert_adapter_io" method="load">
<var name="type">file</var>
<var name="path">datafiles/import</var>
<var name="filename"><![CDATA[import_product_attributes.csv]]></var>
<var name="format"><![CDATA[csv]]></var>

<action type="dataflow/convert_parser_csv" method="parse">
<var name="delimiter"><![CDATA[;]]></var>
<var name="enclose"><![CDATA["]]></var>
<var name="fieldnames">true</var>
<var name="store"><![CDATA[0]]></var>
<var name="number_of_records">1</var>
<var name="adapter">importexportattributes/convert_adapter_product_attribute</var>

Now create a folder on magento root folder name datafiles inside this folder create another >import than place that XML file here that you have created above.

Now goto admin > system > import/export > DataFlow - Advanced Profiles open "Import Product Attributes" than click on Run Profile tab and click on run profile button. That's it now you have new attribute with name and code that you have enter in your file with all brands options that exists in magento.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.