thanos panousis
thanos panousis

Reputation: 464

Kentico Ecommerce: getting top selling categories

I am using Kentico 7.0, ecommerce version.

I would like to create a sidebar menu that shows the eshop's top selling product categories. I am a kentico newbie so I am looking around for the correct terminology/guidance so that I can dig deeper.

The ideal approach in my opinion would be to be able to add a field on categories, which is used to filter categories for the menu. This way I can either have some kind of job that updates the fields automatically based on sales, OR provide a manual override for an admin to specify whether a category will show up on the menu. Of course some kind of weight would also be needed to specify menu item ordering.

Which way should I look?

Upvotes: 2

Views: 299

Answers (2)

Ben E G
Ben E G

Reputation: 971

There are many ways to code for Kentico. I personally find the API is a bit clunky and on quite a few occasions I was surprised that a method didn't exist requiring extra calls to get the required results. I do use the Kentico API more when putting data in to Kentico. Pulling it out I use the following.

STORED PROC

Write a SQL stored procedure to get the top X categories - GetTop5Categories.

Look at the COM_* tables, specifically COM_OrderItem, linking OrderItemSKUID back to COM_SKU (or View_COM_SKU_Joined if you need to get to the IA).

This will get you the top selling products with a group by, a count, a top X and an order by.

Then you can link to other tables such as CMS_Category or CMS_Document (depending on how you setup your categories). The bonus of this is that procs are compiled, you do all your data manipulation there (it's what MSSQL specialises in!) and you only send back what you need to in the result set.

DOMAIN (leveraging EF)

I usually create a separate class library project myproject.domain and put an Entity Framework edmx in there mapped back to the Kentico DB. Add the proc to the EDMX, then create a Function Import MyProject_GetTop5Categories from your newly imported proc.

WEB

add a reference to the domain project from your web project, and a 'using at the top of the codebehind of the control.

using myproject.domain;

then in Page_Load for the control:

...

if(!IsPostBack)
{

var entities = new MyProjectModelContainer();
var list = entities.MyProject_GetTop5Categories().ToList();
StringBuilder sb = new StringBuilder("<ul>");
foreach(var category in list)
{
   sb.Append("<li><a href='"+category.Link+"'>" + category.Name + "</a></li>");
}
sb.Append("<ul>");

listPlaceHolder = sb.ToString();

}

handwritten so probably a typo or two in there :)

HTH

Upvotes: 1

jurajo
jurajo

Reputation: 995

HAve you tried using the "Top N products by sales" web part that is available? you can configure from which part of the content tree (products) it should pull the data - in the Path property you can use also a path expression or macro that is resolved dynamically so the web part can display different products in different sections.

Upvotes: 1

Related Questions