【问题标题】:How to get all Products within a Category or sub-category如何获取类别或子类别中的所有产品
【发布时间】:2013-08-15 14:54:58
【问题描述】:

我正在尝试获取一个类别中的所有产品,我想按 CategoryId 进行搜索。所以我想得到一个列表,其中包含 categoryId 为例如 3 的所有产品。

我该怎么做,我使用的是 NopCommerce 3.10。

Nop 论坛上的某个人使用以下行实现了它:

_productService.SearchProductVariants(categoryId, 0, string.Empty, false, 0, int.MaxValue, false);

但是由于我使用的是 3.10 并且 ProductVariants 被 Products 替换了,所以我不能使用这个。

提前致谢!

【问题讨论】:

  • 返回的结果是否会返回一个 IEnumerable?取回结果后,您或许可以使用 LINQ?
  • 我正在使用 NopCommerce,必须有一种方法可以用来返回这些值,但我不知道在哪个类中。

标签: c# visual-studio nopcommerce


【解决方案1】:

我自己想通了:

对于 1 个 categoryid 内的所有产品:

        NopEngine _engine;
        /// <summary>
        /// Returns IPagedList(Product) filled with all products from selected CategoryId
        /// </summary>
        /// <param name="Categoryid"></param>
        /// <returns></returns>
        public IPagedList<Product> GetAllProductsFromCategory(int Categoryid)
        {
            _engine = new NopEngine();
            var _productService = _engine.Resolve<IProductService>();
            List<int> CategoryIds = new List<int>();
            CategoryIds.Add(Categoryid);
            return _productService.SearchProducts(categoryIds: CategoryIds);
        }

对于所有产品:

        NopEngine _engine;
        /// <summary>
        /// Returns IPagedList(Product) filled with all products, without selection
        /// </summary>
        /// <returns></returns>
        public IPagedList<Product> GetAllProducts()
        {
            _engine = new NopEngine();
            var _allService = _engine.Resolve<IProductService>();
            return _allService.SearchProducts();
        }

【讨论】:

  • 当我调用 _engine.Resolve();
  • 你在执行那句话之前是否添加了:NopEngine _engine = new NopEngine();
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-09-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-06-17
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多