Thursday, January 24, 2013

Magento : Create an attribute for customer mobile number

Consider package : Bd_Customermobile

1. Bd_Customermobile.xml

<?xml version="1.0"?>
<config>
  <modules>
    <Bd_Customermobile>
      <active>true</active>
      <codePool>local</codePool>
      <version>0.1.0</version>
    </Bd_Customermobile>
  </modules>
</config>

2. config.xml
<?xml version="1.0"?>
<config>
  <modules>
    <Bd_Customermobile>
      <version>0.1.0</version>
    </Bd_Customermobile>
  </modules>
  <global>
    <helpers>
      <customermobile>
        <class>Bd_Customermobile_Helper</class>
      </customermobile>
    </helpers>
    <models>
      <customermobile>
        <class>Bd_Customermobile_Model</class>
        <resourceModel>customermobile_mysql4</resourceModel>
      </customermobile>
    </models>
    <resources>
      <customerattribute_setup>
        <setup>
          <module>Bd_Customermobile</module>
          <class>Mage_Customer_Model_Entity_Setup</class>
        </setup>
        <connection>
          <use>core_setup</use>
        </connection>
      </customerattribute_setup>
      <customerattribute_write>
        <connection>
          <use>core_write</use>
        </connection>
      </customerattribute_write>
      <customerattribute_read>
        <connection>
          <use>core_read</use>
        </connection>
      </customerattribute_read>
    </resources>
  </global>
</config>

3. mysql4-install-0.1.0.php
<?php
$installer = $this;
$installer->startSetup();


$installer->addAttribute("customer", "bd_customer_mobile",  array(
    "type"     => "varchar",
    "backend"  => "",
    "label"    => "Customer Mobile",
    "input"    => "text",
    "source"   => "",
    "visible"  => true,
    "required" => false,
    "default" => "",
    "frontend" => "",
    "unique"     => false,
    "note"       => "Additional attribute for mobile number"

    ));

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

       
$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();
    

No comments:

Post a Comment