Studyon Minte9.com
Magento




Address Attributes



<?php

	// eav address custom atribute
	// http://mag.nb.ro/customer/address/edit/id/4024
	// -- customer/address/edit.phtml

	$c = array (
	  'entity_type_id'  => 2,         // 11 is the id of the entity model "sales/order". This could be different on your system! Look at database-table "eav_entity_type" for the correct ID!
	  'attribute_code'  => 'address_iban',
	  'backend_type'    => 'varchar',     // MySQL-DataType
	  'frontend_input'  => 'text', // Type of the HTML-Form-Field
	  'is_global'       => '1',
	  'is_visible'      => '1',
	  'is_required'     => '0',
	  'is_user_defined' => '0',
	  'frontend_label'  => 'IBAN',
	);
	$attribute = new Mage_Eav_Model_Entity_Attribute();
	$attribute->loadByCode($c['entity_type_id'], $c['attribute_code'])
			  ->setStoreId(0)
			  ->addData($c);
	$attribute->save(); 

	// customer_form_attribute

	$setup = new Mage_Eav_Model_Entity_Setup('core_setup');
	$idAttr = $setup->getAttributeId('customer_address', 'address_iban');

	$db = Mage::getSingleton('core/resource')->getConnection('core_write');
	// to link the attribute to the backend
	$sql = "INSERT INTO customer_form_attribute (form_code, attribute_id)
	    VALUES ('customer_address_edit', $idAttr)";
	$db->query($sql);

/*
SELECT * FROM customer_address_entity_varchar WHERE entity_id=4024;
SELECT * FROM eav_attribute WHERE entity_type_id=2;
*/



Config

local/sales/config.xml

sales_copy_order_billing_address
sales_copy_order_shipping_address
sales_convert_quote_address
sales_convert_order_address
customer_address

</sales_copy_order_billing_address>
	...
	<address_iban><to_order>*</to_order></address_iban>
</sales_copy_order_billing_address>

/*
select entity_id, firstname, address_iban from sales_flat_order_address order by entity_id desc limit 2;
*/



Display custom address field

	System -> Configuration -> Customer Configuration -> Address Template
	HTML
	{{depend address_company}}{{var address_company}}<br />{{/depend}}


http://www.magentocommerce.com/boards/viewthread/16582/#t67102
http://stackoverflow.com/questions/5609987/magento-save-custom-address-attribute-in-checkout
http://www.excellencemagentoblog.com/magento-adding-custom-field-to-customer-address