Page 1 of 1

Data Access Layer - From Wiki

Posted: Thu Nov 07, 2013 1:41 pm
by sweeperq
Able Gold has examples for the data access layer (Affiliates) in the wiki: http://wiki.ablecommerce.com/index.php/ ... _-_AC_Gold

I can't find these Affiliate files anywhere in the project, so I'm assuming they are in the core CommerceBuilder libraries.

Where are we supposed to put our classes and NHibernate mapping files for custom tables?

If we need/want to add a custom field to an existing table, how do we go about doing that?

Re: Data Access Layer - From Wiki

Posted: Fri Nov 08, 2013 12:35 am
by mazhar
You need to put your custom classes and mappings in Class Library Project. If you want to extend an existing table and expose the field in existing AbleCommerce object then you will need to make change to class and HBM file within CommerceBuilder. Have a look at this thread viewtopic.php?f=65&t=17586 where new database tables and nhibernate is discussed.

Re: Data Access Layer - From Wiki

Posted: Fri Nov 08, 2013 1:05 pm
by sweeperq
If you want to extend an existing table and expose the field in existing AbleCommerce object then you will need to make change to class and HBM file within CommerceBuilder
I presume I need to purchase the CommerceBuilder source code then?

Is there anything that isn't included/customize-able in the source code package?

If you buy the source code package, do you release updates for the source at the same time as the store/website so we can keep things up to date?

Re: Data Access Layer - From Wiki

Posted: Fri Nov 08, 2013 2:47 pm
by Shopping Cart Admin
I presume I need to purchase the CommerceBuilder source code then?
I do believe so, but Mazhar can confirm.
Is there anything that isn't included/customize-able in the source code package?
No
If you buy the source code package, do you release updates for the source at the same time as the store/website so we can keep things up to date?
Yes, it's typically released the same day as a normal release. The builds are automated.

Re: Data Access Layer - From Wiki

Posted: Sat Nov 09, 2013 6:41 am
by jmestep
I didn't have to modify Able's source code when I did what I explained in the link mazhar posted. I did that code using a custom table. If you want to add properties to one of Able's objects you would need the source code, but there are ways around that so you don't need the source code. You can do like Able does with the subcategory listing on a couple of the category page- make a new kind of object right on the page. They do something similar on the conlibs they use to display product items within a category page- they turn a product into something called Item.

Re: Data Access Layer - From Wiki

Posted: Mon Nov 11, 2013 12:21 pm
by sweeperq
Thanks, will look into it.

Re: Data Access Layer - From Wiki

Posted: Thu Jan 09, 2014 3:47 pm
by sweeperq
Judy, I just took a look at the CategoryGridPage and to see if I could find what you were talking about. I found SubCategoryData, but that is kind of different because SubCategoryData isn't persisting anything to the database; it is basically being used as a View Model for the SubCategoryRepeater.

Be cool if there was a Settings or CustomFields property on all the entities that could be populated when the main object loaded (as opposed to lazy load and firing a query on demand). Hardly anybody would need access to the source then.

Re: Data Access Layer - From Wiki

Posted: Fri Jan 10, 2014 8:36 am
by AbleMods
sweeperq wrote:Be cool if there was a Settings or CustomFields property on all the entities that could be populated when the main object loaded (as opposed to lazy load and firing a query on demand). Hardly anybody would need access to the source then.
This is easy to accomplish (indirectly) using the CustomField class. However you wouldn't want child objects queried on every load of the parent object - that would slam the SQL server unnecessarily and potentially slow the whole site down.

Let's say you have a category with ID 288 and want to store a custom field with it called 'Explosive'.

To persist a custom field, do this:

Code: Select all

            CustomField newField = new CustomField();
            newField.FieldName = "Explosive";
            newField.FieldValue = "Yes";
            newField.ForeignKeyId = 288;
            newField.TableName = "ac_Categories";
            AbleContext.Current.Database.BeginTransaction();
            newField.Save();
            AbleContext.Current.Database.CommitTransaction();
Now when you want to read the custom field back in within a category page user control:

Code: Select all

            IList<CustomField> customFields = NHibernateHelper.CreateCriteria<CustomField>()
                .Add(Restrictions.Eq("TableName", "ac_Categories"))
                .Add(Restrictions.Eq("FieldName", "Explosive"))
                .Add(Restrictions.Eq("ForeignKeyId", categoryId))
                .List<CustomField>();

            if (customFields.Count > 0)
            {
                string fieldValue = customFields[0].FieldValue;
            }
Note how I'm passing the variable categoryId as the parameter in the nHibernate query. This is presumed to be populated already by the user control driving your category display page.

Gets much easier once you build a helper class to handle the heaving lifting above.