繁体   English   中英

马杰托。 仅为分组产品创建属性

[英]Magento. Create attribute for grouped products only

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

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

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

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

在您的代码中 $oEntitySetup 拥有所有产品,您永远不会选择特定的组,并确保将新属性赠送给所有产品

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM