yaniv14 Posted January 10, 2015 Share Posted January 10, 2015 (edited) Hi, I am looking for an idea on how to achieve products page pagination in category page based on categories and not by Configuration::products_per_page. I have different template layouts for different categories and I need to split them to different count. Category 1 = 5 per page. Category 2 = 12 per page. Ect..... Any help will be appreciated. Edited February 18, 2015 by yaniv14 (see edit history) Link to comment Share on other sites More sharing options...
fred-vinapresta Posted January 10, 2015 Share Posted January 10, 2015 (edited) Hi, you need to override the controllers/front/CategoryController.php file In the assignProductList functiion, you need to change $this->cat_products = $this->category->getProducts($this->context->language->id, (int)$this->p, (int)$this->n, $this->orderBy, $this->orderWay); by something like that: switch ($this->category->id) { case 1: $nb_products = 5; break; case 2: $nb_products = 10; break; ....... default: $nb_products = (int)$this->n; } $this->cat_products = $this->category->getProducts($this->context->language->id, (int)$this->p, (int)$nb_products, $this->orderBy, $this->orderWay); Edited January 10, 2015 by fred-vinapresta (see edit history) Link to comment Share on other sites More sharing options...
razaro Posted January 10, 2015 Share Posted January 10, 2015 I was thinking maybe simple module that will save pair category, number of products per category and override of FrontController paginate function but fred_vinapresta solution is more precise. Link to comment Share on other sites More sharing options...
yaniv14 Posted January 10, 2015 Author Share Posted January 10, 2015 Thank you both. I'll give it a shot once the kids go to bed. Link to comment Share on other sites More sharing options...
yaniv14 Posted January 10, 2015 Author Share Posted January 10, 2015 Hi, I am getting the desire products count per page based on the category id with your suggestion but I am not getting the actual pagination functionality. Do I need to override pagination as well or am I am missing something in the template? Thanks Link to comment Share on other sites More sharing options...
razaro Posted January 10, 2015 Share Posted January 10, 2015 Try this override, no changes to template files. Code in assignProductList is bit messy so needs improvement. And also do not forget to enable overrides and clear cache. CategoryController.php Link to comment Share on other sites More sharing options...
yaniv14 Posted January 10, 2015 Author Share Posted January 10, 2015 Thank you, Everything works like a charm. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now