如何在 Magento 中向客户组添加自定义属性?

How do you add custom attributes to Customer Groups in Magento?(如何在 Magento 中向客户组添加自定义属性?)
本文介绍了如何在 Magento 中向客户组添加自定义属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

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

We're on Magento CE 1.7.0.0, and we're trying to add new attributes to the Customer Group entities. We've successfully added custom attributes to Customers using the following install script:

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

有没有人对客户组而不是客户做过类似的事情?

Has anyone had any luck doing something similar with Customer Groups, rather than customers?

推荐答案

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

If you take a look at the sql installer/update scripts you will find something like this:

$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,所以你不要使用它的属性!

As you can see its a simple mysql4 table and you simply need to add a column to the group. It is not EAV so you dont work with attributes on that one!

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

The new colum will not show up in the form or grid! You have to add this manually via observer or rewriting Mage_Adminhtml_Block_Customer_Group_Edit_Form or Mage_Adminhtml_Block_Customer_Group_Grid by adding something like this for e.g text field:

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

这篇关于如何在 Magento 中向客户组添加自定义属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

In PHP how can you clear a WSDL cache?(在 PHP 中如何清除 WSDL 缓存?)
failed to open stream: HTTP wrapper does not support writeable connections(无法打开流:HTTP 包装器不支持可写连接)
Stop caching for PHP 5.5.3 in MAMP(在 MAMP 中停止缓存 PHP 5.5.3)
Caching HTTP responses when they are dynamically created by PHP(缓存由 PHP 动态创建的 HTTP 响应)
Memcached vs APC which one should I choose?(Memcached 与 APC 我应该选择哪一个?)
What is causing quot;Unable to allocate memory for poolquot; in PHP?(是什么导致“无法为池分配内存?在 PHP 中?)