开发者

Magento: export attributes

开发者 https://www.devze.com 2023-02-16 19:10 出处:网络
Is there any way of exporting attributes from Magento? I have dropdown attrib开发者_开发百科utes with a couple of hundred of options each, and need to transfer them to another Magento installation. I\

Is there any way of exporting attributes from Magento? I have dropdown attrib开发者_开发百科utes 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.


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


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


You may also want to take a look at Unirgy's uRapidFlow.


This might help someone one day... This SQL will grab the table values for an EAV Attribute. This example is grabbing all the values for the attribute code of 'color'

SELECT v.* FROM eav_attribute AS a
JOIN eav_attribute_option AS o ON a.attribute_id = o.attribute_id
JOIN eav_attribute_option_value AS v ON o.option_id = v.option_id
WHERE a.attribute_code = 'color';

Just make sure that if you are going to use SQL to upload values back into the eav_attribute_option_value table that you first check if the value for that attribute already exists and that you don't specify the value_id as that is an auto-increment value.

0

精彩评论

暂无评论...
验证码 换一张
取 消