- Posts: 141
- Thank you received: 3
alphabetical order of filter values
7 years 9 months ago #301816
by Greg_C
alphabetical order of filter values was created by Greg_C
-- 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
-- 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.
7 years 9 months ago - 7 years 9 months ago #301826
by Philip
Replied by Philip on topic alphabetical order of filter values
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
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: 7 years 9 months ago by Philip.
Please Log in or Create an account to join the conversation.
7 years 9 months ago #301837
by Greg_C
Replied by Greg_C on topic alphabetical order of filter values
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 ?
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 ?
Please Log in or Create an account to join the conversation.
7 years 9 months ago #301839
by nicolas
Replied by nicolas on topic alphabetical order of filter values
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.
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.
7 years 9 months ago #301880
by Greg_C
Replied by Greg_C on topic alphabetical order of filter values
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,
Regards,
Please Log in or Create an account to join the conversation.
7 years 9 months ago #301882
by nicolas
Replied by nicolas on topic alphabetical order of filter values
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
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.
7 years 9 months ago #301899
by Greg_C
Replied by Greg_C on topic alphabetical order of filter values
Hi, Could you propose how this code should looks like and in which line should be placed ?
Regards,
Regards,
Please Log in or Create an account to join the conversation.
7 years 9 months ago #301919
by nicolas
Replied by nicolas on topic alphabetical order of filter values
Hi,
You would have to have a developer work on that for you.
It will be that code that need to be modified there:
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:
(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)
You would have to have a developer work on that for you.
It will be that code that need to be modified there:
Code:
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>';
}
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:
Code:
usort($field->field_value, function ($a, $b) { return strcmp($a[1], $b[1]); });
Please Log in or Create an account to join the conversation.
7 years 9 months ago #302151
by Greg_C
Replied by Greg_C on topic alphabetical order of filter values
Hi, thank you - I will try to check this
Regards,
Regards,
Please Log in or Create an account to join the conversation.
Time to create page: 0.253 seconds