In mysql4-install-0.1.0.php, I can add custom textfield in my magento module like this:
$entityTypeId = $setup->getEntityTypeId('customer');
$attributeSetId = $setup->getDefaultAttributeSetId($entityTypeId);
$attributeGroupId = $setup->getDefaultAttributeGroupId($entityTypeId, $attributeSetId);
$setup->addAttribute('customer', 'resale', array(
'input' => 'text',
'type' => 'varchar',
'label' => 'Resale number',
'visible' => 1,
'required' => 1,
'user_defined' => 1,
));
$setup->addAttributeToGroup(
$entityTypeId,
$attributeSetId,
$attributeGroupId,
'resale',
'999' //sort_order
);
$oAttribute = Mage::getSingleton('eav/config')->getAttribute('customer', 'resale');
$oAttribute->setData('used_in_forms', array('adminhtml_customer','customer_account_create'));
$oAttribute->save();
I want also add a checkbox field. I add it like this:
$setup->addAttribute('customer', 'marketattended1', array(
'input' => 'checkbox',
'type' => 'int',
'label' => 'San Francisco International Gift Fair',
'visible' => 1,
'required' => 0,
'user_defined' => 1,
));
$setup->addAttributeToGroup(
$entityTypeId,
$attributeSetId,
$attributeGroupId,
'marketattended1',
'999' //sort_order
);
$oAttribute = Mage::getSingleton('eav/config')->getAttribute('customer', 'marketattended1');
$oAttribute->setData('used_in_forms', array('adminhtml_customer','customer_account_create'));
$oAttribute->save();
I can see my checkbox field in admin/customer but when I'm trying to edit or add new customer it won't save the customer. It's just showing the "Please wait" indicator forever. How to make this work?
*Edit
Call to a member function setAttribute() on a non-object
I found this error or server response.
*Edit
I changed the installer code:
$setup->addAttribute('customer', 'marketattended1', array(
'input' => 'boolean',
'type' => 'int',
'label' => 'San Francisco International Gift Fair',
'visible' => 1,
'required' => 0,
'user_defined' => 1,
//'source' => 'eav/entity_attribute_source_boolean'
));
$setup->addAttributeToGroup(
$entityTypeId,
$attributeSetId,
$attributeGroupId,
'marketattended1',
'999' //sort_order
);
$oAttribute = Mage::getSingleton('eav/config')->getAttribute('customer', 'marketattended1');
$oAttribute->setData('used_in_forms', array('adminhtml_customer','customer_account_create'));
$oAttribute->save();
Now i can see select component with yes|no options and its working perfectly. It's also showing on customer registration form like this:
<div class="field">
<label for="marketattended1">San Francisco International Gift Fair</label>
<select id="marketattended1" name="marketattended1" class=" select">
<option value="0">No</option>
<option value="1">Yes</option>
</select></div>
I want it to be checkbox. I have tried like this:
<div class="field">
<input class="checkbox" id="marketattended1" onchange="[removed]changechecked()" type="checkbox" value="1" />
<label class="required">*Others</label >
</div>
But it won't save. How to make it save?
you have to add the name of the checkbox:
<input class="checkbox" id="marketattended1" name="marketattended1" onchange="[removed]changechecked()" type="checkbox" value="1" />
Then it works
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With