2014-02-25 64 views
5

我正在使用NopCommerce。我想在類別主頁上顯示前3名暢銷產品。NopCommerce:在類別主頁上顯示暢銷產品

我有一個想法,在視圖方面CategoryTemplate.ProductsInGridOrLines.cshtml和控制器端CatalogController.cs > HomepageBestSellers方法被使用。

我已經將類別id作爲參數傳遞給了HomepageBestSellers方法。此類別ID作爲參數傳遞給BestSellersReport方法。

我的問題是如何使用類別ID在類別主頁上顯示暢銷產品?

回答

7
  1. 您應該爲暢銷書創建一個新的操作方法,其中您將傳遞類別標識。
  2. 在這種方法中,你應該使用BestSellersReport方法喜歡這裏:

    _orderReportService.BestSellersReport(STOREID:_storeContext.CurrentStore.Id,的categoryId:的categoryId)

  3. 這種新方法是非常相似HomepageBestSellers CatalogController。看看它是如何完成的。

  4. 而且您應該創建一個視圖,如Views \ Catalog \ HomepageBestSellers.cshtml並將其顯示在您需要的位置。
+0

首先感謝您的回答... – Tushar

+0

可以請你告訴我怎樣可以使用查詢加入類別表順序表? – Tushar

+0

你爲什麼要這樣做? – mariann

0

暢銷產品代碼在NopeCommerce

#region bestsellers and products 

     [ChildActionOnly] 
     public ActionResult BestSellProduct(int categoryId) 
     { 

      //load and cache report 
      var report = _orderReportService.BestSellersReport(storeId: _storeContext.CurrentStore.Id, categoryId: categoryId); 


      //load products 
      var products = _productService.GetProductsByIds(report.Select(x => x.ProductId).ToArray()); 
      //ACL and store mapping 
      products = products.Where(p => _aclService.Authorize(p) && _storeMappingService.Authorize(p)).ToList(); 
      //availability dates 
      products = products.Where(p => p.IsAvailable()).ToList(); 

      if (!products.Any()) 
       return Content(""); 

      //prepare model 
      var model = PrepareProductOverviewModels(products, true, true, categoryId).ToList(); 
      return PartialView(model); 
     } 
     #endregion 
相關問題