How to customize address (and any other) table ?

For general questions and discussions specific to the AbleCommerce 7.0 Asp.Net product.
Post Reply
Takitani
Ensign (ENS)
Ensign (ENS)
Posts: 8
Joined: Fri Oct 17, 2008 1:44 pm

How to customize address (and any other) table ?

Post by Takitani » Fri Oct 17, 2008 1:57 pm

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

User avatar
mazhar
Master Yoda
Master Yoda
Posts: 5084
Joined: Wed Jul 09, 2008 8:21 am
Contact:

Re: How to customize address (and any other) table ?

Post by mazhar » Sat Oct 18, 2008 8:46 am

you can use the
User.Settings.Remove(UserSetting)
method to remove the setting from user settings

Takitani
Ensign (ENS)
Ensign (ENS)
Posts: 8
Joined: Fri Oct 17, 2008 1:44 pm

Re: How to customize address (and any other) table ?

Post by Takitani » Sun Oct 19, 2008 10:28 am

Don't understand your answer. I don't want to remove any usersettings .......

User avatar
mazhar
Master Yoda
Master Yoda
Posts: 5084
Joined: Wed Jul 09, 2008 8:21 am
Contact:

Re: How to customize address (and any other) table ?

Post by mazhar » Mon Oct 20, 2008 6:16 am

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.

Code: Select all

User.Settings.Remove(UserSetting)
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.

Takitani
Ensign (ENS)
Ensign (ENS)
Posts: 8
Joined: Fri Oct 17, 2008 1:44 pm

Re: How to customize address (and any other) table ?

Post by Takitani » Mon Oct 20, 2008 8:28 am

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é.

User avatar
mazhar
Master Yoda
Master Yoda
Posts: 5084
Joined: Wed Jul 09, 2008 8:21 am
Contact:

Re: How to customize address (and any other) table ?

Post by mazhar » Mon Oct 20, 2008 8:39 am

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
                        }
                        
                    }

User avatar
mazhar
Master Yoda
Master Yoda
Posts: 5084
Joined: Wed Jul 09, 2008 8:21 am
Contact:

Re: How to customize address (and any other) table ?

Post by mazhar » Mon Oct 20, 2008 9:07 am

Better you should put a try catch block as well

Post Reply