Jump to content

Sorting Features on Product Page


derthis

Recommended Posts

Hi Everyone,

 

I try to sort features on product page, I found out that they are generated by this function:

 

public static function getFrontFeaturesStatic($id_lang, $id_product)
{
 if (!array_key_exists($id_product.'-'.$id_lang, self::$_frontFeaturesCache))
 {
  self::$_frontFeaturesCache[$id_product.'-'.$id_lang] = Db::getInstance()->ExecuteS('
  SELECT name, cat, value, pf.id_feature
  FROM '._DB_PREFIX_.'feature_product pf
  LEFT JOIN '._DB_PREFIX_.'feature_lang fl ON (fl.id_feature = pf.id_feature AND fl.id_lang = '.(int)$id_lang.')
  LEFT JOIN '._DB_PREFIX_.'feature_value_lang fvl ON (fvl.id_feature_value = pf.id_feature_value AND fvl.id_lang = '.(int)$id_lang.')
  WHERE pf.id_product = '.(int)$id_product);
 }
 return self::$_frontFeaturesCache[$id_product.'-'.$id_lang];
}

 

However, if I try to add 'ORDER BY ' clause at the end of the query, it breaks and shows either 'A A' or nothing. Even if I try to add a whitespace after WHERE clause, meaning:

 

WHERE pf.id_product = '.(int)$id_product).' ';

 

It breaks! How is it possible?

How to make this query editable?

 

Thanks for your comments.

Link to comment
Share on other sites

Silly me.

 

I missed that one last bracket.

 

So, if you want to sort your features by name, you can edit classes/Product.php and on line 2752, there you have to modify this query accordingly:

 

  self::$_frontFeaturesCache[$id_product.'-'.$id_lang] = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
  SELECT name, value, pf.id_feature
  FROM '._DB_PREFIX_.'feature_product pf
  LEFT JOIN '._DB_PREFIX_.'feature_lang fl ON (fl.id_feature = pf.id_feature AND fl.id_lang = '.(int)$id_lang.')
  LEFT JOIN '._DB_PREFIX_.'feature_value_lang fvl ON (fvl.id_feature_value = pf.id_feature_value AND fvl.id_lang = '.(int)$id_lang.')
  WHERE pf.id_product = '.(int)$id_product.'
  ORDER BY name ASC');

 

The last line is important - it ORDERs BY name. Be aware of the brackets.

(btw. overriding doesn't work)

Edited by derthis (see edit history)
Link to comment
Share on other sites

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...