Page 1 of 1

Popular Products are showing random order?

Posted: Wed May 15, 2013 12:18 pm
by BWalt302
Ok, so I am trying to get my products to display in order from best selling to lowest selling (best being first, and lowest selling on bottom of page)

I have used : ProductList.DataSource = ProductDataSource.GetPopularProducts(_MaxItems,_CategoryId); - Everything is working great, except each time I load the page, the products are showing in random order?!?

It is pulling from the right category and only showing what I have defined my max items to be, just doesn't appear to be working the way I need it to. Any suggestions?

The way I call the script is:[[ConLib:custom/bestsell CategoryId="120" Caption="Best Sellers" MaxItems="360"]]

Re: Popular Products are showing random order?

Posted: Wed May 15, 2013 12:26 pm
by BWalt302
I also was trying to figure something out maybe using this method: //ProductList.DataSource = ProductDataSource.LoadForCriteria(_CatrgoryID,_MaxItems,0,"OrderCount DESC"); no luck though...

Possibly I believe I could somehow pull the order count from the database and just put it inline with my code...

("SELECT P.ProductId AS ProductId, COUNT(OI.ProductId) AS OrderCount FROM ac_OrderItems AS OI RIGHT OUTER JOIN ac_Products AS P ON OI.ProductId = P.ProductId WHERE P.ProductId IN ({0}) GROUP BY OI.ProductId, P.ProductId ORDER BY OrderCount DESC",productIds)

Re: Popular Products are showing random order?

Posted: Thu May 16, 2013 4:59 am
by ForumsAdmin
Popular products control does not display products randomly. The ones that are purchased most are shown first. The order by clause uses something like this

Code: Select all

 ORDER BY SUM(ac_OrderItems.Quantity) DESC 

Re: Popular Products are showing random order?

Posted: Thu May 16, 2013 5:37 am
by BWalt302
I dont know whats going on then, because my code //ProductList.DataSource = ProductDataSource.GetPopularProducts(_MaxItems,_CategoryId);
is displaying products, but it is not picking up the correct category, and it is showing them in different order every time.

How would I implement the loadforcriteria to replace: ProductList.DataSource = ProductDataSource.NarrowSearch("",_CategoryId,0,0,0,_MaxItems,0,"ProductId");
to only show best sellers form that category in order

Re: Popular Products are showing random order?

Posted: Thu May 16, 2013 5:54 am
by jmestep
In Gold, you can't pass scriplet parameters anymore like this that you could do in Able 7

Code: Select all

[[ConLib:custom/bestsell CategoryId="120" Caption="Best Sellers" MaxItems="360"]]
You have to do it in the master page, like Layouts/ThreeColumn.Master

Code: Select all

<uc:PopularProductsDialog ID="PopularProductsDialogRight" MaxItems="360" runat="server" />
You can't pass a category id unless you have customized it.

Re: Popular Products are showing random order?

Posted: Thu May 16, 2013 6:55 am
by BWalt302
I am actually using able commerce 7.

The issue is that I have 3 different categories on the home page that I am pulling product from. So I have the code 3 times with 3 different cats: such as

[[ConLib:custom/bestsell CategoryId="2" Caption="Best Sellers" MaxItems="360"]]

[[ConLib:custom/bestsell CategoryId="16" Caption="Best Sellers" MaxItems="360"]]

[[ConLib:custom/bestsell CategoryId="3" Caption="Best Sellers" MaxItems="360"]]

PopularProducts is pulling from both the parent and all subs before determining (randomly) which ones to display, so I think I need to use a SQL statement, and pull each category and sort via OrderCount method... how would I go about this.

Re: Popular Products are showing random order?

Posted: Thu May 16, 2013 6:59 am
by BWalt302
Is there a way I could implement an SQL query (SELECT P.ProductId AS ProductId, COUNT(OI.ProductId) AS OrderCount FROM ac_OrderItems AS OI RIGHT OUTER JOIN ac_Products AS P ON OI.ProductId = P.ProductId WHERE P.ProductId IN ({0}) GROUP BY OI.ProductId, P.ProductId ORDER BY OrderCount DESC",productIds)

such as the one above and pull it based on results?

Re: Popular Products are showing random order?

Posted: Tue May 21, 2013 9:45 am
by BWalt302
Anyone? Still needing help with this.

Re: Popular Products are showing random order?

Posted: Wed May 22, 2013 5:20 am
by jmestep
You could try this method and see if it works before you do custom sql
GetPopularProductsByCategory(int categoryId, int limit)

If you need to do custom sql, this article will point you in the right direction.
http://wiki.ablecommerce.com/index.php/Custom_Queries

Re: Popular Products are showing random order?

Posted: Thu May 23, 2013 2:42 pm
by BWalt302
I tried that, and unfortunately it is still displaying them in a different order each page load.