Top Selling Products

 

Hi All,


Is there any example showing how to develop code to return Top Selling Products (Best Seller)?

So if user perform a search then we can sort it by best seller rank.

#64107 Dec 11, 2012 2:48
  •  

    It´s kind of hacky, but there is an existing stored procedure that fetches entries from shipped orders.

     

                DataCommand dataCommand = OrderDataHelper.CreateTranDataCommand();
                DataParameters dataParameters = new DataParameters();
                DataSet dataSet = new DataSet();
                string query = "[dbo].[ecf_reporting_ProductBestSellers]";

                dataCommand.CommandText = query;
                dataCommand.CommandType = CommandType.StoredProcedure;
                dataParameters.Add(new DataParameter("ApplicationId", CatalogConfiguration.Instance.ApplicationId, DataParameterType.UniqueIdentifier));
                dataParameters.Add(new DataParameter("interval", "year", DataParameterType.VarChar));
                dataParameters.Add(new DataParameter("startdate", DateTime.Now.Date.AddDays(-100), DataParameterType.VarChar));
                dataParameters.Add(new DataParameter("enddate", DateTime.Now.Date, DataParameterType.VarChar));
                dataCommand.Parameters = dataParameters;
                dataCommand.DataSet = dataSet;

                DataResult dr = DataService.LoadDataSet(dataCommand);
                int[] po = new int[dataSet.Tables[0].Rows.Count];
                foreach (DataRow row in dr.DataSet.Tables[0].Rows)
                {
                    int x = (int)Math.Round(decimal.Parse(row["Ordered"].ToString()));
                    if (x != 0)
                    {
                        Console.WriteLine(row["Code"]);
                        Console.WriteLine(row["Ordered"]);
                    }
                }

    #64609 Jan 04, 2013 14:36