使用者模組在MAGENTO系統中的應用點;
- Frontend 的註冊,登陸, 結合購物車管理
- 使用者中心
- 後台backend的使用者管理以及相應的操作(包括使用者管理,查看使用者資訊,使用者組等)
在MAGENTO系統中,Customer模組所使用的是EAV的設計方式,也就是說customer相關的資料是通過magento內建的API來調用處理的。
所涉及到的API:
對於使用者模組的API可以從以下的三個方面來考慮;
- 針對目前使用者(獲得目前使用者的資料資訊)
- 針對後台系統管理使用者
- 普通使用者的刪除,添加,修改,查詢等
- 使用者與地址之間的對應API
1, 針對當前的使用者(已經登陸而產生的session)
針對customer login(是否登陸)
Mage::getSingleton('customer/session')->isLoggedIn() 返回boolean
if(Mage::getSingleton('customer/session')->isLoggedIn()) {
}
2.由session得到目前使用者(CUSTOMER)相關資訊的API
得到當前customer的entity:
Mage::getSingleton('customer/session')->getCustomer();
由當前entity所產生的API
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();
如果對customer model添加了自訂的欄位(如在MAGENTO系統上添加手機號,QQ號,微博號等),則可以根據EAV ORM的映射依次內推。
與目前使用者產生的預設運輸方式
Mage::getSingleton('customer/session')->getCustomer()->getDefaultShipping()
BILL
Mage::getSingleton('customer/session')->getCustomer()->getDefaultBilling()
TIPS:
由於shipping,bill有著一對多的關係(如一個使用者可以填寫多個運輸地址等,詳細的bill API將參考BILL 以及order相關的API.
3. 針對後台
針對admin後台是否登陸
Mage::getSingleton('admin/session')->isLoggedIn()
後台管理員相關的information
Mage::getSingleton('admin/session')->getUser()->getFirstname()
Mage::getSingleton('admin/session')->getUser()->getLastname())
Mage::getSingleton('admin/session')->getUser()->getId()
Mage::getSingleton('admin/session')->getUser()->getExtra()
- 使用者的查詢,添加,修改,刪除操作
涉及到的Resource :customer
針對某一個使用者;
$customer->load($customer->getId());
刪除
Load()來獲得某一個customer,進而調用delete方法來刪除
$customer->load($customer->getId());
$customer->delete();
查詢 List()
獲得所有的customer
- 使用者與地址之間的對應API
涉及到的Resource: customer_address
使用者與地址之間的綁定
$address = Mage::getModel('customer/address');
$address->setId(null)->setIsDefaultBilling(DATA)->setIsDefaultShipping();
$customer->addAddress($address);
資料庫與表;
使用者處理在資料庫中的反映包括:customer address, customer, customer group.
根據EAV的設計原則,所涉及到的表都應該包括有entity, attribute, attribute_儲存類型。
針對customer:
customer_entity
customer_entity_decimal
customer_entity_datetime
customer_entity_varchar
customer_entity_text
TIPS: 依次customer
address也方式也一樣(當然除customer_group外,它使用非EAV方式來實現)。
對使用者功能擴充的思考
- 使用者註冊(或者是使用者個人資訊):根據中國人的使用習慣是不需要first name, last name的,如何刪除這些欄位?
- 使用者註冊(或者是使用者個人資訊):隨著WEB2.0的發展,使用者可以填寫擴充資訊,包括有手機號,QQ號,微博號等,如何新添加這些欄位?
- 使用者登陸: 現在主流網站已經提供三種登陸方式,包括手機號登陸,郵箱登陸,使用者名稱登陸,預設情況下只有郵箱登陸在MAGENTO中使用,如何添加使用另外的個人資訊來登陸?
在使用者模組實踐中,個人所產生的問題:
- 移除多餘的資訊: removeAttribute()方法無法正常的移除多餘的屬性,如
$setup->removeAttribute('customer', 'firstname');
$setup->removeAttribute('customer', 'lastname');
- 在MAGENTO1.6中所添加的欄位無法添加到entity中(已經實現添加到資料庫表中)。
- 在啟動多種方式登陸時,無法使用customize module的方式來override loginPost這個action,從而導致無法使用customize module的controller來重寫處理login的action.