Filter Products by Country

For general questions and discussions specific to the AbleCommerce 7.0 Asp.Net product.
Post Reply
Gilroy
Ensign (ENS)
Ensign (ENS)
Posts: 5
Joined: Tue Jun 09, 2009 11:41 am

Filter Products by Country

Post by Gilroy » Thu Jun 18, 2009 12:11 pm

I'm in the process of extending the AbleCommerce functionality to allow our product administrators to exclude products from specific countries.

To do this, I have created a new table called ProductCountryExclusions. This is simply a cross-reference table containing the following foreign keys. ac_Products.ProductID and ac_Countries.CountryCode. I created a simple admin tool which is an extention of Edit Products which allows for the selection of the excluded countries for the specified product.

I have also integrated with MaxMind GeoIP to get the end user's country code and stored it in a session variable.

Now... the question is.... How do I override the ProductDataSource class in the CommerceBuilder Class Library so that all Methods which return a Product collection will be filtered to include only the Products that are not excluded for the current users session country code?

Any tips?

Thanks, in advance, for your feedback!

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

Re: Filter Products by Country

Post by mazhar » Fri Jun 19, 2009 5:55 am

You can not override ProductDataSouce because its in backend code. You need to replace ProductDataSource method calls with some of your custom methods which return products depending upon your custom stored information.

Gilroy
Ensign (ENS)
Ensign (ENS)
Posts: 5
Joined: Tue Jun 09, 2009 11:41 am

Re: Filter Products by Country

Post by Gilroy » Fri Jun 19, 2009 7:06 am

Thanks for the quick reply, mazhar. I do appreciate your time.

How's this for an alternative....

I can create a proprietary API, let's call it myCommerceBuilder. This API would attempt to provide extended functionality to specific AC CommerceBuilder methods, such as ProductDataSource. So, in this example, myCommerceBuilder would inherit the AC CommerceBuilder.ProductDataSource class -- exposing all the properties and methods provided therein -- and call it myProductDataSource. I could then modify myProductDataSource.Load method to call ProductDataSource.Load as normal, but put the resulting Products object in a DataTable, then filter by Country, as described earlier. myProductDataSource.Load would then return a filtered Products object.

With that... I would then just need to do a global find of all instances of "ProductDataSource" and replace with "myProductDataSource". In theory, all references to Products within AbleCommerce would then be filtered by excluded Countries.

Make sense? Workable?

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

Re: Filter Products by Country

Post by mazhar » Fri Jun 19, 2009 10:30 am

Keep in mind that If you make your custom derived class then you would need to update it every where across the store. Since your changes much related to control of display most probably all you would need to adjust some category control on product details page etc so better write some custom loader class and make use of it.

Carolharry
Commander (CMDR)
Commander (CMDR)
Posts: 121
Joined: Wed Dec 17, 2008 9:13 am

Re: Filter Products by Country

Post by Carolharry » Thu Jul 23, 2009 10:36 am

This product filering is throughout the store. For eg: filter by user country when related products,featuredproducts,upsellproducts ,productdetails page ,
when all the search results are displayed we have to filter products from that search which should not be shown in the user country.
What is the idea of having a customloader class?

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

Re: Filter Products by Country

Post by mazhar » Fri Jul 24, 2009 3:47 am

Please read following thread and read my post in it
viewtopic.php?f=42&t=10886

The trick is to first call AbleCommerce method to bring results and then again filter returned results for your custom criteria. For example in your case when you narrow your store search then filter returned products again for desired country.

Post Reply