Add a Set attribute, but based on an existing set - Magento

Well, you can add a new attribute to it set in magento using something like the following:

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

But how can I set a set in an existing set, as by default. This option is available in the administrator section, so it can be used.

+5
source share
5 answers

I did this 6 months ago, I no longer have the code, but I know that you should use the initFromSkeleton () method on your attribute set. You can look for Magento code for calls to this function, very few calls (maybe just one). He will show you its use.

EDIT: , , , . :

$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();

.

+3
            // create attribute set
            $entityTypeId = Mage::getModel('eav/entity')
                ->setType('catalog_product')
                ->getTypeId(); // 4 - Default

            $newSet = Mage::getModel('eav/entity_attribute_set');
            $newSet->setEntityTypeId($entityTypeId);
            $newSet->setAttributeSetName(self::ATTRIBUTE_SET_NAME);
            $newSet->save();

            $newSet->initFromSkeleton($entityTypeId);
            $newSet->save();
+3

This is what worked for me.

$i_duplicate_attribut_set_id = 10; // ID of Attribut-Set you want to duplicate
$object = new Mage_Catalog_Model_Product_Attribute_Set_Api();
$object->create('YOUR_ATTRIBUT_SET_NAME', $i_duplicate_attribut_set_id);

Alex

+1
source

Here you can find useful information about working with attribute sets .

0
source

Here:

$entityTypeId = Mage::getModel('eav/entity')
    ->setType('catalog_product')  // This can be any eav_entity_type code
    ->getTypeId();
$attrSet = Mage::getModel('eav/entity_attribute_set');

$attrSetCollection = $attrSet->getCollection();
$attrSetCollection
    ->addFieldToFilter('entity_type_id', array('eq' => $entityTypeId))
    ->addFieldToFilter('attribute_set_name', array('eq' => 'Default')); // This can be any attribute set you might want to clone

$defaultAttrSet = $attrSetCollection->getFirstItem();
$defaultAttrSetId = $defaultAttrSet->getAttributeSetId();

$attrSet->setAttributeSetName('Assinaturas'); // This is the new attribute set name
$attrSet->setEntityTypeId($entityTypeId);
$attrSet->initFromSkeleton($defaultAttrSetId);
$attrSet->save();
0
source

All Articles