Adding custom attribute to Customer

/app/code/local/Your/Customattribute/sql/your_customattribute_setup/install-0.1.0.php

<?php
$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", "customattribute",  array(
    "type"     => "varchar",
    "backend"  => "",
    "label"    => "Custom Attribute",
    "input"    => "text",
    "source"   => "",
    "visible"  => true,
    "required" => false,
    "default" => "",
    "frontend" => "",
    "unique"     => false,
    "note"       => "Custom Attribute"
));

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

$setup->addAttributeToGroup(
    $entityTypeId,
    $attributeSetId,
    $attributeGroupId,
    'customattribute',
    '999'  //sort_order
);

$used_in_forms=array();

$used_in_forms[]="adminhtml_customer";
//$used_in_forms[]="checkout_register";
//$used_in_forms[]="customer_account_create";
//$used_in_forms[]="customer_account_edit";
//$used_in_forms[]="adminhtml_checkout";
        $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();

/app/code/local/Your/Customattribute/etc/config.xml

 <?xml version="1.0"?>
    <config>
        <modules>
            <Your_Customattribute>
                <version>0.1.0</version>
            </Your_Customattribute>
        </modules>
        <global>

            <resources>
                <Your_Customattribute_setup>
                    <setup>
                        <module>Your_Customattribute</module>
                        <class>Mage_Customer_Model_Entity_Setup</class>
                    </setup>
                    <connection>
                        <use>core_setup</use>
                    </connection>
                </Your_Customattribute_setup>
                <Your_Customattribute_write>
                    <connection>
                        <use>core_write</use>
                    </connection>
                </Your_Customattribute_write>
                <Your_Customattribute_read>
                    <connection>
                        <use>core_read</use>
                    </connection>
                </Your_Customattribute_read>
            </resources>
        </global>

    </config>

app/etc/modules/Your_Customattribute.xml

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

Then to retrieve or edit you use:

$customer = Mage::getModel('customer/customer')->load($custid);
$customer->getCustomattribute();
$customer->setCustomattribute($yourjson);

You will have to create event observers for the login event, answered here: How can i get customer data from observer after successful login?

and also likely observers for the customer_save_after in case they alter their address in account mgmt, and one for the quote, which could be in different places depending on what you are going for.


There is a lot of custom functionality you'll have to create yourself as custom module overriding classes, and hooking into events where you want data passed to your web service. As far as the attribute goes, when you create your custom module and define a setup resource for it in the module's config.xml like in the tutorial above, then in your install script you can do something like this:

[module_path]/sql/[resource_node_defined_in_config_xml]/mysql4-install-[module_version_number].php

$installer = $this;

$installer->startSetup ();

$setup = Mage::getModel ( 'customer/entity_setup' , 'core_setup' );

    //add budget
    $setup->addAttribute('customer', 'budget', array(
        'type' => 'decimal',
        'input' => 'text',
        'label' => 'Budget',
        'global' => 1,
        'visible' => 1,
        'required' => 0,
        'user_defined' => 0,
        'default' => '',
        'visible_on_front' => 1,
        'source' =>   NULL,
        'comment' => 'This is a budget'
    ));

$installer->endSetup ();

user_defined makes the attribute a system attribute if set to 0, which disables the ability to delete it from the admin.