Magento的 - 添加属性客户实体 [英] Magento - Add attribute to customer entity

查看:224
本文介绍了Magento的 - 添加属性客户实体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有关这两天我一直在试图为添加新的客户属性以Magento的数据库。但它不工作。我添加了一个简单的昵称输入域 register.phtml edit.phtml 下面这个教程:

For two days I have been trying to add new customer attribute to the magento database. But it isn't working. I added a simple "nickname" input field to the register.phtml and edit.phtml following this tutorial:

<一个href=\"http://www.magentocommerce.com/wiki/5_-_modules_and_development/customers_and_accounts/registration_fields\">http://www.magentocommerce.com/wiki/5_-_modules_and_development/customers_and_accounts/registration_fields

下面是内在的论坛帖子:

Here is the inherent forum post:

<一个href=\"http://www.magentocommerce.com/boards/viewthread/9620/\">http://www.magentocommerce.com/boards/viewthread/9620/

属性将被添加到数据库表中的 eav_attribute ,但该值不会出现在 customer_entity_varchar

The attribute is added to the database table eav_attribute, but the value doesn't appear in the customer_entity_varchar.

下面是我:

所有文件都位于应用/ code /本地/公司/

应用/ code /本地/公司/客户的/ etc / config.xml中

http://mysticpaste.com/view/9466 (注意:&LT ;! - 绰号 - &GT;

