Magento 1.9,新创建的客户属性将无法保存

时间:2018-11-01 20:17:33

标签: magento magento-1.9

我正在创建一个新的客户属性。我已经使用升级安装程序脚本创建了定制属性。脚本成功运行并创建字段。我可以在Magento管理员中看到该字段,但是,我无法保存记录。

<?php
$installer = $this;
$installer->startSetup();

$installer->addAttribute("customer", "verifiedcustomer",  array(
    "type"     => "varchar",
    "backend"  => "",
    "label"    => "Verified Customer Completion",
    "input"    => "text",
    "source"   => "",
    "visible"  => true,
    "required" => false,
    "default" => "",
    "frontend" => "",
    "unique"     => false,
    "note"       => ""

	));

$attribute   = Mage::getSingleton("eav/config")->getAttribute("customer", "verifiedcustomer");
$used_in_forms=array();
$used_in_forms[]="adminhtml_customer";
$attribute->setData("used_in_forms", $used_in_forms)
    ->setData("is_used_for_customer_segment", true)
    ->setData("is_system", 0)
    ->setData("is_user_defined", 1)
    ->setData("is_visible", 1)
    ->setData("sort_order", 200);
$attribute->save();

$installer->endSetup();

其他自定义属性值已从Magento管理员正确保存,但是此新创建的“已验证”客户将不会保存。

以下是Magento管理员生成的HTML ... 'verifiedcustomer' Custom Field

<tr>
  <td class="label"><label for="_accountverifiedcustomer">Verified Customer Completion</label></td>
  <td class="value">
    <input id="_accountverifiedcustomer" name="account[verifiedcustomer]" value="" class=" input-text" type="text"> </td>
</tr>

我正在寻找任何想法,感谢您的答复。

1 个答案:

答案 0 :(得分:0)

因此,很明显,Magento不喜欢以单词“ customer”结尾的定制客户属性。我将属性的变量更改为verifiedprogram而不是verifiedcustomer,现在属性已正确保存。

下面的最终代码...

<?php

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

$installer->addAttribute("customer", "verifiedprogram",  array(
    "type"     => "varchar",
    "backend"  => "",
    "label"    => "Verified Customer Completion",
    "input"    => "text",
    "source"   => "",
    "visible"  => true,
    "required" => false,
    "default"  => "",
    "frontend" => "",
    "unique"   => false,
    "note"     => ""

	));

$attribute   = Mage::getSingleton("eav/config")->getAttribute("customer", "verifiedprogram");
$used_in_forms=array();
$used_in_forms[]="adminhtml_customer";
$attribute->setData("used_in_forms", $used_in_forms)
    ->setData("is_used_for_customer_segment", true)
    ->setData("is_system", 0)
    ->setData("is_user_defined", 1)
    ->setData("is_visible", 1)
    ->setData("sort_order", 200);
$attribute->save();

$installer->endSetup();