• Resolved Reed Sutton

    (@reedus33)


    Mentioned this issue on this github issue page: https://github.com/pods-framework/pods/pull/7175, however I figure it might warrant a separate thread here.

    There is some strange behavior happening with the currency field when a 0 is entered. Although I can enter 0 and it displays correctly on the individual post entry, on the admin overview it shows as blank (screenshots 1 and 2).

    It actually seems in some cases to be treated as a blank as well. For example my application is configured to pass a currency value from one pod custom post entry to another pod custom post entry (screenshot 3). However when the value is 0, it seems to fail and end up with a blank entry (screenshot 4).

    Screenshots:

    Any idea what is going on and how I can fix this so my posts actually inherit and display the correct 0 value? (or if this is a bug in Pods that should be tracked?)

    • This topic was modified 11 months, 1 week ago by Reed Sutton.
Viewing 1 replies (of 1 total)
  • Plugin Support Paul Clark

    (@pdclark)

    Yes, a bug, as you mentioned in GitHub, related to the difference between null, 0, and '' (a blank string).

    Fixing it in all cases and situations may require some digging, as it will require checking all the save and display data flows for correct datatypes.

    The challenge is that when considering all use cases, there may be situations where null is meant to mean “the price has not been set”, while 0 would be meant to mean “free”, so just saying “empty means zero means free” might not make sense for all users.

    The quickest fix in an individual site is to enforce the data type at the point of display. Here are some common functions which might aid in that process:

    • intval() converts any data type to an integer. null , a blank string, and textual '0' will become integer 0.
    • floatval() same, but with support for decimals.
    • is_null() will return true if a value is null as in the datatype of nothing.
    • number_format( $number, 2 ) will format an integer or float to a currency-like string, with commas and decimals. WordPress also has number_format_i18n( $number, $decimals )
    • empty() is likely what is causing the problem for Pods currently. Will return true if the input is integer 0 or false or [] an empty array or null or an empty string ''.

    In a use case like Pods, where all currencies and languages are considered, this can get quite complex.

    But in a single site, which can make some assumptions, like any blank price is free, if ( empty( $price ) ) { echo '$0.00 Free No Price Priceless'; } may suffice.

Viewing 1 replies (of 1 total)
  • The topic ‘Pods Currency Field Doesn’t Work with 0 Values’ is closed to new replies.