2015-11-03 77 views
2

我正尝试以编程方式为我网站上的所有分组产品创建属性。我正在尝试使用组创建自定义属性集。Magento。仅为分组产品创建属性

$oEntitySetup = $this; 
$oEntitySetup->removeAttribute('catalog_product', 'grouped_base_price'); 

$skeletonID=$oEntitySetup->getAttributeSetId('catalog_product','Default'); 
$entityTypeId = Mage::getModel('catalog/product') 
    ->getResource() 
    ->getEntityType() 
    ->getId(); //product entity type 

$attributeSet = Mage::getModel('eav/entity_attribute_set') 
    ->setEntityTypeId($entityTypeId) 
    ->setAttributeSetName("oggy_attr_set"); 

$attributeSet->validate(); 
$attributeSet->save(); 

$attributeSet->initFromSkeleton($skeletonID)->save(); 

$data = array(
    'attribute_set' => 'oggy_attr_set', 
    'group' => 'General', 
    'label' => 'Base Price', 
    'apply_to' => 'grouped', 
    'input' => 'text', 
    'visible' => true, 
    'visible_on_front' => true, 
    'required' => true, 
    'position' => 1, 
    'global' => 'Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL', 
    'note'  => "Default Price For Configurable Products" 
); 
$oEntitySetup->addAttribute('catalog_product', 'grouped_base_price', $data); 

$oEntitySetup->endSetup(); 

问题是该属性出现在所有产品类型中。但我只需要分组产品。我做错了什么?

回答

2

将创建的属性分配给特定的“属性集”,然后在创建任何组产品时选择该属性集。

+0

您好,感谢您的回答。我已更新我的问题,请检查它。 – user3162709

0
在你的代码$ oEntitySetup

拥有所有的产品,你永远不采取特定群体,并确保你的礼物新属性的所有产品