自定义客户属性未保存到数据库Magento


Custom Customer Attributes not saving to database Magento?

我尝试了互联网上的每个教程,我在这里提出了问题,并得到了一些我接受并遵循的好的答案。我已经创建了模块,更改了核心文件,安装了各种版本的magento,但无论我做什么,我都不能得到任何我要存储在数据库中的东西!

我只是想能够创建一个自定义字段的新帐户形式,并将其存储在数据库中,我不在乎在哪里?

我也有同样的问题,这是由于在您的属性名称中使用大写字母引起的。

如果你只使用小写字母,所有的东西都会被保存得很好。

设置脚本如下:

<?php
$installer = $this;
$installer->startSetup();
$eav = new Mage_Eav_Model_Entity_Setup('core_setup');
$eav->addAttribute('customer', 'my_property', array(
    'label'     => 'My Property',
    'type'      => 'varchar',
    'input'     => 'text',
    'visible'   => true,
    'required'  => true,
    'position'  => 1,
));
$installer->endSetup();

那么您应该能够添加my_property作为New Customer表单的输入。

更多关于EAV在Alan Storm的博客

检查这些MySQL表,以确保您的新EAV属性已正确插入。属性名应该在eav_attribute中,包含所有属性设置和一个新的attribute_id。新的attribute_id应该在customer_eav_attribute, customer_eav_attribute_website, customer_form_attribute这3个表的新记录中。

customer_eav_attribute, customer_eav_attribute_website中确保is_visible字段设置为1。

如果所有这些检查出来,报告我刚刚提到的4个新行的转储,这样我们就可以检查DB中任何其他可能错误的地方。我最近刚刚在Magento 1.6.1上添加了新的属性,我几乎要把我的头发扯出来,但最终还是让它工作了。

当我有这个问题是因为缺少这样的代码

$installer->addAttribute("empresas", "email", array(
    "type" => "varchar",
    "backend" => "",
    "label" => "Email",
    "input" => "text",
    "source" => "",
    "visible" => true,
    "required" => true,
    "default" => "",
    "frontend" => "",
    "unique" => false
));
$attribute = Mage::getSingleton("eav/config")->getAttribute("empresas", "email");

$used_in_forms = array();
$used_in_forms[] = "adminhtml_empresas";
$attribute->setData("used_in_forms", $used_in_forms)
        ->setData("is_used_for_customer_segment", false)
        ->setData("is_system", 0)
        ->setData("is_user_defined", 0)
        ->setData("is_visible", 1)
        ->setData("sort_order", 100)
;
$attribute->save();

$installer->installEntities();

之后