Hello my dearest friends,
Here we are again, meeting up in Magento Tutorials after one week. Before we proceed further, let me ask you a very simple question: “What is the basic difference between a successful and an unsuccessful business?” A business is successful only when its products and services have enough buyers in the market. Yes, there are several other parameters also but customers play a crucial role in deciding the success and failure of an organization. And with such a large number of customer in your system, how can you handle them? Magento helps manage customer easily and conveniently.
1. Customer Entity
Similar to product, Magento uses EAV model to keep customer’s information. The main table to store customer data is customer_entity.
Besides EAV tables, customer’s attributes have an additional table (customer_eav_attribute), you can add validate required to an attribute:
If you want to add attributes in customer’s data, you can use the customer setup class (Mage_Customer_Model_Entity_Setup):
In addition, if you want to show your custom attribute on edit form in backend, you need to add attribute to customer form attribute:
2. Magento Customer Address
Magento designs multiple addresses option for one customer. In checkout process, customer address is converted to billing address and shipping address. The billing address is often used to calculate the tax for order, the shipping address is always used to calculate the shipping fee. Magento configures fields that convert from customer address to order address in config.xml file:
customer_id * *
Please note that EAV Model stores customer address. Therefore, adding attributes in it is similar to customer entity, which entity type is customer_address.
3. Configure validation customer information
To change the validation of customer information, you can go to System > Configuration > Customer Configuration and find the field set Name and Address Options:
When you save the configuration, the customer attribute is saved too. You can find the code to save it on class Mage_Adminhtml_Model_System_Config_Backend_Customer_Show_Customer and method _afterSave():
Therefore, you can add configuration to your custom attribute with the backend model (tag backend_model) as the following instruction: adminhtml/system_config_backend_customer_show_customer. The configuration will be automatically applied to your custom attribute that you added.
Well, that’s the end of today tutorial. Hope it’ll help you in managing customer data to make the most from your site! Feel free to leave any questions in comment and see you next time in Magestore Magento Blog!