diff --git a/src/Modules/SimplCommerce.Module.Catalog/Areas/Catalog/Components/ProductWidgetViewComponent.cs b/src/Modules/SimplCommerce.Module.Catalog/Areas/Catalog/Components/ProductWidgetViewComponent.cs index 30462c0e13..311807e4d0 100644 --- a/src/Modules/SimplCommerce.Module.Catalog/Areas/Catalog/Components/ProductWidgetViewComponent.cs +++ b/src/Modules/SimplCommerce.Module.Catalog/Areas/Catalog/Components/ProductWidgetViewComponent.cs @@ -53,11 +53,31 @@ public IViewComponentResult Invoke(WidgetInstanceViewModel widgetInstance) query = query.Where(x => x.IsFeatured); } - model.Products = query + if (model.Setting.OrderBy == ProductWidgetOrderBy.Newest) + { + query = query.OrderByDescending(p => p.CreatedOn); + } + + if (model.Setting.OrderBy == ProductWidgetOrderBy.BestSelling) + { + //TODO: ProductWidgetOrderBy.BestSelling must be managed + // create a new property in product incremented each time a product + // is created or updated or calculated how many time the products already + // ordered ? + } + + var productThumbnail = query .Include(x => x.ThumbnailImage) - .OrderByDescending(x => x.CreatedOn) - .Take(model.Setting.NumberOfProducts) - .Select(x => ProductThumbnail.FromProduct(x)).ToList(); + .Select(x => ProductThumbnail.FromProduct(x)); + + if (model.Setting.OrderBy == ProductWidgetOrderBy.Discount) + { + model.Products = model.Products.OrderByDescending(p => p.CalculatedProductPrice.PercentOfSaving).ToList(); + } + + + + model.Products = productThumbnail.Take(model.Setting.NumberOfProducts).ToList(); foreach (var product in model.Products) {