Jump to content

Sort product features in comparison


roco

Recommended Posts

You could try this:

 

Edit file /classes/CompareProduct.php, and find function:

 

 

public static function getCompareProducts($id_compare)

{

$results = Db::getInstance()->executeS('

SELECT DISTINCT `id_product`

FROM `'._DB_PREFIX_.'compare` c

LEFT JOIN `'._DB_PREFIX_.'compare_product` cp ON (cp.`id_compare` = c.`id_compare`)

WHERE cp.`id_compare` = '.(int)($id_compare).' ORDER BY id_product'); // add this (don't forget the period!)

 

$compareProducts = null;

...

}

 

 

Add the red part to it, and see if this works (don't forget the "." at the beginning of the addition!)

Not sure if this is enough, or that we need to change addCompareProduct() as well. try this first :-)

 

Pascal

 

 

Hope this helps,

Pascal

Link to comment
Share on other sites

  • 4 weeks later...

Hi,

Open classes/Feature.php

 

Find

public static function getFeaturesForComparison

 

Replace ORDER BY nb DESC with ORDER BY f.id_feature ASC here:

 

return Db::getInstance()->executeS('
  SELECT * , COUNT(*) as nb
  FROM `'._DB_PREFIX_.'feature` f
  LEFT JOIN `'._DB_PREFIX_.'feature_product` fp
ON f.`id_feature` = fp.`id_feature`
  LEFT JOIN `'._DB_PREFIX_.'feature_lang` fl
ON f.`id_feature` = fl.`id_feature`
  WHERE fp.`id_product` IN ('.$ids.')
  AND `id_lang` = '.(int)$id_lang.'
  GROUP BY f.`id_feature`
  ORDER BY f.`id_feature` ASC
 ');

 

If you want features order as set in the Back Office / Product page use

 

ORDER BY f.position ASC

 

instead

Edited by doubleD (see edit history)
  • Like 3
Link to comment
Share on other sites

  • 1 year later...
  • 4 months later...
  • 2 weeks later...

Thanks! I'm sure loving the PrestaShop way.

For any newbies, to extend the core and have your changes survive an upgrade, in PS 1.6.0.9 simply create this file in this location (to have features in the front end obey the sort order as set in the backend):

Create a new file (or if one exists, merge this function, getFeaturesForComparison, or add it) override/classes/Feature.php

<?php
/*
* 2007-2014 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to [email protected] so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
*  @author PrestaShop SA <[email protected]>
*  @copyright  2007-2014 PrestaShop SA
*  @license    http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
*  International Registered Trademark & Property of PrestaShop SA
*
*
*/

class Feature extends FeatureCore {
	public static function getFeaturesForComparison($list_ids_product, $id_lang)
	{
		if (!Feature::isFeatureActive())
			return false;

		$ids = '';
		foreach ($list_ids_product as $id)
			$ids .= (int)$id.',';

		$ids = rtrim($ids, ',');

		if (empty($ids))
			return false;

		return Db::getInstance()->executeS('
			SELECT * , COUNT(*) as nb
			FROM `'._DB_PREFIX_.'feature` f
			LEFT JOIN `'._DB_PREFIX_.'feature_product` fp
				ON f.`id_feature` = fp.`id_feature`
			LEFT JOIN `'._DB_PREFIX_.'feature_lang` fl
				ON f.`id_feature` = fl.`id_feature`
			WHERE fp.`id_product` IN ('.$ids.')
			AND `id_lang` = '.(int)$id_lang.'
			GROUP BY f.`id_feature`
			ORDER BY f.position ASC
		');
	}

}
?>

This way your changes will survive an upgrade and you will only have to monitor if the original function: "getFeaturesForComparison" in  classes/Feature.php for any rare changes (in which case you will have to do a merge, or just copy the new function as modified and search and replace:
ORDER BY nb DESC

 
WITH:
ORDER BY f.position ASC
 
Voila! :)
Link to comment
Share on other sites

  • 2 months later...
  • 1 year later...

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...