Product filters don't work with falsy values

  • Posts: 193
  • Thank you received: 76
10 years 1 month ago #179057

-- HikaShop version -- : 2.3.4
-- Joomla version -- : 3.3.6

Product filters with falsy values are ignored.
Problem is in file \plugins\hikashop\massaction_product\massaction_product.php on line 60:

if(!empty($filter['value']) || (empty($filter['value']) && in_array($filter['operator'],array('IS NULL','IS NOT NULL')))){

Replacing
!empty($filter['value'])
with
isset($filter['value'])
fixed the problem, but I'm not sure about all consequences.

Here is screenshot with test:
https://www.uploady.com/#!/download/x3Ez8neAvx8/fuY5C_AQ7ERf280G

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

  • Posts: 13201
  • Thank you received: 2322
10 years 1 month ago #179260

Hi,

Could you try that instead:

if((!empty($filter['value']) || $filter['value'] == '0' ) || (empty($filter['value']) && in_array($filter['operator'],array('IS NULL','IS NOT NULL')))){

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

  • Posts: 193
  • Thank you received: 76
10 years 1 month ago #179361

This solve the issue for 0 but not for empty string ''.

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

  • Posts: 13201
  • Thank you received: 2322
10 years 1 month ago #179397

Hi,

In which case do you want to let the field empty ?
In most of the filters, we can't allow an empty field, or you have to select "IS NULL" in the dropdown before that field.

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

  • Posts: 193
  • Thank you received: 76
10 years 1 month ago #179474

IS NULL doesn't help because Hikashop use empty string when data are not provided.
I need it when I want to search for products not having filled alias, meta, title... etc.

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

  • Posts: 13201
  • Thank you received: 2322
10 years 1 month ago #179478

You can use a filter like:
field_name = "NOT REGEXP" "[a-zA-Z]"

Which means that it will show all the product where the field "field_name" doesn't have any character.

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

  • Posts: 193
  • Thank you received: 76
10 years 1 month ago #179561

I'm fine to use REGEXP ^\s*$ , but it's hard to persuade clients to dive in Regex.
My only concern is that user is allowed to save empty field and gets misleading results.

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

  • Posts: 13201
  • Thank you received: 2322
10 years 1 month ago #179570

Hi,

You can potentially use your code, but I think that in some situations that can cause errors, not sure (there is a lot of possibilities).
Thanks to report us if any problems are met, if not we will do more tests with your suggested code and potentially use it in a future release if everything is ok.

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

Time to create page: 0.079 seconds
Powered by Kunena Forum