How can I get my custom backend Magento Customer Checkbox Attribute to save my selection?

喜夏-厌秋 提交于 2019-12-11 15:33:05

问题


Magento CE 1.5.1.0

I'm trying to create a new customer attribute on the installation file for a Magento Module. I have it working fine for text inputs, but I would like to add a checkbox to the customer "Account Information" section of the "Customer Information" page, in the admin backend. It shouldn't be visible on the frontend or editable by the customer. I just want it to be a boolean value.

I have the attribute appearing on the backend, in the correct place, and it defaults to being unselected, which is good, but when I click "Save and continue edit" button (or "save customer"), I am redirected to the main Admin Dashboard. When i manage the customer again I see that me checking the checkbox has not been stored, and it's default again.

The code I currently have (taken from Jonathan Day's answer to this question: Adding attributes to customer entity ) is this:

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

$setup = new Mage_Eav_Model_Entity_Setup('core_setup');

$entityTypeId     = $setup->getEntityTypeId('customer');
$attributeSetId   = $setup->getDefaultAttributeSetId($entityTypeId);
$attributeGroupId = $setup->getDefaultAttributeGroupId($entityTypeId, $attributeSetId);

$setup->addAttribute('customer', 'ignore_ip_notifications', array(
    'input'         => 'checkbox',
    'type'          => 'int',
    'label'         => 'Ignore IP Notifications',
    'visible'       => 1,
    'user_defined'  => 0,
    'required'      => 0,
    'source'        => 'eav/entity_attribute_source_boolean'
));

$setup->addAttributeToGroup(
$entityTypeId,
$attributeSetId,
$attributeGroupId,
'ignore_ip_notifications',
'998'  //overwritten sort_order
);

$oAttribute = Mage::getSingleton('eav/config')->getAttribute('customer', 'ignore_ip_notifications');
$oAttribute->setData('used_in_forms', array('adminhtml_customer'));
$oAttribute->setData('sort_order', 998);
$oAttribute->save();

$installer->endSetup();

As mentioned, the attribute appears as it should but redirects to the dashboard, rather than save.

Any help would be very much appreciated.

IB


回答1:


I'm not 100% sure, but you might need fieldsets defined for backend as well, like this:

<fieldsets>
             <customer_account>
                 <attribute_code>
                    <create>1</create>
                    <update>1</update>
                </attribute_code>
             <customer_account>
</fieldsets>


来源:https://stackoverflow.com/questions/7114099/how-can-i-get-my-custom-backend-magento-customer-checkbox-attribute-to-save-my-s

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!