tags:

views:

47

answers:

1

Ok, its possible to add a new attribute set in magento using something like the following:

$entitySetup = new Mage_Eav_Model_Entity_Setup;
$entitySetup->addAttributeSet('catalog_product', $setName);

But how can i base the set on an existing set like the default. This option is available in the admin section so its possible.

A: 

I did this 6 months ago, I do not have the code anymore, but I know you have to use the initFromSkeleton() method on your attribute set. You can search Magento's code for calls to this function, there are very few calls (just one perhaps). It will show you its usage.

EDIT: I remember I had the very same problem you are talking about, and I mailed about it. Here is the usage I was advised:

$attrSet = Mage::getModel('eav/entity_attribute_set');
$attrSet->setAttributeSetName('MyAttributeSet');
$attrSet->setEntityTypeId(4);//You can look into the db what '4' corresponds to, I think it is for products.
$attrSet->initFromSkeleton($attrSetId);
$attrSet->save();

The initialization is done before the save.

greg0ire
Heres the thing though, in the admin section when you hover over the link for the default attribute set, the id shows as 4. When i call Mage::getModel('eav/entity_attribute_set') ->load($setName, 'attribute_set_name'); the attribute id is returned as 1. Therefore when calling initFromSkeleton the the default group is 4 and not 1 so no attributes are associated
Bill
@Bill: I edited my post (code is more readable in the initial message).
greg0ire