3

I want to create a new attributeset through a custom module installer. I found this code and it works :-) Only thing missing is that he should copy the new attribute set from the exsisting default attribute set. That way he would copy all the attributes already in the default set.

For example when I create attributes I use

<?php
$installer = $this;
/* @var $installer Mage_Eav_Model_Entity_Setup */

$installer->startSetup();
$installer->addAttributeSet(Mage_Catalog_Model_Product::ENTITY, 'Stoelen');
$installer->endSetup();
1

It may just be an error in English (which is a difficult language for sure), but attributes are not "copied" - they are linked via reference.

There is no native "duplicate this attribute set" functionality in Magento. To accomplish this you have two choices: via framework-supplied setup functionality or via EAV ORM. In the setup approach, you do the following:

  1. Create your set (as you've done with addAttributeSet())
  2. Retrieve the groups from the "source" set; loop, assign to "new" set
  3. Retrieve attribute from the "source" set; loop, and assign to groups

The setup approach simply wraps the direct ORM approach. See Mage_Eav_Model_Entity_Setup for more info, including paths on how to do this.

  • what's up with your weird tone in the first part of your message? Thanks for the rest I will try to find more information about that – Sander van Zuidam Jan 20 '15 at 14:16
  • Not seeing any weird tone (and certainly was not trying to present a tone). I mentioned it just in case it was a misconception that you had, and I also wanted to acknowledge that it may just be an issue with English language. – benmarks Jan 21 '15 at 9:47
  • Ok sorry then I misunderstood. – Sander van Zuidam Jan 21 '15 at 13:45
  • Actually, there is basically "duplicate this attribute set" in native magento, and it is a public method. Mage_Eav_Model_Entity_Attribute_Set->initFromSkeleton() Not sure if there are any downsides to using models directly in setup script to create attribute sets using initFromSkeleton – grizwako Aug 25 '16 at 5:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.