Jump to content

Wrong order of Product feature when comparing (frontpage vs backoffice)


Recommended Posts

  • 3 weeks later...

I'm not an expert, so I hope someone can look through this change.

 

The code in classes/Feature.php looks like this (near line 246):

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

That means the features are only sorted by the amount of products which have them set.

That means features which are set in all products come before features that are set in only one product.

 

Like this they should be sorted first by the number amount of products which have them set AND AFTERWARDS by their position:

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, position ASC

And like this they should only be sorted by their Position

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 position ASC

This depends on which behaviour you want to achieve.

 

Greets

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

Solved!

in classes/Feature.php

    public static function getFeaturesForComparison

 

Change:

 

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
'
);

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

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, position ASC

I would still prefer this one.

It doesn't really make sense to compare features which aren't availlable on all the products.

  • Like 1
Link to comment
Share on other sites

Sorry for late reply, thank you very much Qvixx. I actually ended up with your second alternative as this suit better. Now its easy to control according to how we arange the order of the Product feature as 80% of all the products uses all the feature. It was a bit frustrating when products showed up with "random" order compared to what we actually set in the BO page, now we are all happy about this :-)

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