【问题标题】:NopCommerce : Display best seller products on category home pageNopCommerce:在类别主页上显示畅销产品
【发布时间】:2014-03-27 03:53:57
【问题描述】:

我正在使用 NopCommerce。我想在类别主页上显示前 3 名畅销产品。

我知道在视图端 CategoryTemplate.ProductsInGridOrLines.cshtml 和控制器端 CatalogController.cs > HomepageBestSellers 方法被使用。

我已将类别 ID 作为参数传递给 HomepageBestSellers 方法。此类别 ID 作为参数传递给 BestSellersReport 方法。

我的问题是如何使用类别 ID 在类别主页上显示畅销产品?

【问题讨论】:

    标签: asp.net-mvc-4 nopcommerce


    【解决方案1】:
    1. 您应该为畅销书创建一个新的操作方法,您将在其中传递类别 ID。
    2. 在这种方法中,您应该使用 BestSellersReport 方法,如下所示:

      _orderReportService.BestSellersReport(storeId: _storeContext.CurrentStore.Id, categoryId: categoryId)

    3. 这个新方法与 CatalogController 中的 HomepageBestSellers 非常相似。看看它是如何完成的。

    4. 您应该创建一个视图,例如 Views\Catalog\HomepageBestSellers.cshtml 并将其显示在您需要的位置。

    【讨论】:

    • 你能告诉我如何使用查询将类别表与订单表连接起来吗?
    • 你为什么要这样做?
    • 我只想展示该特定类别的畅销产品。
    • 按照我写的说明进行操作。不再需要做任何事情。查看 HomepageBestSellers 方法 - 您的代码应该与它非常相似。
    • _orderReportService.BestSellersReport(storeId: _storeContext.CurrentStore.Id, categoryId: categoryId)。这里的categoryId表示仅针对具有此id的类别显示产品。
    【解决方案2】:

    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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多