Magento:创建自定义属性,设置默认属性集

时间:2011-12-19 15:25:38

标签: php api magento attributes

只是一个简单但令人头疼的问题。

我创建了一个属性,将其设置为Drop-Down行为(在Admin-Store中,被视为下拉属性) 它正在创建安静平滑,但没有设置attribute_set。

简而言之:

是状态: 我的属性 - >没有链接到属性集

到状态: 我的属性 - >链接到默认属性集

1 个答案:

答案 0 :(得分:4)

管理方式:

自然地,新创建的属性不会自动分配给属性集(包括Default属性集)。你需要手动完成。

在管理员中,在目录>下;属性>管理属性集。

source

编程方式:

试试这段代码:

$installer = Mage::getModel('eav/entity_setup');
$installer->addAttributeToSet($entityTypeId, $setId, $groupId, $attributeId, $sortOrder);

addAttributeToSet函数的规范:

  • mixed $ entityTypeId
  • mixed $ setId
  • mixed $ groupId
  • mixed $ attributeId
  • int $ sortOrder = null
  • @return Mage_Eav_Model_Entity_Setup

以“Id”结尾的参数根据代码实际上不必是id。设置和组名称可以自动转换为ID。但是对于属性,你应该使用代码(通常用小写字母,例如'firstname')而不是名字(例如'First Name')。

例如,您想要将名为“热门”的产品属性添加到“常规”组下的“默认”属性集中,只需这样写:

$installer = Mage::getModel('eav/entity_setup');
$installer->addAttributeToSet('catalog_product', 'Default', 'General', 'popularity');

不幸的是我暂时没有安装来测试代码,希望它应该可以工作:)

相关问题