确定,它可以添加一个新的属性,使用类似以下在Magento设置:添加属性集中,但基于现有的一组 - Magento的
$entitySetup = new Mage_Eav_Model_Entity_Setup;
$entitySetup->addAttributeSet('catalog_product', $setName);
但我怎么能立足于现有的一组像集默认。该选项在管理部分中可用,因此可能。
确定,它可以添加一个新的属性,使用类似以下在Magento设置:添加属性集中,但基于现有的一组 - Magento的
$entitySetup = new Mage_Eav_Model_Entity_Setup;
$entitySetup->addAttributeSet('catalog_product', $setName);
但我怎么能立足于现有的一组像集默认。该选项在管理部分中可用,因此可能。
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();
初始化在保存之前完成。
在这里您可以找到关于working with attribute sets的有用信息。
// 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();
这里:
$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();
这是对我工作。
$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);
亚历
最佳答案imo – 2016-04-26 14:58:08
继承人的事情不过,在当鼠标悬停在链接设置的默认属性管理部分,该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