How To: NopCommerce Best Practices for Customer table
NopCommerce Versions: 3.7
NOTE: DRAFT IN PROGRESS
The Customer table is used for capturing both registered and non registered users of the system. For registered users, it only contains a small set of information usch as Username, Email, and password as shown below. Additional information relating to the customer such as First Name, Last Name and Gender is captured in the GenericAttribute table. The different way Customer information is entered are:
- When a user goes through the Retail > Register process a record is created in the Customer table.
- When a user does a Checkout > Guest Checkout (not logged in) they will have a generic empty record added. The Username, Email, Password, PasswordSalt, AdminContent, SystemName, LastLoginDateutc fields are set as NULL. The Id, CustomerGuid, PasswordFormatId, IsTaxExempt, AffiliateId, VendorId, HasShoppingCartItems, Active, Deleted, IsSystemAccount, LastIpAddress, CreatedOnUtc, LastActivityDateUtc, BillingAddress_id, ShippingAddress_Id are set. New Billing and Shipping Address records are created and then associated to the new Customer record.
- Guest Checkout Orders orders will leave a cookie on the client with a generated ID that was created in the Customer table. The Next time the registered Guest user comes to the site and places an order as Guest, it will use the originally created Customer.Id to use and associate to the Order. If the user decides to register at this point, it will use the originally created Customer record associated to the ID to be used for the new registered to the account.
- Admins going through Administration > Customer > New and
- Active (bit, 1)
- AdminComment (nvarchar, not null)
- AffiliateId (int, 4)
- BillingAddress_Id (int, 4, not null)
- CompanyId (int, 4, not null)
- CreatedOnUtc (datetime, 8)
- CustomerGuid (uniqueidentifier, 16)
- CustomerTypeId (int, 4, not null)
- Deleted (bit, 1)
- Email (nvarchar, 2000, not null)
- HasShoppingCartItems (bit, 1)
- Id (PK, int, 4)
- IsSystemAccount (bit, 1)
- IsTaxExempt (bit, 1)
- LastActivityDateUtc (datetime, 8)
- LastIpAddress (nvarchar, not null)
- LastLoginDateUtc (datetime, 8, not null)
- Password (nvarchar, not null)
- PasswordFormatId (int, 4)
- PasswordSalt (nvarchar, not null)
- ShippingAddress_Id (int, 4, not null)
- SystemName (nvarchar, 800, not null)
- Username (nvarchar, 2000, not null)
- VendorId (int, 4)
- Retail Site > Register:
- Checkout > Guest:
- Admin > Customer:
- If you are need to capture information relating to the user, you can capture information in the GenericAttribute table, but beware of the GenericAttribute tables usages. WARNING: storing data in here does not enforce referential integrity. You might want to consider the below option of creating a new table with foreign keys if you need data integrity.
- If you need to enforce referential integrity, instead of adding columns to the Customer table, add a second Table with the foreign key to the Customer table and set it as the Primary Key and then add your custom columns to that new table.