【发布时间】:2011-12-07 08:49:01
【问题描述】:
我已经尝试了互联网上的每个教程,我在这里提出了问题并得到了一些我接受并遵循的好答案。我已经创建了模块,更改了核心文件,安装了各种版本的 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 添加为新客户表单上的输入。
有关 EAV 的更多信息,请访问 Alan Storm's Blog
【讨论】:
检查这些 MySQL 表以确保您的新 EAV 属性已正确插入。
属性名称应在eav_attribute 中,并带有所有属性设置和一个新的attribute_id。新的 attribute_id 应该在这 3 个表的新记录中:customer_eav_attribute、customer_eav_attribute_website、customer_form_attribute。
在customer_eav_attribute,customer_eav_attribute_website 中确保is_visible 字段设置为1。
如果所有这些都检查成功,请报告我刚才提到的 4 个新行的转储,以便我们检查数据库中可能存在的任何其他问题。我最近刚刚在 Magento 1.6.1 上添加了新属性,我差点把头发扯下来,但最终还是让它工作了。
【讨论】:
customer_form_attribute 看起来不错,customer_eav_attribute 看起来不错。我错了,你只需要customer_eav_attribute_website 如果它是一个多商店。您使用的是什么版本的 Magento?是否保存了任何学校、childsname 或 flavor 字段?
customer_address_entity_varchar。你在说什么_form表,`customer_form_attribute`?这没有值,只有 4 个具有新属性 id 和表单代码的引用:adminhtml_customer_address、customer_address_edit 和 customer_register_address。你的模块 config.xml 是什么样的?
我遇到这个问题是因为缺少这样的代码
$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();之后的我的设置脚本中
【讨论】: