derthis Posted May 23, 2012 Share Posted May 23, 2012 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 More sharing options...
derthis Posted May 23, 2012 Author Share Posted May 23, 2012 (edited) 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 May 23, 2012 by derthis (see edit history) 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