【问题标题】:Custom Customer Attributes not saving to database Magento?自定义客户属性未保存到数据库 Magento?
【发布时间】:2011-12-07 08:49:01
【问题描述】:

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

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

【问题讨论】:

标签: php mysql magento


【解决方案1】:

我遇到了同样的问题,它是由在您的属性名称中使用大写字母引起的。

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

【讨论】:

    【解决方案2】:

    制作一个这样的设置脚本:

    <?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

    【讨论】:

    • 我可以将 my_property 添加到 eav 属性,使用这样的脚本,没问题,我可以在前端添加漂亮的表单并放置正确的代码,但没有任何东西保存到数据库,我已经尝试了这一切让我疯狂的事情,我不明白为什么?看起来很简单,
    【解决方案3】:

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

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

    如果所有这些都检查成功,请报告我刚才提到的 4 个新行的转储,以便我们检查数据库中可能存在的任何其他问题。我最近刚刚在 Magento 1.6.1 上添加了新属性,我差点把头发扯下来,但最终还是让它工作了。

    【讨论】:

    • 感谢您的帮助,很抱歉延迟回复我不得不去戴上新假发!!!
    • 新的属性id在eav_attribute和customer_eav_attribute中但不在其他中并且可见,_website表中没有记录??我的尝试之一是设法在 _form_arrribute 表中获取 id(见链接)screencast.com/t/es5o3CApIDwnscreencast.com/t/tujQ48spWscreencast.com/t/onF5tA5Na我希望你能帮忙!!!再次感谢
    • customer_form_attribute 看起来不错,customer_eav_attribute 看起来不错。我错了,你只需要customer_eav_attribute_website 如果它是一个多商店。您使用的是什么版本的 Magento?是否保存了任何学校、childsname 或 flavor 字段?
    • 1.6.1 ,不,他们不保存,他们应该保存到 customer_entity_varchar 吗? _form 表呢?我还有一个实用程序可以搜索整个数据库的记录,所以我知道它们没有保存?谢谢
    • 是的,我也在 1.6.1 上,varchar 属性值保存到 customer_address_entity_varchar。你在说什么_form表,`customer_form_attribute`?这没有值,只有 4 个具有新属性 id 和表单代码的引用:adminhtml_customer_address、customer_address_edit 和 customer_register_address。你的模块 config.xml 是什么样的?
    【解决方案4】:

    我遇到这个问题是因为缺少这样的代码

    $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-&gt;installEntities();之后的我的设置脚本中

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-06-25
      • 2023-03-06
      相关资源
      最近更新 更多