Jump to content

[Solved] How to change order of feature values in layered navigation block


Recommended Posts

Is it possible to change the display order of the feature values in the layered navigation block? Please see the first attachment, I have a range of thicknesses which I would like to in ascending order. The IDs are not in proper order as I created the feature values over time and not in correct order, as you can see in the second attachment. As you can also see there are no arrows to move the values up/down.

 

Is it possible to edit the IDs in the database or something like that, or will I just have to start again??

 

Thanks for any ideas

post-27482-0-10022200-1375759766_thumb.jpg

post-27482-0-50729300-1375759778_thumb.jpg

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

I presume you have 'used the attributes already in products (if not, you can just edit the names and change them into increasing values). I think we have to search for a solution in either the database query (as I quickly could see, in modules/blocklayered/blocklayered.php

or we have to change the array order just before displaying.

 

Needs some time to sort out, though. Maybe also have a look into this, so we can try to come up with a solution faster.

 

My 2 cents for now,

pascal.

 

 

quick try:

find in above mentioned file the function:

public function getFilterBlock($selected_filters = array())

scroll down until you see

 

case 'id_attribute_group':// attribute group (the 'case' under 'case manufacturer)

case 'id_attribute_group':// attribute group
 $sql_query['select'] = '
 SELECT COUNT(DISTINCT p.id_product) nbr, lpa.id_attribute_group,
 a.color, al.name attribute_name, agl.public_name attribute_group_name , lpa.id_attribute, ag.is_color_group,
 liagl.url_name name_url_name, liagl.meta_title name_meta_title, lial.url_name value_url_name, lial.meta_title value_meta_title';
 $sql_query['from'] = '
 FROM '._DB_PREFIX_.'layered_product_attribute lpa
 INNER JOIN '._DB_PREFIX_.'attribute a
 ON a.id_attribute = lpa.id_attribute
 INNER JOIN '._DB_PREFIX_.'attribute_lang al
 ON al.id_attribute = a.id_attribute
 AND al.id_lang = '.$id_lang.'
 INNER JOIN '._DB_PREFIX_.'product as p
 ON p.id_product = lpa.id_product
 INNER JOIN '._DB_PREFIX_.'attribute_group ag
 ON ag.id_attribute_group = lpa.id_attribute_group
 INNER JOIN '._DB_PREFIX_.'attribute_group_lang agl
 ON agl.id_attribute_group = lpa.id_attribute_group
 AND agl.id_lang = '.$id_lang.'
 LEFT JOIN '._DB_PREFIX_.'layered_indexable_attribute_group_lang_value liagl
 ON (liagl.id_attribute_group = lpa.id_attribute_group AND liagl.id_lang = '.$id_lang.')
 LEFT JOIN '._DB_PREFIX_.'layered_indexable_attribute_lang_value lial
 ON (lial.id_attribute = lpa.id_attribute AND lial.id_lang = '.$id_lang.') ';
 $sql_query['where'] = 'WHERE a.id_attribute_group = '.(int)$filter['id_value'];
 if (version_compare(_PS_VERSION_,'1.5','>'))
  $sql_query['where'] .= ' AND lpa.`id_shop` = '.(int)Context::getContext()->shop->id;
 $sql_query['where'] .= ' AND '.$alias.'.active = 1 AND p.id_product IN (
 SELECT id_product
 FROM '._DB_PREFIX_.'category_product cp
 INNER JOIN '._DB_PREFIX_.'category c ON (c.id_category = cp.id_category AND
 '.(Configuration::get('PS_LAYERED_FULL_TREE') ? 'c.nleft >= '.(int)$parent->nleft.'
 AND c.nright <= '.(int)$parent->nright : 'c.id_category = '.(int)$id_parent).'
 AND c.active = 1)) ';
 $sql_query['group'] = '
 GROUP BY lpa.id_attribute
 ORDER BY id_attribute_group, id_attribute ';

 

 

At the end you see ORDER BY id_attribute_group, id_attribute ';

change id_attribute into:

ORDER BY id_attribute_group, lial ';

 

Not sure if it's correct, just try for a moment :-)

pascal

Edited by PascalVG
EDIT: OF course doesn't work, as ORDER BY value is a table name, not a field name :[ . Also, the name wasn't in the Select list. Most of all, as duratex mentioned correctly below, we needed the features, not the attributes (see edit history)
Link to comment
Share on other sites

Ah, you're right of course. Slip of the mind.

 

I think I found it:

 

