Magento: export attributes

10,861

Solution 1

Magento doesn't have (that I know of) a competent way to export product attributes with large value lists. If the second machine is a fresh install of Magento (or you don't mind editing a little SQL), I'd offer that you should just dump the database tables for eav_attributes and copy it into the new database.

Hope that helps!

Thanks, Joe

Solution 2

If you create your own custom module, you can use the sql/modulename_setup scripts to import attribute values. The snippet below shows you how the code required for an attribute called "class" being added to an attribute set called "Profiles". You could adapt it to your own attributes and sets. Refer to the wiki for more info.

$iAttributeId = $installer->getAttributeId($iProductEntityTypeId, 'class');
$iSetId = $profileAttrSet = Mage::getModel("eav/entity_attribute_set")
    ->getResourceCollection()
    ->addFieldToFilter("entity_type_id", Mage::getModel('catalog/product')->getResource()->getTypeId())
    ->addFieldToFilter("attribute_set_name", "Profiles")
    ->getFirstItem()
    ->getId();
$installer->addAttributeToSet($iProductEntityTypeId,$iSetId,'General',$iAttributeId);

$aClasses = array('TV','DVD','Home Theatre','Air Conditioner','Stereo/Hifi','Game Console','Camcorder','VCR','Set Top Box','PVR');
$aOption = array();
$aOption['attribute_id'] = $iAttributeId;

for($iCount=0;$iCount<sizeof($aClasses);$iCount++){
    $aOption['value']['option'.$iCount][0] = $aClasses[$iCount];
}
$installer->addAttributeOption($aOption);

You could use the eav/entity_attribute API to extract the values then populate your array above.

HTH,
JD

Share:
10,861
whostolemyhat
Author by

whostolemyhat

Full-stack web development, including Javascript, HTML/CSS, PHP and Python. iOS and Android app development. Twitter: http://twitter.com/whostolemyhat

Updated on June 04, 2022

Comments

  • whostolemyhat
    whostolemyhat almost 2 years

    Is there any way of exporting attributes from Magento? I have dropdown attributes with a couple of hundred of options each, and need to transfer them to another Magento installation. I've found instructions on how to import attributes from CSV, but have had no luck with exporting so far.