Boris726 Posted April 7, 2013 Share Posted April 7, 2013 Hello, I did find that sorting of features in Product Comparition are RANDOM! For example: http://demo-store.pr...ning-dress.html Sorting: Style Strapless Color Length Material Let's go there: http://demo-store.pr...evening-dresses and check three products for comparition. We can see sorting: Material Style Length Strapless Color Then, if remove one product - sorting changed: Material Strapless Length Style Color If remove another one product: Length Style Color Material Strapless How to make sorting in Product Compatition according sorting Features in Backoffice? Link to comment Share on other sites More sharing options...
NemoPS Posted April 8, 2013 Share Posted April 8, 2013 (edited) Here is why: foreach ($ids as $k => &$id) { $curProduct = new Product((int)$id, true, $this->context->language->id); if (!Validate::isLoadedObject($curProduct) || !$curProduct->active || !$curProduct->isAssociatedToShop()) { if (isset($this->context->cookie->id_compare)) CompareProduct::removeCompareProduct($this->context->cookie->id_compare, $id); unset($ids[$k]); continue; } foreach ($curProduct->getFrontFeatures($this->context->language->id) as $feature) $listFeatures[$curProduct->id][$feature['id_feature']] = $feature['value']; Basically, the compare controllers gets features based on the first product in the comparison, that's why it's varying from page to page. Heavy changes are needed to sort them out always the same way Edited April 8, 2013 by Nemo1 (see edit history) Link to comment Share on other sites More sharing options...
Boris726 Posted April 8, 2013 Author Share Posted April 8, 2013 (edited) Nemo1, Thank you for suggestion. If the compare controller gets features based on the FIRST product in the comparison - it is OK for me. But in that sample ALL three products are SIMILAR and they have the SAME features list and sorting future list: Style Strapless Color Length Material Why on the Product Compatition page initial sorting is different? Why after deleting one product - we get mixed sorting? By the way, if to switch page to other language the sotring will be changed. I did not find out sorting rule... all I can say it is no-ID and no-alphabetically. Is it the bug? Edited April 8, 2013 by Boris726 (see edit history) Link to comment Share on other sites More sharing options...
NemoPS Posted April 8, 2013 Share Posted April 8, 2013 Dumb of me. I was wrong, here is the function 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 nb DESC '); } It orders, or it SHOULD, by the number of featuers it finds :/ this doens't explain why it swaps around then changing language, if you have a value for the specific language 1 Link to comment Share on other sites More sharing options...
Boris726 Posted April 8, 2013 Author Share Posted April 8, 2013 Nemo1, Thanks! Is it: /classes/Feature.php ??? OK. Let's forget about changing language? Do you have any ideas how to change the function to work correct? Or everybody likes how the comparition works? Link to comment Share on other sites More sharing options...
Boris726 Posted April 9, 2013 Author Share Posted April 9, 2013 Problem solved. Thanks to doubleD! Link to comment Share on other sites More sharing options...
ALMAJ Posted June 22, 2013 Share Posted June 22, 2013 This problem is solved here: http://www.prestashop.com/forums/topic/232672-sort-product-features-in-comparison/ Link to comment Share on other sites More sharing options...
Recommended Posts