Just under the code mentioned above (Which didn't work by the way, as I ordered on the table (name), instead of a field , oops, too quick a first try!!! )

You have this code:

 

   case 'id_feature':
 $sql_query['select'] = 'SELECT fl.name feature_name, fp.id_feature, fv.id_feature_value, fvl.value,
 COUNT(DISTINCT p.id_product) nbr,
 lifl.url_name name_url_name, lifl.meta_title name_meta_title, lifvl.url_name value_url_name, lifvl.meta_title value_meta_title ';
 $sql_query['from'] = '
 FROM '._DB_PREFIX_.'feature_product fp
 INNER JOIN '._DB_PREFIX_.'product p ON (p.id_product = fp.id_product)
 LEFT JOIN '._DB_PREFIX_.'feature_lang fl ON (fl.id_feature = fp.id_feature AND fl.id_lang = '.$id_lang.')
 INNER JOIN '._DB_PREFIX_.'feature_value fv ON (fv.id_feature_value = fp.id_feature_value AND (fv.custom IS NULL OR fv.custom = 0))
 LEFT JOIN '._DB_PREFIX_.'feature_value_lang fvl ON (fvl.id_feature_value = fp.id_feature_value AND fvl.id_lang = '.$id_lang.')
 LEFT JOIN '._DB_PREFIX_.'layered_indexable_feature_lang_value lifl
 ON (lifl.id_feature = fp.id_feature AND lifl.id_lang = '.$id_lang.')
 LEFT JOIN '._DB_PREFIX_.'layered_indexable_feature_value_lang_value lifvl
 ON (lifvl.id_feature_value = fp.id_feature_value AND lifvl.id_lang = '.$id_lang.') ';
 $sql_query['where'] = 'WHERE '.$alias.'.`active` = 1 AND fp.id_feature = '.(int)$filter['id_value'].'
 AND p.id_product IN (
 SELECT id_product
 FROM '._DB_PREFIX_.'category_product cp
 INNER JOIN '._DB_PREFIX_.'category c ON (c.id_category = cp.id_category AND
 '.(Configuration::get('PS_LAYERED_FULL_TREE') ? 'c.nleft >= '.(int)$parent->nleft.'
 AND c.nright <= '.(int)$parent->nright : 'c.id_category = '.(int)$id_parent).'
 AND c.active = 1)) ';
 $sql_query['group'] = 'GROUP BY fv.id_feature_value ORDER BY fvl.value '; // <-- ADD THIS HERE: ORDER BY fvl.value

 if (!Configuration::get('PS_LAYERED_HIDE_0_VALUES'))
 {
  $sql_query['second_query'] = '
   SELECT fl.name feature_name, fp.id_feature, fv.id_feature_value, fvl.value,
   0 nbr,
   lifl.url_name name_url_name, lifl.meta_title name_meta_title, lifvl.url_name value_url_name, lifvl.meta_title value_meta_title

   FROM '._DB_PREFIX_.'feature_product fp
   '.(version_compare(_PS_VERSION_,'1.5','>') ? Shop::addSqlAssociation('product', 'fp') : '').'
   INNER JOIN '._DB_PREFIX_.'product p ON (p.id_product = fp.id_product)
   LEFT JOIN '._DB_PREFIX_.'feature_lang fl ON (fl.id_feature = fp.id_feature AND fl.id_lang = '.$id_lang.')
   INNER JOIN '._DB_PREFIX_.'feature_value fv ON (fv.id_feature_value = fp.id_feature_value AND (fv.custom IS NULL OR fv.custom = 0))
   LEFT JOIN '._DB_PREFIX_.'feature_value_lang fvl ON (fvl.id_feature_value = fp.id_feature_value AND fvl.id_lang = '.$id_lang.')
   LEFT JOIN '._DB_PREFIX_.'layered_indexable_feature_lang_value lifl
   ON (lifl.id_feature = fp.id_feature AND lifl.id_lang = '.$id_lang.')
   LEFT JOIN '._DB_PREFIX_.'layered_indexable_feature_value_lang_value lifvl
   ON (lifvl.id_feature_value = fp.id_feature_value AND lifvl.id_lang = '.$id_lang.')
   WHERE '.$alias.'.`active` = 1 AND fp.id_feature = '.(int)$filter['id_value'].'
   GROUP BY fv.id_feature_value ORDER BY fvl.value '; // <-- ADD THIS HERE : ORDER BY fvl.value
 }

 break;

 

Add two times this piece of code:

ORDER BY fvl.value

just after the group by... code piece.

 

That should do the trick.

 

Note: values like '5' will come AFTER '25', as the values are compared as string, not as value: so first 'digit-characters' are compared: '5' > '2'). To solve this, change 5 into 05 if needed. Then you will get order of 05, 25, ...

 

Let me know if it works for you!

pascal

  • Like 2
Link to comment
Share on other sites

  • 3 months later...

In case of attributes instead of features, this works:

 

Toeareg, on 01 Aug 2013 - 08:20 AM, said:snapback.png

**UPDATE**
I made some changes to modules/blocklayered/blocklayered.php (lines 2677 & 2709) to make the sort order of the attributevalues work in block layered navigation as well as in the menus.
Line 2677, added a.position in the SELECT clause:

SELECT COUNT(DISTINCT p.id_product) nbr, lpa.id_attribute_group,
a.position, a.color, al.name attribute_name, agl.public_name attribute_group_name , lpa.id_attribute, ag.is_color_group,Line 2709, changed the ORDER BY clause from:
ORDER BY id_attribute_group, id_attribute';to:
ORDER BY id_attribute_group, position';Now all sorting works like it should   :)

 

 

 

You  also have to add a.position in the sql query in 2715 and in the order 2742 

Link to comment
Share on other sites

  • 1 year later...
  • 1 year later...

Hello guys,

 

can anybody help with this problem? I have lot of rings sizes and lot of other and it would be nice to have these attributes sorted from smallest size to the biggest, nomatter the position is in the BO or DB, so literaly order by name, but 5 needs to be smaller then 25, but I cant make it that way Pascal said to change 5 to 05 :). And I think I will need it to order just before displaying because I have all the products imported and they are reimported every day... 

 

I am also having similar problem at product pages, where I need to order/sort the attributes from smallest/from A to biggest/to Z. 

 

My test domain is http://www.webgamesy.cz PS 1.6.1.4

 

It would be so nice if someone can help with this...

 

Very very thanks for any hint...

 

Daniel

Link to comment
Share on other sites

  • 5 months later...
  • 5 months later...

Another way...

I wanted to display the price slider first, but otherwise keep the order. It was coming last.

In the blocklayered.php, in the case "price" simply add it to the start of the filter_blocks array using unshift.
 

//$filter_blocks[] = $price_array; // move price to top
array_unshift($filter_blocks, $price_array);
 
hope that helps someone :)
  • Like 1
Link to comment
Share on other sites

  • 2 months later...
  • 7 months later...
  • 3 months later...

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