Magento1 adds the custom attribute customerorientationcustomerjourneymapcustomerbas to the customer.

Source: Internet
Author: User
Customer, magento: magento1 add custom attributes to customer: data-licensecc & gt; in the module's SQL file: startSetup (); $ eavConfigMage :: getSingleton (eavconf data-id = "1190000005008696" data-license = "cc">

In the SQL file of the module:
/**

  • Add Attribute mobile for customer
    */

//echo 12345;$installer = $this;$installer->startSetup();$eavConfig = Mage::getSingleton('eav/config');$store  = Mage::app()->getStore(Mage_Core_Model_App::ADMIN_STORE_ID);$sortOrder = 999;$attributes = array('chuanzhen'              => array(    'type'          => 'varchar',    'label'         => 'chuanzhen',    'input'         => 'text',    'required'      => 1,    'global'        => 1,    'is_visible'    => 1,    'is_system'     => 0,    'position'      => 40,    'is_user_defined'  => 1,    'sort_order'    => $sortOrder++,),'sex'                   => array(    'type'          => 'int',    'label'         => 'Sex',    'input'         => 'radio',    'required'      => 1,    'is_visible'    => 1,    'is_system'     => 0,    'global'        => 1,    'is_user_defined'  => 1,    'position'      => 44,    'sort_order'    => $sortOrder++,),

);
/Save the preceding attributes to the database and add them to the page form./

Foreach ($ attributes as $ attributeCode => $ data) {$ installer-> addAttribute ('customer', $ attributeCode, $ data );} foreach ($ attributes as $ attributeCode => $ data) {$ attribute = $ eavConfig-> getAttribute ('customer', $ attributeCode ); $ attribute-> setWebsite ($ store-> getWebsite (); $ attribute-> addData ($ data ); if (false = ($ data ['is _ system'] = 1 & $ data ['is _ visable'] = 0 )) {$ usedInForms = array ('customer _ account_create ', 'Customer _ account_edit', 'checkout _ register ', 'adminhtml _ custom', 'adminhtml _ checkout '); $ attribute-> setData ('used _ in_forms ', $ usedInForms);} $ attribute-> save ();} $ installer-> endSeup (); add the properties of the drop-down box, add gender male and famale: $ installer-> startSetup (); $ installer-> addAttribute ('customer', 'gender', array ('label' => 'gender ', 'visible '=> true, 'required' => false, 'type' => 'int', 'input' => 'select ', 'Source' => 'eav/entity_attribute_source_table ',));
$tableOptions        = $installer->getTable('eav_attribute_option');  $tableOptionValues   = $installer->getTable('eav_attribute_option_value');    // add options for level of politeness  $attributeId = (int)$installer->getAttribute('customer', 'gender', 'attribute_id');  foreach (array('Male', 'Female') as $sortOrder => $label) {    // add option  $data = array(    'attribute_id' => $attributeId,      'sort_order'   => $sortOrder,  );  $installer->getConnection()->insert($tableOptions, $data);  // add option label  $optionId = (int)$installer->getConnection()->lastInsertId($tableOptions, 'option_id');  $data = array(      'option_id' => $optionId,      'store_id'  => 0,      'value'     => $label,  );  $installer->getConnection()->insert($tableOptionValues, $data);  

}

$installer->endSetup();

The above describes how magento1 adds custom attributes to the customer, including the customer and magento content, and hopes to help those who are interested in the PHP Tutorial.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.