How to customize address (and any other) table ?
How to customize address (and any other) table ?
Hi, I'm starting to work on a customization of AbleCommerce and I need to add custom fields to the Address table.
How is the best way to accomplish this ?
Another question, we extend the User with another fields using the UserSettings engine. My user save method is something like this:
MembershipCreateStatus status;
User newUser = UserDataSource.CreateUser(UserName.Text, Password.Text, string.Empty, string.Empty, true, 0, out status);
UserSetting s = new UserSetting();
s.FieldName = "eye-color";
s.FieldValue = "blue";
newUser.Settings.Add(s);
newUser.Save();
Can i control the transaction scope of CommerceBuilder API ? How to rollback the created user if a fail occurs when create the user custom fields ?
Thanks!
Takitani
How is the best way to accomplish this ?
Another question, we extend the User with another fields using the UserSettings engine. My user save method is something like this:
MembershipCreateStatus status;
User newUser = UserDataSource.CreateUser(UserName.Text, Password.Text, string.Empty, string.Empty, true, 0, out status);
UserSetting s = new UserSetting();
s.FieldName = "eye-color";
s.FieldValue = "blue";
newUser.Settings.Add(s);
newUser.Save();
Can i control the transaction scope of CommerceBuilder API ? How to rollback the created user if a fail occurs when create the user custom fields ?
Thanks!
Takitani
Re: How to customize address (and any other) table ?
you can use the
method to remove the setting from user settingsUser.Settings.Remove(UserSetting)
Re: How to customize address (and any other) table ?
Don't understand your answer. I don't want to remove any usersettings .......
Re: How to customize address (and any other) table ?
You can use the Remove method in order to remove any setting that you previously saved.Can i control the transaction scope of CommerceBuilder API ? How to rollback the created user if a fail occurs when create the user custom fields ?
Code: Select all
User.Settings.Remove(UserSetting)
Well the best way would be that you carried out your job without modifying the the tables created by AbleCommerce. May be by creating your own tables etc.Hi, I'm starting to work on a customization of AbleCommerce and I need to add custom fields to the Address table.
How is the best way to accomplish this ?
You can also try a workaround. If you need to store small amount of extra information with the address, for example if you just need one extra column. Then may be you first give a try to user settings. For example when saving the address you can check that weather the address is saved properly. And if it is saved properly then save the extra field information into user settings by first creating a unique key that correspond to the currently modified address.
For example the pseudo code will be something like
Code: Select all
if address.Save is OK)
then
-addresskey as string
-addresskey = "ADD"+address.AddressId;
-Create a User Setting setting
-setting.FieldName = addresskey
-setting.FieldValue = extra info
-CurrentUser.Settings.Add(setting);
-CurrUser.Save();
Re: How to customize address (and any other) table ?
I understand u point.
U tell me to use something like this:
UserSetting s = new UserSetting();
s.FieldName = "1|AddressCustomField";
s.FieldValue = "something here for addressid 1";
s.FieldName = "2|AddressCustomField";
s.FieldValue = "something here for addressid 2";
newUser.Settings.Add(s);
newUser.Save();
Yes ? If yes, how can i control the transaction if a error occurs when insert custom data ?
My Code:
MembershipCreateStatus status;
newUser = UserDataSource.CreateUser(Email.Text, Password.Text, string.Empty, string.Empty, true, 0, out status);
if (status == MembershipCreateStatus.Success)
{
//MIGRATE USER IF NEEDED
if ((Token.Instance.UserId != newUser.UserId) && (newUser.UserId != 0))
{
User.Migrate(Token.Instance.User, newUser);
Token.Instance.UserId = newUser.UserId;
}
UserSetting s = new UserSetting();
s.FieldName = "1|AddressCustomField";
s.FieldValue = "something here for addressid 1";
s.FieldName = "2|AddressCustomField";
s.FieldValue = "something here for addressid 2";
newUser.Settings.Add(s);
newUser.Save();
//ERROR HERE, NEED TO ROLLBACK USER INSERT, HOW ?
}
Thanks,
André.
U tell me to use something like this:
UserSetting s = new UserSetting();
s.FieldName = "1|AddressCustomField";
s.FieldValue = "something here for addressid 1";
s.FieldName = "2|AddressCustomField";
s.FieldValue = "something here for addressid 2";
newUser.Settings.Add(s);
newUser.Save();
Yes ? If yes, how can i control the transaction if a error occurs when insert custom data ?
My Code:
MembershipCreateStatus status;
newUser = UserDataSource.CreateUser(Email.Text, Password.Text, string.Empty, string.Empty, true, 0, out status);
if (status == MembershipCreateStatus.Success)
{
//MIGRATE USER IF NEEDED
if ((Token.Instance.UserId != newUser.UserId) && (newUser.UserId != 0))
{
User.Migrate(Token.Instance.User, newUser);
Token.Instance.UserId = newUser.UserId;
}
UserSetting s = new UserSetting();
s.FieldName = "1|AddressCustomField";
s.FieldValue = "something here for addressid 1";
s.FieldName = "2|AddressCustomField";
s.FieldValue = "something here for addressid 2";
newUser.Settings.Add(s);
newUser.Save();
//ERROR HERE, NEED TO ROLLBACK USER INSERT, HOW ?
}
Thanks,
André.
Re: How to customize address (and any other) table ?
You can wrap the user.Save() call into an if statement. Checking the result of the save operation. If you got a operation failed result then you can check the user settings and if setting do exist there just remove it or change its value to null etc.
Code: Select all
if (newUser.Save() == SaveResult.Failed)
{
if(newUser.Settings.Contains(s))
{
//Rollback code here
}
}
Re: How to customize address (and any other) table ?
Better you should put a try catch block as well