alphabetical order of filter values

  • Posts: 141
  • Thank you received: 3
5 years 11 months ago #301816

-- HikaShop version -- : 4.0.1.
-- Joomla version -- : 3.8.13

Hi, I am working on Hikashop Business 4.0.1.
Is it possible to set alphabetical order of filter values presented in dropdown list (filter based on custom field) ?
I see that the order of values in dropdown list is taken by default based on order of values typed in the value list in the custom fields setup but I cannot find the way how to change this order to alphabetical.
Regards,
Greg

Please Log in or Create an account to join the conversation.

  • Posts: 4747
  • Thank you received: 644
  • MODERATOR
5 years 11 months ago #301826

Hello,

So far, I can say that you are right there is no options in order to order value by alphabetical order, but maybe there is a way but this will depends from your specific needs and your filter and custom field configuration.

So in order to find a solution can you provide :
- Filer settings screenshot
- Custom fields screenshot
- Describe in details your needs and your value

the point is for us to understand the context and what you want achieved as filter results.
Regards

Last edit: 5 years 11 months ago by Philip.

Please Log in or Create an account to join the conversation.

  • Posts: 141
  • Thank you received: 3
5 years 11 months ago #301837

Hi Philip, thank you for your response

Please find below an example of the custom field set as dropdown field and filter based on this custom field also set as dropdown type.





Finally filter on the front page (in filter module) will looks like below – so order of values is as entered to the custom field settings but because I plan to have a lot of different filters with many values I prefer to have possibility to sort these vaules in the filter in alphabetical order



maybe the solution would be to place relevant code to the Display-Views-Filter.php – but question how this code should looks like and where should be placed ?

Attachments:

Please Log in or Create an account to join the conversation.

  • Posts: 82868
  • Thank you received: 13376
  • MODERATOR
5 years 11 months ago #301839

Hi,

No, you would have to do that in the administrator/components/com_hikashop/classes/filter.php file when the values are loaded or when the dropdown is generated.
In the filter.php view, the elements are just assembled so I don't think you would be able to do it from there.

But why not reorder the values on the custom field ? That way, you would have the order you want.

Please Log in or Create an account to join the conversation.

  • Posts: 141
  • Thank you received: 3
5 years 11 months ago #301880

Hi Nicolas, I can keep the proper (alphabetical) order of the values on the custom field but in case of multilanguage site and translation to different language the order will be not alpabetcial in different language. Is it possible to keep alphabetical order regardless of language ?

Regards,

Please Log in or Create an account to join the conversation.

  • Posts: 82868
  • Thank you received: 13376
  • MODERATOR
5 years 11 months ago #301882

Hi,

I didn't think of that.
That's indeed a valid reason to have a alphabetic ordering setting for the options of the filter directly in the filter.
Right now, the only way would be to modify the code in administrator/components/com_hikashop/classes/filter.php

Please Log in or Create an account to join the conversation.

  • Posts: 141
  • Thank you received: 3
5 years 11 months ago #301899

Hi, Could you propose how this code should looks like and in which line should be placed ?
Regards,

Please Log in or Create an account to join the conversation.

  • Posts: 82868
  • Thank you received: 13376
  • MODERATOR
5 years 11 months ago #301919

Hi,

You would have to have a developer work on that for you.
It will be that code that need to be modified there:

				foreach($field->field_value as $val){
					$selectedItem='';
					if(!empty($selected) && in_array($val[0], $selected)){
						$selectedItem='selected="selected"';
					}
					if(empty($val[0]) && $field->field_required) continue;
					$html.='<OPTION '.$selectedItem.' name="'.$filter->filter_data.'" value="'.$val[0].'">'.JText::_($val[1]).'</OPTION>';
				}
It's a more complex that just one line of code you can copy/paste there.


I've thought of an alternative. Supposing that you're using Falang to translate your products (which you probably do), you can translate your custom field through Falang's translations interface instead of using the translation files system of Joomla. With it, you'll also be able to translate the values of the custom field and in that case, the sorting can be done before the code above with just that line:
usort($field->field_value, function ($a, $b) { return strcmp($a[1], $b[1]); });
(note that I didn't test it and just wrote it off the top of my head so I can't guarantee that it will work without some tweaking)

Please Log in or Create an account to join the conversation.

  • Posts: 141
  • Thank you received: 3
5 years 10 months ago #302151

Hi, thank you - I will try to check this
Regards,

Please Log in or Create an account to join the conversation.

Time to create page: 0.084 seconds
Powered by Kunena Forum