Jump to content

Sorting features in Product Comparison (bug)?


Recommended Posts

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

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 by Nemo1 (see edit history)
Link to comment
Share on other sites

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 by Boris726 (see edit history)
Link to comment
Share on other sites

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

  • Like 1
Link to comment
Share on other sites

  • 2 months later...
×
×
  • Create New...