When writing AC Gold API we had this thing in mind and we tried our best to keep it backward compatible to preserve most of the custom codes done by end users. There are few major changes and higher chances are that most of the AC7 codes can simply be converted to AC Gold by making these few adjustments.
I am going to explain the changes which are likely to be most common reason for problems you are facing.
1. Token.Instance is changed to AbleContext.Current
Chances are you will be seeing the following error
Error: The name 'Token' does not exist in the current context
In AC 7 we had Token object that provided access on store context. For example like Token.Instance.UserId, Token.Instance.Store etc. This is changed in AC Gold and now you need to use AbleContext.Current to get store context. This the most common error you will see during the porting work and its fix is very simple. Just change Token.Instance => AbleContext.Current
Follwoing code will demonstrante the coding style for both AC 7 and AC GOLD to explain the differance.
Code: Select all
// AC 7
Store = Token.Instance.Store;
// AC 8
Store = AbleContext.Current.Store;
Chances are you you will be seeing the following error
Error: The type or namespace name 'StoreSettingCollection' could not be found (are you missing a using directive or an assembly reference?)
AC 7 had StoreSettingCollection which gave access on store wide settings. This was strongly typed collection class which had properties on it to set/get store settings. In AC Gold we no longer have strongly typed collection class so StoreSettingCollection is replaced by StoreSettingsManager class. In order to fix this broken piece of code all you need is to change StoreSettingCollection => StoreSettingsManager.
Following code will demonstrate coding style for both AC 7 and AC Gold
Code: Select all
// AC 7
StoreSettingCollection settings = Token.Instance.Store.Settings;
// AC Gold
StoreSettingsManager settings = AbleContext.Current.Store.Settings;
3. No more strongly typed collection classes, instead Gold is using generic lists
Chances are you will be seeing the following error
Error: The type or namespace name '___Collection' could not be found (are you missing a using directive or an assembly reference?)
where ___ can be any entity classs for example Product, Order, Coupon.
AC 7 had strongly typed collection classes to hold 0 or more objects of specific entity class. For example ProductCollection to contain list of products, OrderCollection to contain list of orders etc. This resulted in lot of code files for those collection classes in AC7. In AC gold we using generic lists which are allowing us compile time type safety without separate collection code file for each object. You can fix broken code suffering from this change very easily using following trick.
Simply remove the word Collection from variable declaration and wrap rest of it in IList<---> where --- will be entity type name left after removal of word collection.
Following code demonstrate coding style for AC 7 and AC Gold
Code: Select all
// AC 7
ProductCollection products = ProductDataSource.LoadForCategory(1, false);
// AC Gold
IList<Product> products = ProductDataSource.LoadForCategory(1, false);
Chances are you will be seeing the following error
Error: Argument 1: cannot convert from 'string' to 'NHibernate.ICriteria'
This is bit difficult. In AC 7 we had LoadForCriteria method that used to take where clause string to allow an easy way to quickly run your query having simple where restrictions. In AC Gold since we are using NHibernate this LoadForCriteria now takes Nhibernate ICriteria object. In order to fix it you will have to build and pass nhibernate criteria. If you ever found yourself in this situation i would suggest that you better create and run the criteria object your self instead of passing it to LoadForCriteria it really doesn't make much of difference any beside executing and returning the results. Following code will demonstrate about custom criteria based query in AC 7 and AC Gold.
Code: Select all
// AC 7
ProductCollection products = ProductDataSource.LoadForCriteria("Name LIKE %apple%");
// AC Gold
IList<Product> products = NHibernateHelper.CreateCriteria<Product>()
.Add(Restrictions.Like("Name", "apple", MatchMode.Anywhere))
.List<Product>();
Code: Select all
// AC 7
LSDecimal price = product.Price;
// AC Gold
decimal price = product.Price;