c# - How to get all Products within a Category or sub-category -
i'm trying products within 1 category, want search categoryid. want list filled products categoryid example 3.
how can this, i'm using nopcommerce 3.10.
someone on nop forum achieved using following line:
_productservice.searchproductvariants(categoryid, 0, string.empty, false, 0, int.maxvalue, false);
but since use 3.10 , productvariants replaced products, can't use this.
thanks in advance!
i figured out myself:
for products within 1 categoryid:
nopengine _engine; /// <summary> /// returns ipagedlist(product) filled products 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); }
for products:
nopengine _engine; /// <summary> /// returns ipagedlist(product) filled products, without selection /// </summary> /// <returns></returns> public ipagedlist<product> getallproducts() { _engine = new nopengine(); var _allservice = _engine.resolve<iproductservice>(); return _allservice.searchproducts(); }
Comments
Post a Comment