Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fetch with upsteam #1033

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down