Page 1 of 1
How to customize address (and any other) table ?
Posted: Fri Oct 17, 2008 1:57 pm
by Takitani
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
Re: How to customize address (and any other) table ?
Posted: Sat Oct 18, 2008 8:46 am
by mazhar
you can use the
User.Settings.Remove(UserSetting)
method to remove the setting from user settings
Re: How to customize address (and any other) table ?
Posted: Sun Oct 19, 2008 10:28 am
by Takitani
Don't understand your answer. I don't want to remove any usersettings .......
Re: How to customize address (and any other) table ?
Posted: Mon Oct 20, 2008 6:16 am
by mazhar
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 ?
You can use the Remove method in order to remove any setting that you previously saved.
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 ?
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.
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();
Similarly when reading you can first create the address key by combining the current address address id and word "ADD" and then use this key to get the store value for that address from current user.
Re: How to customize address (and any other) table ?
Posted: Mon Oct 20, 2008 8:28 am
by Takitani
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é.
Re: How to customize address (and any other) table ?
Posted: Mon Oct 20, 2008 8:39 am
by mazhar
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 ?
Posted: Mon Oct 20, 2008 9:07 am
by mazhar
Better you should put a try catch block as well