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

时间:2011-12-07 08:49:01

标签: php mysql magento

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

我只是希望能够在新帐户表单上创建自定义字段并将其存储在数据库中,我不关心在哪里?

4 个答案:

答案 0 :(得分:2)

我遇到了同样的问题,这是因为你的属性名称中使用了大写字母。

如果你只使用小写字母,一切都会保存得很好。

答案 1 :(得分:0)

制作如下设置脚本:

<?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作为输入。

有关Alan Storm's Blog

的EAV的更多信息

答案 2 :(得分:0)

检查这些MySQL表以确保您已正确插入新的EAV属性。 属性名称应位于eav_attribute中,包含所有属性设置和新的attribute_id。新的attribute_id应该位于这3个表中的新记录中:customer_eav_attributecustomer_eav_attribute_websitecustomer_form_attribute

customer_eav_attributecustomer_eav_attribute_website确保is_visible字段设置为1.

如果所有这些都检出,请用我刚刚提到的4个新行的转储报告回来,这样我们就可以检查数据库中可能出错的其他任何内容。我刚刚在Magento 1.6.1上添加了新的属性,我几乎把我的头发撕掉了,但最后还是让它工作了。

答案 3 :(得分:0)

当我遇到这个问题时,因为缺少像这样的代码

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

之后的设置脚本中