Skip to content

Commit 5dce098

Browse files
committed
Minor refactoring
1 parent 0698fe4 commit 5dce098

3 files changed

Lines changed: 26 additions & 25 deletions

File tree

src/Libraries/SmartStore.Services/Catalog/ProductService.cs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -204,17 +204,13 @@ public virtual IList<Product> GetProductsByIds(int[] productIds)
204204
where productIds.Contains(p.Id)
205205
select p;
206206
var products = query.ToList();
207-
208-
//sort by passed identifiers
209-
var sortedProducts = new List<Product>();
210207

211-
foreach (int id in productIds)
212-
{
213-
var product = products.Find(x => x.Id == id);
214-
if (product != null)
215-
sortedProducts.Add(product);
216-
}
217-
return sortedProducts;
208+
// sort by passed identifier sequence
209+
var sortQuery = from i in productIds
210+
join p in products on i equals p.Id
211+
select p;
212+
213+
return sortQuery.ToList();
218214
}
219215

220216
/// <summary>

src/Presentation/SmartStore.Web/Controllers/CatalogController.cs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -642,16 +642,20 @@ public ActionResult HomepageBestSellers(int? productThumbPictureSize)
642642
if (!_catalogSettings.ShowBestsellersOnHomepage || _catalogSettings.NumberOfBestsellersOnHomepage == 0)
643643
return Content("");
644644

645-
//load and cache report
646-
var report = _services.Cache.Get(string.Format(ModelCacheEventConsumer.HOMEPAGE_BESTSELLERS_IDS_KEY, _services.StoreContext.CurrentStore.Id), () =>
647-
_orderReportService.BestSellersReport(_services.StoreContext.CurrentStore.Id, null, null, null, null, null, 0, _catalogSettings.NumberOfBestsellersOnHomepage));
645+
// load and cache report
646+
var report = _services.Cache.Get(string.Format(ModelCacheEventConsumer.HOMEPAGE_BESTSELLERS_IDS_KEY, _services.StoreContext.CurrentStore.Id), () =>
647+
{
648+
return _orderReportService.BestSellersReport(_services.StoreContext.CurrentStore.Id, null, null, null, null, null, 0, _catalogSettings.NumberOfBestsellersOnHomepage);
649+
});
648650

649-
//load products
651+
// load products
650652
var products = _productService.GetProductsByIds(report.Select(x => x.ProductId).ToArray());
651-
//ACL and store mapping
653+
654+
// ACL and store mapping
652655
products = products.Where(p => _aclService.Authorize(p) && _storeMappingService.Authorize(p)).ToList();
653-
//prepare model
654-
var model = new HomePageBestsellersModel()
656+
657+
// prepare model
658+
var model = new HomePageBestsellersModel
655659
{
656660
UseSmallProductBox = _catalogSettings.UseSmallProductBoxOnHomePage,
657661
Products = _helper.PrepareProductOverviewModels(products, true, true, productThumbPictureSize).ToList()

src/Presentation/SmartStore.Web/Controllers/ProductController.cs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -450,21 +450,22 @@ public ActionResult ProductsAlsoPurchased(int productId, int? productThumbPictur
450450
if (!_catalogSettings.ProductsAlsoPurchasedEnabled)
451451
return Content("");
452452

453-
//load and cache report
454-
var productIds = _services.Cache.Get(string.Format(ModelCacheEventConsumer.PRODUCTS_ALSO_PURCHASED_IDS_KEY, productId, _services.StoreContext.CurrentStore.Id), () =>
455-
_orderReportService
456-
.GetAlsoPurchasedProductsIds(_services.StoreContext.CurrentStore.Id, productId, _catalogSettings.ProductsAlsoPurchasedNumber)
457-
);
453+
// load and cache report
454+
var productIds = _services.Cache.Get(string.Format(ModelCacheEventConsumer.PRODUCTS_ALSO_PURCHASED_IDS_KEY, productId, _services.StoreContext.CurrentStore.Id), () =>
455+
{
456+
return _orderReportService.GetAlsoPurchasedProductsIds(_services.StoreContext.CurrentStore.Id, productId, _catalogSettings.ProductsAlsoPurchasedNumber);
457+
});
458458

459-
//load products
459+
// load products
460460
var products = _productService.GetProductsByIds(productIds);
461-
//ACL and store mapping
461+
462+
// ACL and store mapping
462463
products = products.Where(p => _aclService.Authorize(p) && _storeMappingService.Authorize(p)).ToList();
463464

464465
if (products.Count == 0)
465466
return Content("");
466467

467-
//prepare model
468+
// prepare model
468469
var model = _helper.PrepareProductOverviewModels(products, true, true, productThumbPictureSize).ToList();
469470

470471
return PartialView(model);

0 commit comments

Comments
 (0)