应用/ code /本地/公司/客户/型号/实体/ Setup.php (注意: / *昵称* /

http://mysticpaste.com/view/9467


class Company_Customer_Model_Entity_Setup extends Mage_Customer_Model_Entity_Setup{

    public function getDefaultEntities()
        {
            return array(
                'customer' => array(
                    'entity_model'          =>'customer/customer',
                    'table'                 => 'customer/entity',
                    'increment_model'       => 'eav/entity_increment_numeric',
                    'increment_per_store'   => false,
                    'additional_attribute_table' => 'customer/eav_attribute',
                    'entity_attribute_collection' => 'customer/attribute_collection',
                    'attributes' => array(
    //                    'entity_id'         => array('type'=>'static'),
    //                    'entity_type_id'    => array('type'=>'static'),
    //                    'attribute_set_id'  => array('type'=>'static'),
    //                    'increment_id'      => array('type'=>'static'),
    //                    'created_at'        => array('type'=>'static'),
    //                    'updated_at'        => array('type'=>'static'),
    //                    'is_active'         => array('type'=>'static'),

                        'website_id' => array(
                            'type'          => 'static',
                            'label'         => 'Associate to Website',
                            'input'         => 'select',
                            'source'        => 'customer/customer_attribute_source_website',
                            'backend'       => 'customer/customer_attribute_backend_website',
                            'sort_order'    => 10,
                        ),
                        'store_id' => array(
                            'type'          => 'static',
                            'label'         => 'Create In',
                            'input'         => 'select',
                            'source'        => 'customer/customer_attribute_source_store',
                            'backend'       => 'customer/customer_attribute_backend_store',
                            'visible'       => false,
                            'sort_order'    => 20,
                        ),
                        'created_in' => array(
                            'type'          => 'varchar',
                            'label'         => 'Created From',
                            'sort_order'    => 30,
                        ),
                        'prefix' => array(
                            'label'         => 'Prefix',
                            'required'      => false,
                            'sort_order'    => 37,
                        ),
                        'firstname' => array(
                            'label'         => 'First Name',
                            'sort_order'    => 40,
                        ),
                        'middlename' => array(
                            'label'         => 'Middle Name/Initial',
                            'required'      => false,
                            'sort_order'    => 43,
                        ),
                        'lastname' => array(
                            'label'         => 'Last Name',
                            'sort_order'    => 50,
                        ),
                        'suffix' => array(
                            'label'         => 'Suffix',
                            'required'      => false,
                            'sort_order'    => 53,
                        ),
                        'email' => array(
                            'type'          => 'static',
                            'label'         => 'Email',
                            'class'         => 'validate-email',
                            'sort_order'    => 60,
                        ), /* nickname */
                        'nickname' => array(
                            'label'         => 'nickname',
                            'unique'        => true,
                            'sort_order'    => 65,
                            'required'      => true,
                        ),
                        'group_id' => array(
                            'type'          => 'static',
                            'input'         => 'select',
                            'label'         => 'Group',
                            'source'        => 'customer/customer_attribute_source_group',
                            'sort_order'    => 70,
                        ),
                        'dob' => array(
                            'type'          => 'datetime',
                            'input'         => 'date',
                            'backend'       => 'eav/entity_attribute_backend_datetime',
                            'required'      => false,
                            'label'         => 'Date Of Birth',
                            'sort_order'    => 80,
                        ),
                        'password_hash' => array(
                            'input'         => 'hidden',
                            'backend'       => 'customer/customer_attribute_backend_password',
                            'required'      => false,
                        ),
                        'default_billing' => array(
                            'type'          => 'int',
                            'visible'       => false,
                            'required'      => false,
                            'backend'       => 'customer/customer_attribute_backend_billing',
                        ),
                        'default_shipping' => array(
                            'type'          => 'int',
                            'visible'       => false,
                            'required'      => false,
                            'backend'       => 'customer/customer_attribute_backend_shipping',
                        ),
                        'taxvat' => array(
                            'label'         => 'Tax/VAT Number',
                            'visible'       => true,
                            'required'      => false,
                        ),
                        'confirmation' => array(
                            'label'         => 'Is Confirmed',
                            'visible'       => false,
                            'required'      => false,
                        ),
                        'created_at' => array(
                            'type'          => 'static',
                            'label'         => 'Created At',
                            'visible'       => false,
                            'required'      => false,
                            'input'         => 'date',
                        ),
                    ),
                ),

                'customer_address'=>array(
                    'entity_model'  =>'customer/customer_address',
                    'table' => 'customer/address_entity',
                    'additional_attribute_table' => 'customer/eav_attribute',
                    'entity_attribute_collection' => 'customer/address_attribute_collection',
                    'attributes' => array(
    //                    'entity_id'         => array('type'=>'static'),
    //                    'entity_type_id'    => array('type'=>'static'),
    //                    'attribute_set_id'  => array('type'=>'static'),
    //                    'increment_id'      => array('type'=>'static'),
    //                    'parent_id'         => array('type'=>'static'),
    //                    'created_at'        => array('type'=>'static'),
    //                    'updated_at'        => array('type'=>'static'),
    //                    'is_active'         => array('type'=>'static'),

                        'prefix' => array(
                            'label'         => 'Prefix',
                            'required'      => false,
                            'sort_order'    => 7,
                        ),
                        'firstname' => array(
                            'label'         => 'First Name',
                            'sort_order'    => 10,
                        ),
                        'middlename' => array(
                            'label'         => 'Middle Name/Initial',
                            'required'      => false,
                            'sort_order'    => 13,
                        ),
                        'lastname' => array(
                            'label'         => 'Last Name',
                            'sort_order'    => 20,
                        ),
                        'suffix' => array(
                            'label'         => 'Suffix',
                            'required'      => false,
                            'sort_order'    => 23,
                        ),
                        'company' => array(
                            'label'         => 'Company',
                            'required'      => false,
                            'sort_order'    => 30,
                        ),
                        'street' => array(
                            'type'          => 'text',
                            'backend'       => 'customer_entity/address_attribute_backend_street',
                            'input'         => 'multiline',
                            'label'         => 'Street Address',
                            'sort_order'    => 40,
                        ),
                        'city' => array(
                            'label'         => 'City',
                            'sort_order'    => 50,
                        ),
                        'country_id' => array(
                            'type'          => 'varchar',
                            'input'         => 'select',
                            'label'         => 'Country',
                            'class'         => 'countries',
                            'source'        => 'customer_entity/address_attribute_source_country',
                            'sort_order'    => 60,
                        ),
                        'region' => array(
                            'backend'       => 'customer_entity/address_attribute_backend_region',
                            'label'         => 'State/Province',
                            'class'         => 'regions',
                            'sort_order'    => 70,
                        ),
                        'region_id' => array(
                            'type'          => 'int',
                            'input'         => 'hidden',
                            'source'        => 'customer_entity/address_attribute_source_region',
                            'required'      => 'false',
                            'sort_order'    => 80,
                            'label'         => 'State/Province'
                        ),
                        'postcode' => array(
                            'label'         => 'Zip/Postal Code',
                            'sort_order'    => 90,
                        ),
                        'telephone' => array(
                            'label'         => 'Telephone',
                            'sort_order'    => 100,
                        ),
                        'fax' => array(
                            'label'         => 'Fax',
                            'required'      => false,
                            'sort_order'    => 110,
                        ),
                    ),
                ),
            );
        }   
}

应用程序/设计/前端/默认/公司/模板/客户/表格/ register.phtml

<label for="nickname" class="required" style="margin-left: -1px;"><em>*</em><?php echo $this->__('Nickname') ?></label>
<input type="text" name="nickname" id="nickname" value="<?php echo $this->htmlEscape($this->getFormData()->getnickname()) ?>" title="<?php echo $this->__('Nickname') ?>" class="input-text required-entry" />

我也在顶部运行这块PHP code的 register.phtml 的属性添加到 eav_attribute
这code的执行一次:

i also run this piece of php code in the top of register.phtml to add the attribute to the eav_attribute this code was executed once:

<?php
    $setup = new Mage_Eav_Model_Entity_Setup('core_setup');
    $AttrCode = 'nickname';
    $settings = array (
        'position' => 1,
        'is_required' => 0
    );
    $setup->addAttribute('1', $AttrCode, $settings);
?>

应用程序/设计/前端/默认/公司/模板/客户/表格/ edit.phtml

<label for="nickname" class="required" style="margin-left: -1px;"><em>*</em><?php echo $this->__('Nickname') ?></label>
<input type="text" name="nickname" id="nickname" value="<?php echo $this->htmlEscape($this->getCustomer()->getnickname()) ?>" title="<?php echo $this->__('Nickname') ?>" class="input-text required-entry" />

我也清空了的/ var /缓存文件夹,但没有任何效果。

I also manually cleared the /var/cache folder but without any effect.

我不知道我能做些什么,所以任何帮助是非常欢迎的。

I have no idea what else I could do, so any help is very welcome.

编辑:

确定这里是我尝试了Magento的根:

Ok here is what i have tried on the magento root:

define('MAGENTO', realpath(dirname(__FILE__)));
ini_set('memory_limit', '32M');
set_time_limit (0);
require_once MAGENTO . '/app/Mage.php';

Mage::app();

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

$setup = new Mage_Eav_Model_Entity_Setup('core_setup');

$entityTypeId     = $setup->getEntityTypeId('customer');
$attributeSetId   = $setup->getDefaultAttributeSetId($entityTypeId);
$attributeGroupId = $setup->getDefaultAttributeGroupId($entityTypeId, $attributeSetId);

$setup->addAttribute('customer', 'nickname', array(
    'input'         => 'text',
    'type'          => 'text',
    'label'         => 'Nickname',
    'visible'       => 1,
    'required'      => 1,
    'user_defined'  => 1,
));

$setup->addAttributeToGroup(
 $entityTypeId,
 $attributeSetId,
 $attributeGroupId,
 'nickname',
 '999'  //sort_order
);


$oAttribute = Mage::getSingleton('eav/config')->getAttribute('customer', 'nickname');
$oAttribute->setData('used_in_forms', array('adminhtml_customer'));

$oAttribute->save();
$installer->endSetup();

这code将被执行罚款,有添加到 eav_attribute 表上没有错误信息或东西,但也没有新的属性。

This code will be executed fine and there is no error message or something but also no new attribute added to the eav_attribute table.

推荐答案

我编辑你的脚本,它的工作对我很好,我可以看到,现在的支持。新的属性

I edited your script and it worked fine for me, I can see new attribute in backed now.

替换此:

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

$setup = new Mage_Eav_Model_Entity_Setup('core_setup');

这一点:

$setup = new Mage_Eav_Model_Entity_Setup('core_setup');
$setup->startSetup();

这篇关于Magento的 - 添加属性客户实体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