Magento – Programmatically create new attribute set while inheriting from another

attributesmagento-1.7

I am programmatically creating attributes and attribute sets. The attributes work like they should, but with the attribute sets I have a problem.

When I create an attribute set, I can not let it inherit from another set (for example the default set). I have searched a lot but could not find any good info that could help me further.

My first thought there should be some function that lets you duplicate a set and edit it. I could not find it.

My second thought was recreating the whole set, but I could not find a function to get the groups from an attribute set, which I do want.

I'm pretty new to Magento, so sorry if I just missed something, but I am currently stuck. Any solutions / suggestions will be greatly appreciated.

Best Answer

After trying out again, messing up a lot and finally finding the correct answer, this works:

$entityTypeId = Mage::getModel('catalog/product')
                  ->getResource()
                  ->getEntityType()
                  ->getId(); //product entity type

$attributeSet = Mage::getModel('eav/entity_attribute_set')
                  ->setEntityTypeId($entityTypeId)
                  ->setAttributeSetName("test_set");

$attributeSet->validate();
$attributeSet->save();

$attributeSet->initFromSkeleton($entityTypeId)->save();

You need to save before you do initFromSekeleton(). Otherwise it just won't work.

Related Topic