Mike McBrien
Mike McBrien

Reputation: 111

Magento 1.9, Newly Created Customer Attribute Will Not Save

I am working on creating anew customer attribute. I have created the custom attribute using an upgrade installer script. The script successfully runs and creates the field. I can see the field in the Magento admin, however, I am unable to save the record.

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

Other custom attribute values save correctly from the Magento admin but this newly created 'verified' customer will not save.

Below is the HTML generated on the Magento admin... '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>

I'm looking for any ideas, and I appreciate the responses.

Upvotes: 1

Views: 1468

Answers (1)

Mike McBrien
Mike McBrien

Reputation: 111

So, apparently, Magento is no fond of the custom customer attribute ending with the word "customer". I changed the variable for the attribute to verifiedprogram instead of verifiedcustomer and now the attribute properly saves.

The final code below...

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

Upvotes: 0

Related Questions