How to add custom checkbox to client in magento?

In mysql4-install-0.1.0.php, I can add a custom text field in my magento module as follows:

$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 also want to add a check box. 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 check box in admin / customer, but when I try to edit or add a new client, it will not save the client. It will just show the β€œWait” indicator. How to do it?

* Edit

Calling the member function setAttribute () for 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 see the select component with yes | no and his work is excellent. It is also displayed in the customer registration form as follows:

<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 this to be a check box. I 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 that will not save. How to save it?

+5
2

javascript. select jQuery. , .

(function($){
    $(document).ready(function(){
        var selects = $('.checkselect');
        $.each(selects, function(index, select){
            var checkbox = "<input class='selectcheckbox' type='checkbox' value='0' />";
            $(select).append($(checkbox));
            $(select).find('select').hide();
            $(select).on('click', '.selectcheckbox', function(){
                if($(this).is(':checked'))
                    $(select).find('select').val('1');
                else 
                    $(select).find('select').val('0');
            });
        });
    });
})(jQuery);

, . - , .

+1

:

<input class="checkbox" id="marketattended1" name="marketattended1" onchange="[removed]changechecked()" type="checkbox" value="1" />

+5

All Articles