Magento Forum

   
Adding an attribute in addresses
 
SeL_
Magento Team
 
Avatar
Total Posts:  1140
Joined:  2007-10-10
Paris, France
 

Hi,

I need to add an attribute to the addresses (customer’s, billing and shipping ones).
So i ran this SQL:

insert into eav_attribute (attribute_identity_type_idattribute_codeattribute_modelbackend_modelbackend_typebackend_tablefrontend_modelfrontend_inputfrontend_labelfrontend_classsource_modelis_globalis_visibleis_requiredis_user_defineddefault_valueis_searchableis_filterableis_comparableis_visible_on_frontis_uniqueapply_touse_in_super_product
values (null2'vatnumber'null'''varchar''''''text''VAT Number'null'''true''true''false''false''''false''false''false''false''false'0'true');
insert into eav_attribute (attribute_identity_type_idattribute_codeattribute_modelbackend_modelbackend_typebackend_tablefrontend_modelfrontend_inputfrontend_labelfrontend_classsource_modelis_globalis_visibleis_requiredis_user_defineddefault_valueis_searchableis_filterableis_comparableis_visible_on_frontis_uniqueapply_touse_in_super_product
values (null6'vatnumber'null'''varchar''''''text''VAT Number'null'''true''true''false''false''''false''false''false''false''false'0'true');
insert into eav_attribute (attribute_identity_type_idattribute_codeattribute_modelbackend_modelbackend_typebackend_tablefrontend_modelfrontend_inputfrontend_labelfrontend_classsource_modelis_globalis_visibleis_requiredis_user_defineddefault_valueis_searchableis_filterableis_comparableis_visible_on_frontis_uniqueapply_touse_in_super_product
values (null12'vatnumber'null'''varchar''''''text''VAT Number'null'''true''true''false''false''''false''false''false''false''false'0'true');
insert into eav_attribute (attribute_identity_type_idattribute_codeattribute_modelbackend_modelbackend_typebackend_tablefrontend_modelfrontend_inputfrontend_labelfrontend_classsource_modelis_globalis_visibleis_requiredis_user_defineddefault_valueis_searchableis_filterableis_comparableis_visible_on_frontis_uniqueapply_touse_in_super_product
values (null19'vatnumber'null'''varchar''''''text''VAT Number'null'''true''true''false''false''''false''false''false''false''false'0'true');
And I added an input form element “vatnumber” in the templates.
So I can create a new address with this attribute. I’ve got the information in the database.
First question: is this correct ?

Then, when i checkout with this address, the billing and shipping addresses don’t have the VAT Number information in the database. It seems that it does not take this attribute from customer’s address.

Any suggestion ?

Thanks

 
Magento Community Magento Community
Magento Community
Magento Community
 
Michael
Enthusiast
 
Total Posts:  826
Joined:  2007-08-31
 

You can check if there is anything you has to modify in app\code\core\Mage\Sales\Model\Quote\Address.php method importCustomerAddress() and app\code\core\Mage\Sales\Model\Order\Address.php method importQuoteAddress().

 
Magento Community Magento Community
Magento Community
Magento Community
 
SeL_
Magento Team
 
Avatar
Total Posts:  1140
Joined:  2007-10-10
Paris, France
 

Thank you Michael, it works perfectly. I made a new class to overload app\code\core\Mage\Sales\Model\Quote\Address.php
method: importCustomerAddress():

class Mage_EuVatNumber_Sales_Model_Quote_Address extends Mage_Sales_Model_Quote_Address
{
    
public function importCustomerAddress(Mage_Customer_Model_Address $address)
    
{
        
return parent::importCustomerAddress($address)
        ->
setVatnumber($address->getVatnumber());
    
}
}
And the attribute is now saved in both billing and shipping addresses.

Thanks !

 
Magento Community Magento Community
Magento Community
Magento Community
 
SeL_
Magento Team
 
Avatar
Total Posts:  1140
Joined:  2007-10-10
Paris, France
 

Another question.
Do i need to modify Mage/Sales/Model/Entity/Setup.php file ?
What is it used for ?

 
Magento Community Magento Community
Magento Community
Magento Community
 
Michael
Enthusiast
 
Total Posts:  826
Joined:  2007-08-31
 
SeL - 29 November 2007 07:42 AM

Another question.
Do i need to modify Mage/Sales/Model/Entity/Setup.php file ?
What is it used for ?

It’s used to setup sales entities. If you don’t want to look for IDs in the database, modify your queries posted above and running them again each time your reinstall your Magento you have to create EuVatNumber/sql/euvatnumber_setup/mysql4-install-0.0.1.php containing something like the following:

$this->addAttribute('customer_address''vatnumber', array('type'=>'text''visible'=>false));
$this->addAttribute('quote_item''vatnumber', array('type'=>'text''visible'=>false));
$this->addAttribute('quote_address_item''vatnumber', array('type'=>'text''visible'=>false));
$this->addAttribute('order_item''vatnumber', array('type'=>'text''visible'=>false));

Don’t forget to modify your module version in EuVatNumber/etc/config.xml once you create an upgrade file (mysql4-upgrade-old.version.number-new.version.number.php) later.

You can look into the files under app\code\core\Mage\Core\sql\core_setup\ - they have all the possible install/upgrade ways used grin

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
    Back to top