n13design Posted November 13, 2014 Share Posted November 13, 2014 Prestashop Documents says that the sort of the manufacturer list can not be changed. In the classes/manufacturer.php I see that the list is set to sort alphabetically. I want to sort the list by the number of products associated with each manufacturer. Can I do this in the smarty tags in the manufacturer-list.tpl? I see $manufacturer.nb_products that contains the number of products for the manufactuers. Could I add something to this tag to sort? {foreach from=$manufacturers item=manufacturer name=manufacturers } Or could I change the class or controller files to sort by number of products? Link to comment Share on other sites More sharing options...
NamPham Posted May 20, 2015 Share Posted May 20, 2015 It's easier to sort by Id_manufacturer or date_upd (ASC or DSC) You can custome change position very easy. Modify getManufacturers function in class>manufacture.php line 177 (or maybe nearby with other versions) ==> "ORDER BY m.`name` ASC" Link to comment Share on other sites More sharing options...
Sharak Posted May 24, 2019 Share Posted May 24, 2019 In case anybody is looking to sort manufacturer list on left column in prestashop 1.6 by the highest product count, here's the code to put into /override/modules/blockmanufacturer/blockmanufacturer.php (create if doesn't exist): class BlockManufacturerOverride extends BlockManufacturer { public function hookLeftColumn($params) { if (!$this->isCached('blockmanufacturer.tpl', $this->getCacheId())) { $manufacturers = Manufacturer::getManufacturers(true); if (count($manufacturers)) { usort($manufacturers, function ($a, $b) { return strnatcmp(strval($b["nb_products"]), strval($a["nb_products"])); }); } foreach ($manufacturers as &$manufacturer) { $manufacturer['image'] = $this->context->language->iso_code.'-default'; if (file_exists(_PS_MANU_IMG_DIR_.$manufacturer['id_manufacturer'].'-'.ImageType::getFormatedName('medium').'.jpg')) { $manufacturer['image'] = $manufacturer['id_manufacturer']; } } $this->smarty->assign(array( 'manufacturers' => $manufacturers, 'text_list' => Configuration::get('MANUFACTURER_DISPLAY_TEXT'), 'text_list_nb' => Configuration::get('MANUFACTURER_DISPLAY_TEXT_NB'), 'form_list' => Configuration::get('MANUFACTURER_DISPLAY_FORM'), 'display_link_manufacturer' => Configuration::get('PS_DISPLAY_SUPPLIERS'), )); } return $this->display(__FILE__, 'blockmanufacturer.tpl', $this->getCacheId()); } } 1 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