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!
Filter Products by Country
Re: Filter Products by Country
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.
Re: Filter Products by Country
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?
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?
Re: Filter Products by Country
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.
-
- Commander (CMDR)
- Posts: 121
- Joined: Wed Dec 17, 2008 9:13 am
Re: Filter Products by Country
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?
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?
Re: Filter Products by Country
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.
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.