0

我在使用安装程序脚本创建属性和属性集时遇到问题。属性集和属性已创建,但问题是属性被分配给所有属性集,而不是仅使用安装程序脚本创建自定义属性。

以下是我的安装程序脚本:

<?php
$installer = $this;
$installer->startSetup();
try{
$sNewSetName = 'Product Bundler Package';
$iCatalogProductEntityTypeId = (int) $installer->getEntityTypeId('catalog_product');

$oAttributeset = Mage::getModel('eav/entity_attribute_set')
->setEntityTypeId($iCatalogProductEntityTypeId)
->setAttributeSetName($sNewSetName);

if ($oAttributeset->validate()) {
$oAttributeset
    ->save()
    ->initFromSkeleton($installer->getAttributeSetId('catalog_product', 'Default'))
    ->save();
 }
else {
   Mage::log('Attributeset with name ' . $sNewSetName . ' already exists.');
   }
  }
  catch(Exception $ex){
 Mage::log('Attributeset with name ' . $sNewSetName . ' already exists.');

}


$installer->addAttributeGroup('catalog_product', 'Product Bundler Package', 'Bundled Package Data', 1000);

$data1= array (
    'attribute_set' =>  'Product Bundler Package',
    'group' => 'Bundled Package Data',
    'label'    => 'Preset1 name',
    'visible'     => true,
    'type'     => 'varchar', 
    'input'    => 'text',
    'system'   => true,
    'required' => false,
    'user_defined' => 1, 
);

$installer->addAttribute('catalog_product','bundle_preset1_name',$data1);

  $data2= array (
    'attribute_set' =>  'Product Bundler Package',
    'group'    => 'Bundled Package Data',
    'label'    => 'Preset2 name',
    'visible'  => true,
    'type'     => 'varchar', 
    'input'    => 'text',
    'system'   => true,
    'required' => false,
    'user_defined' => 1, 
);
$installer->addAttribute('catalog_product','bundle_preset2_name',$data2);

$data3= array (
    'attribute_set' =>  'Product Bundler Package',
    'group' => 'Bundled Package Data',
    'label'    => 'Preset3 name',
    'visible'     => true,
    'type'     => 'varchar', 
    'input'    => 'text',
    'system'   => true,
    'required' => false,
    'user_defined' => 1, 
);
$installer->addAttribute('catalog_product','bundle_preset3_name',$data3);

$data4 = array (
    'attribute_set' =>  'Product Bundler Package',
    'group' => 'Bundled Package Data',
    'label'    => 'Preset4 name',
    'visible'     => true,
    'type'     => 'varchar', 
    'input'    => 'text',
    'system'   => true,
    'required' => false,
    'user_defined' => 1, 
);
   $attribute =  $installer->addAttribute('catalog_product','bundle_preset4_name',$data4);


$installer->endSetup();
 ?>

我想创建具有属性集名称“Product Bundler Package”的自定义属性,并将所有属性分配给该属性集。

请帮我解决它。

4

1 回答 1

0

您可以在 $installer->endSetUp(); 之前添加以下代码

/*delete the group from default attribute set in the end of the script */
$resource = Mage::getSingleton('core/resource');
$write = $resource->getConnection('write');
$groupTable = $installer->getTable('eav_attribute_group');
$defaultSetId = $installer->getDefaultAttributeSetId($iCatalogProductEntityTypeId);
$groupNameToRemove = 'Bundled Package Data';
$write->query("Delete from $groupTable where attribute_set_id=$defaultSetId and attribute_group_name='$groupNameToRemove'");
于 2013-11-10T11:57:21.947 回答