Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add attributeSet but based on an existing set - Magento

Tags:

php

magento

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.

like image 658
Bill Avatar asked Aug 19 '10 21:08

Bill


3 Answers

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.

like image 199
greg0ire Avatar answered Nov 08 '22 09:11

greg0ire


            // 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();
like image 3
Andre Aus B Avatar answered Nov 08 '22 10:11

Andre Aus B


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

like image 1
Alex Herbel Avatar answered Nov 08 '22 10:11

Alex Herbel