User's API and Process summary

Source: Internet
Author: User
Application of the user module in the MAGENTO system;
  • Frontend registration, login, combined with shopping cart management
  • User Center
  • Backend user management and related operations (including user management, user information viewing, and user groups)

 

 

In the MAGENTO system, the Customer module uses the EAV design method, that is, the customer-related data is called and processed through the magento built-in API.

 

 

Involved APIs:

The APIs of the user module can be considered in the following three aspects;

  • For the current user (obtain the data information of the current user)
  • For background management users
  • Deletion, addition, modification, and query of common users
  • Corresponding API between users and addresses

 

 

1. For the current user (the session generated after login)

 

For customer login (login or not)

Mage: getSingleton ('customer/session')-> isLoggedIn () returns boolean

If (Mage: getSingleton ('customer/session')-> isLoggedIn ()){

}

 

 

2.SessionAPI for obtaining information about the current user (CUSTOMER)

 

Get the entity of the current customer:

Mage: getSingleton ('customer/session')-> getCustomer ();

 

API generated by the current entity

Mage: getSingleton ('customer/session')-> getCustomerId ();

 

Mage: getSingleton ('customer/session')-> getId ();

 

Mage: getSingleton ('customer/session')-> getCustomer ()-> getName ();

 

Mage: getSingleton ('customer/session')-> getUsername (true );

 

(String) Mage: getSingleton ('customer/session')-> getCustomer ()-> getEmail ();

 

If a custom field is added to the customer model (for example, the mobile phone number, QQ number, and Weibo number are added to the MAGENTO system), the eav orm ing can be used to push the fields in sequence.

 

 

The default shipping mode with the current user

Mage: getSingleton ('customer/session')-> getCustomer ()-> getdefashipshipping ()

 

 

BILL

Mage: getSingleton ('customer/session')-> getCustomer ()-> getDefaultBilling ()

 

TIPS:
Because of shipping, bill has a one-to-many relationship (for example, a user can enter multiple shipping addresses. For details about bill API, refer to BILL and order related APIs.

 

3. Targeting the background

Logon to admin background?

 

Mage: getSingleton ('admin/session')-> isLoggedIn ()

 

 

Background administrator-relatedInformation

 

Mage: getSingleton ('admin/session')-> getUser ()-> getFirstname ()

 

Mage: getSingleton ('admin/session')-> getUser ()-> getLastname ())

 

Mage: getSingleton ('admin/session')-> getUser ()-> getId ()

 

Mage: getSingleton ('admin/session')-> getUser ()-> getExtra ()

 

 

 

 

  1. User query, add, modify, and delete operations

    InvolvedResource: Customer

Targeting a user;

$ Customer-> load ($ customer-> getId ());

 

 

Delete


Load () to obtainCustomerAnd then callDeleteMethod To delete

$ Customer-> load ($ customer-> getId ());

 

$ Customer-> delete ();

 

 

Query List ()


Obtain all customers

 

 

 

 

  1. Corresponding API between users and addresses

InvolvedResource: Customer_address

 

Binding between users and addresses

 

$ Address = Mage: getModel ('customer/address ');

$ Address-> setId (null)-> setIsDefaultBilling (DATA)-> setisdefashipshipping ();

$ Customer-> addAddress ($ address );

 

 

Databases and tables;

User processing in the database includes: customer address, customer, customer group.

 

According to the EAV design principles, all tables involved should contain the entity, attribute, and attribute _ Storage types.

 


For customers:

Customer_entity

Customer_entity_decimal

Customer_entity_datetime

Customer_entity_varchar

Customer_entity_text

 

TIPS:Customer
The address method is also the same (of course, in addition to customer_group, it is implemented in non-EAV mode ).

 

 

 

Thoughts on User Function Expansion

  1. User Registration (or user personal information): According to Chinese usage habits, first name and last name are not required. How to delete these fields?

     

  2. User Registration (or user personal information): With the development of WEB2.0, users can fill in extended information, including mobile phone numbers, QQ numbers, Weibo numbers, etc. How to add these fields?

     

     

  3. User Login: Currently, three login methods are available for mainstream websites, including mobile phone number login, email login, and user name login. By default, only email login is used in MAGENTO, how can I add another personal information for login?

 

 

In the practice of the user module, problems caused by individuals:

  1. Remove redundant information: The removeAttribute () method cannot normally remove redundant attributes, as shown in figure


$ Setup-> removeAttribute ('customer', 'firstname ');

 

$ Setup-> removeAttribute ('customer', 'lastname ');

 

 

  1. Fields added in MAGENTO1.6 cannot be added to entity (added to the database table ).

 

 

  1. When multiple login methods are enabled, you cannot override loginPost this action using the customize module method. As a result, you cannot use the controller of the customize module to rewrite the action for processing login.


 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.