Some programming questions if you have a moment to teach...

For general questions and discussions specific to the AbleCommerce 7.0 Asp.Net product.
Post Reply
User avatar
AbleMods
Master Yoda
Master Yoda
Posts: 5170
Joined: Wed Sep 26, 2007 5:47 am
Location: Fort Myers, Florida USA

Some programming questions if you have a moment to teach...

Post by AbleMods » Fri Dec 07, 2007 3:32 am

Just remember that imitation is the best form of flattery :)

After weeks of seeing AC7 code, I have learned a great deal about classes. I never used them before - my limited knowledge of VB.Net made it faster to just write tons of code rather than try wrapping my brain around the class object model concepts.

I needed a way to put all the product template ac_orderinputitem values into a single record for processing by my calculations. I wrote a function, but it pulled each entry separately so it took 9 calls to read one order. Ugly.

So I wrote my first true class for my solunar orders, and it works great.

On to my question...

I can pull up the current customers orders into a collection with...

Code: Select all

Dim _MyOrders As OrderCollection = OrderDataSource.LoadForUser(Token.Instance.UserId)
I can reference anything within the order, and even change a value and call the Save method. Sweet.

But how did you construct the OrderCollection class? Is that just another class that sub-classed the Order class and returns List(Of Class)?

My brain isn't wrapping around that part so well. What I ended up doing was...

Code: Select all

Dim _SolunarOrders As List(Of SolunarOrderInputs) = SolunarOrderDataSource.LoadforUser(Token.Instance.UserId)
This stuff gets kinda deep once you get into it, but I think I'm finally starting to grasp the concept.

I know you guys are busy, so if you don't have time that's ok - what I got works but I really see the elegance in your base class designs and I'd like to try imitating that for my stuff. Yes, that was a shameless attempt at flattery to encourage a response :)
Joe Payne
AbleCommerce Custom Programming and Modules http://www.AbleMods.com/
AbleCommerce Hosting http://www.AbleModsHosting.com/
Precise Fishing and Hunting Time Tables http://www.Solunar.com

User avatar
sohaib
Developer
Developer
Posts: 1079
Joined: Fri Jan 23, 2004 1:38 am

Post by sohaib » Fri Dec 07, 2007 8:13 am

The actual base class of all the collection classes is System.Collections.CollectionBase.

In AC we have CommerceBuilder.Common.SortableCollection which derives from CollectionBase.
All Collections for database objects derive from CommerceBuilder.Common.PersistentCollection which derives itself from SortableCollection.

OrderCollection also derives from CommerceBuilder.Common.PersistentCollection.

Collection classes support generics (or templates in other words). PersistentCollection also supports generics.

A PersistentCollection that holds Order objects will be defined something like this

Code: Select all

PersistentCollection<Order> ordersCol = new PersistentCollection<Order>();
if defined this way the ordersCol can only hold objects of type Order.

To make it more formal an OrderCollection class is defined as

Code: Select all

public class OrderCollection : PersistentCollection<Order> 
{
  //any additional methods specific to OrderCollection
}

User avatar
AbleMods
Master Yoda
Master Yoda
Posts: 5170
Joined: Wed Sep 26, 2007 5:47 am
Location: Fort Myers, Florida USA

Post by AbleMods » Sat Dec 08, 2007 6:21 pm

thanks for the info - I think I need to bone up more on CollectionBase before going deeper.

Seems like the ability to class and sub-class is remarkably useful when it's well designed. I never worked with classses in FoxPro/DBase, so the concept is still foreign to me.
Joe Payne
AbleCommerce Custom Programming and Modules http://www.AbleMods.com/
AbleCommerce Hosting http://www.AbleModsHosting.com/
Precise Fishing and Hunting Time Tables http://www.Solunar.com

User avatar
bobr2k
Commander (CMDR)
Commander (CMDR)
Posts: 183
Joined: Fri Oct 26, 2007 2:31 pm
Location: Illinois

Post by bobr2k » Sun Dec 09, 2007 2:53 pm

I love it when you guys talk dirty! (even if I don't know what you said) :lol:
Bob R.
"Bills travel through the mail at twice the speed of checks." -- Steven Wright

Post Reply