2010-08-19 74 views
5

確定,它可以添加一個新的屬性,使用類似以下在Magento設置:添加屬性集中,但基於現有的一組 - Magento的

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

但我怎麼能立足於現有的一組像集默認。該選項在管理部分中可用,因此可能。

回答

3

6個月前,我做了這個,我沒有代碼了,但是我知道你必須在屬性集上使用initFromSkeleton()方法。你可以搜索Magento的代碼來調用這個函數,只有很少的調用(也許只有一個)。它會告訴你它的用法。

編輯:我記得我有同樣的問題,你正在談論,我寄給它。以下是我建議的用法:

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

初始化在保存之前完成。

+0

繼承人的事情不過,在當鼠標懸停在鏈接設置的默認屬性管理部分,該ID顯示爲4。當我打電話法師:: getModel('EAV/entity_attribute_set ') \t \t \t \t - > load($ setName,'attribute_set_name');屬性id返回爲1.因此,在調用initFromSkeleton時,默認組爲4而不是1,因此沒有屬性關聯 – Bill 2010-08-19 22:13:51

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

這裏:

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

這是對我工作。

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

亞歷

+0

最佳答案imo – 2016-04-26 14:58:08