SuperCharlie Posted August 13, 2012 Share Posted August 13, 2012 (edited) Thought Id share this quick nugget. There is a global sort option in the admin but I wanted the regular categories to sort by category order and for new products to sort by last date added.. so I made this tweak. In controllers/NewProductsController.php around line 47 you will find this.. 'products' => Product::getNewProducts((int)(self::$cookie->id_lang), (int)($this->p) - 1, (int)($this->n), false, $this->orderBy, $this->orderWay), Change the end of it like this for great sorting victory.. 'products' => Product::getNewProducts((int)(self::$cookie->id_lang), (int)($this->p) - 1, (int)($this->n), false, 'date_add', 'DESC'), Remember to back up Will probably not make it thru an upgrade/update Works for me, your mileage may vary. SC Update: I just realized this will disable any other sorting.. so there ya go.. Edited August 13, 2012 by SuperCharlie (see edit history) 2 Link to comment Share on other sites More sharing options...
patrikar Posted August 11, 2014 Share Posted August 11, 2014 As SuperCharlie realized in the update to his post, the solution disables other sorting on the New products page. How to show newest first on New Products AND still have other sorting available 1. If you have done the edits described in SuperCharlies post, undo them! 2. Open up /override/controllers/front/NewProductsController.php and make it look like this: <?php class NewProductsController extends NewProductsControllerCore { /** * Assign template vars related to page content * @see FrontController::initContent() */ public function initContent() { parent::initContent(); $this->productSort(); $nbProducts = (int)Product::getNewProducts( $this->context->language->id, (isset($this->p) ? (int)($this->p) - 1 : null), (isset($this->n) ? (int)($this->n) : null), true ); $this->pagination($nbProducts); if( ( empty($this->orderBy) || $this->orderBy == 'position' ) && ( empty($this->orderWay) || $this->orderWay == 'asc' ) ) { $this->context->smarty->assign(array( //'products' => Product::getNewProducts($this->context->language->id, (int)($this->p) - 1, (int)($this->n), false, $this->orderBy, $this->orderWay), 'products' => Product::getNewProducts($this->context->language->id, (int)($this->p) - 1, (int)($this->n), false, 'date_add', 'DESC'), 'add_prod_display' => Configuration::get('PS_ATTRIBUTE_CATEGORY_DISPLAY'), 'nbProducts' => (int)($nbProducts), 'homeSize' => Image::getSize('home_default'), 'comparator_max_item' => Configuration::get('PS_COMPARATOR_MAX_ITEM') )); } else { $this->context->smarty->assign(array( 'products' => Product::getNewProducts($this->context->language->id, (int)($this->p) - 1, (int)($this->n), false, $this->orderBy, $this->orderWay), //'products' => Product::getNewProducts($this->context->language->id, (int)($this->p) - 1, (int)($this->n), false, 'date_add', 'DESC'), 'add_prod_display' => Configuration::get('PS_ATTRIBUTE_CATEGORY_DISPLAY'), 'nbProducts' => (int)($nbProducts), 'homeSize' => Image::getSize('home_default'), 'comparator_max_item' => Configuration::get('PS_COMPARATOR_MAX_ITEM') )); } $this->setTemplate(_PS_THEME_DIR_.'new-products.tpl'); } } 3. Upload the new file, finito! Extra: This adds a check so that SuperCharlies fix is applied only when the "default" order is in place. Thanks SuperCharlie and good luck to all of you! I've tested this on 1.5.2.0. Link to comment Share on other sites More sharing options...
motion2082 Posted April 20, 2015 Share Posted April 20, 2015 Will this work on Version 1.6.0.14? 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