Thursday , 18 September 2014
Topic 9 – Part 7: Customer Management

Topic 9 – Part 7: Customer Management

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.

Magento blog - Magento tutorial: Customer managerment

Customer_entity

Besides EAV tables, customer’s attributes have an additional table (customer_eav_attribute), you can add validate required to an attribute:

Magento blog - Magento tutorial: Customer management

Customer_eav_attribute

If you want to add attributes in customer’s data, you can use the customer setup class (Mage_Customer_Model_Entity_Setup):

$setup=new Mage_Customer_Model_Entity_Setup();
$setup->addAttribute('customer','national_id',array(
'group'=>'General',
'type'=>'varchar',
'input'=>'text',
'label'=>'National Identification',
'visible'=>1,
'required'=>0,
'visible_on_front'=>1,
'sort_order'=>120
));

In addition, if you want to show your custom attribute on edit form in backend, you need to add attribute to customer form attribute:

[php]$setup->getConnection()->insertMultiple($setup->getTable(‘customer/form_attribute’),array(
array(
‘form_code’=>’adminhtml_customer’,
‘attribute_id’=>$setup->getAttributeId(‘customer’,’national_id’)
)
));
[/php]

 

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:

[php] …

customer_address_id
customer_id * *
*
*
*

About David

David has been developing many great extensions in Magestore. He has a strong passion on programming and want to create product/service that serve society.