Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pro search {pro_search_distance} can't return 0 #3245

Closed
robinsowell opened this issue Apr 6, 2023 · 1 comment · Fixed by #3253
Closed

Pro search {pro_search_distance} can't return 0 #3245

robinsowell opened this issue Apr 6, 2023 · 1 comment · Fixed by #3253
Labels
Bug: Accepted Bug has been confirmed, is reproducible, and ready to work on.

Comments

@robinsowell
Copy link
Contributor

EE 7.2.13

The {pro_search_distance} should show the distance from the 'to' lat/longitude parameter, and it works UNLESS the distance is 0. Then it just is empty. I couldn't get it to output 0 no matter how I futzed around with it, including just hard coding '0' in the code.

I'm not sure how to fix, but it's definitely a bit confusing. And at some point in the past, it did work.

Example template:

{exp:pro_search:form query="{segment_3}" result_page="home/search"}

  {!-- The user’s lat/long values --}
  <input type="hidden" name="distance:from" value="52.163298|4.505547">
  
  <input type="text" name="distance:radius" value="100">


  <button type="submit">Go</button>
{/exp:pro_search:form}

{exp:pro_search:results
  query="{segment_3}"
  distance:to="local_lat|local_long"
  distance:unit="km"
}
  <p>{title} is {pro_search_distance}km away.</p>
  {if no_results}
    <p>Sorry, nothing found within a {pro_search_distance:radius}km radius.</p>
  {/if}
{/exp:pro_search:results}

I had 2 custom fields local_lat and local_long - local_lat 52.163298 local_long 4.505543 is so close, rounded it comes to 0 and just doesn't display anything for that variable.

@robinsowell robinsowell added the Bug: Accepted Bug has been confirmed, is reproducible, and ready to work on. label Apr 6, 2023
@intoeetive
Copy link
Contributor

intoeetive commented Apr 11, 2023

This appears to be an issue with the parser in general, not Pro Variables in particular. Elvis can be dangerous!

(when you're using Elvis operand ?: and not checking for variable type - PHP would evaluate float(0) or even string("0") as false. TL, DR: don't use Elvis if you're working with mixed data type)

intoeetive added a commit that referenced this issue Apr 11, 2023
intoeetive added a commit that referenced this issue Apr 11, 2023
…te variables provided by add-ons

(cherry picked from commit dd27816)
intoeetive added a commit that referenced this issue Apr 24, 2023
…te variables provided by add-ons

(cherry picked from commit dd27816)
intoeetive added a commit that referenced this issue Apr 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug: Accepted Bug has been confirmed, is reproducible, and ready to work on.
Projects
None yet
2 participants