0

In Magento 1.9 there's this form in the magento admin:

account info

What's the best way to add an additional checkbox input to this form? I need this new checkbox/flag to be saved to the database.

| improve this question | | | | |
0

Attributes are the best bet for this job. Below script will help you to add an additional checkbox in the customer form

Create a script add.php in your root folder and use the below script, and call this script http://domain.com/add.php

<?php
 $baseDir = dirname(dirname(__FILE__));

 require_once($baseDir.'/app/Mage.php');

 umask(0);
 Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);

 $installer = new Mage_Customer_Model_Resource_Setup('core_setup');
 $installer->startSetup();

 $setup = new Mage_Eav_Model_Entity_Setup('core_setup');

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


 $installer->addAttribute('customer', 'additional_checkbox', array(
    'label' => 'Additional Checkox',
    'visible'  => true,
    'input' => 'checkbox',
    'type'  => 'int',
    'source'  => 'eav/entity_attribute_source_table',
    'forms' => array('adminhtml_customer'),
    'required' => 0,
    'user_defined' => 0,
));

$attribute  = Mage::getSingleton("eav/config")->getAttribute("customer", 
"additional_checkbox");

$setup->addAttributeToGroup(
   $entityTypeId,
   $attributeSetId,
   $attributeGroupId,
   'additional_checkbox',
   '99991'  //sort_order
 );

 //$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", 100)
 ;
 $attribute->save();
 $installer->endSetup();
| improve this answer | | | | |
  • I haven't tried it yet but thanks. So when I run this script it just adds some data to the database and I can then throw away the script? Should I make a module that contains this code? Where is the best documentation to learn about all the stuff you used in your code? – Ryan May 3 '19 at 2:32
  • The right place for this code is setup folder in a module mysql4-install-1.0.0.php. This will run only once, at the time of module installation. – Rinto George May 3 '19 at 19:54
  • Why do you have to specify the forms twice? – Ryan May 5 '19 at 2:05
  • @Ryan That is an error from my side – Rinto George May 5 '19 at 4:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.