6

我们在 Magento CE 1.7.0.0 上,我们正在尝试向客户组实体添加新属性。我们已经使用以下安装脚本成功地向客户添加了自定义属性:

<?php
$installer = $this;
$installer->startSetup();

$setup = Mage::getModel('customer/entity_setup', 'core_setup');

$setup->addAttribute('customer', 'ussco_account_number', array(
    'type' => 'varchar',
    'input' => 'text',
    'label' => 'USSCO Account Number',
    'note' => 'Leave blank for default',
    'global' => 1,
    'visible' => 1,
    'required' => 0,
    'user_defined' => 0,
    'default' => '',
    'visible_on_front' => 0,
    'source' =>   NULL,
));

Mage::getSingleton('eav/config')
    ->getAttribute('customer', 'ussco_account_number')
    ->setData('used_in_forms', array('adminhtml_customer'))
    ->save();

$installer->endSetup();

有没有人幸运地与客户组而不是客户做类似的事情?

4

2 回答 2

8

如果您查看 sql 安装程序/更新脚本,您会发现如下内容:

$table = $installer->getConnection()
    ->newTable($installer->getTable('customer/customer_group'))
    ->addColumn('customer_group_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, null, array(
        'identity'  => true,
        'unsigned'  => true,
        'nullable'  => false,
        'primary'   => true,
        ), 'Customer Group Id')
    ->addColumn('customer_group_code', Varien_Db_Ddl_Table::TYPE_TEXT, 32, array(
        'nullable'  => false,
        ), 'Customer Group Code')
    ->addColumn('tax_class_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
        'unsigned'  => true,
        'nullable'  => false,
        'default'   => '0',
        ), 'Tax Class Id')
    ->setComment('Customer Group');

如您所见,它是一个简单的 mysql4 表,您只需向组中添加一列。它不是 EAV,所以你不要使用那个属性!

新列不会出现在表格或网格中!您必须通过观察者或重写手动添加此内容,Mage_Adminhtml_Block_Customer_Group_Edit_Form或者Mage_Adminhtml_Block_Customer_Group_Grid为例如文本字段添加类似内容:

$fieldset->addField('your_column', 'text',
    array(
        'name'  => 'Your_Column',
        'label' => Mage::helper('customer')->__('Tax Class'),
        'title' => Mage::helper('customer')->__('Tax Class'),
        'class' => 'required-entry',
        'required' => true
    )
);
于 2013-08-14T21:03:14.480 回答
0

我同样需要在 customer_group 中包含一个字段。我想在这里添加我的 sql 脚本以将一些自定义字段添加到customer_group

$installer = $this; 
$installer->startSetup();   

$installer->getConnection()->addColumn($installer->getTable('customer_group'), 'my_custom_field1', 'varchar(100)');
$installer->getConnection()->addColumn($installer->getTable('customer_group'), 'my_custom_field2', 'varchar(100)');

$installer->endSetup();

问候

于 2015-02-16T12:18:06.523 回答