Skip to content

Calling math filters on rating field in metaobject results in incorrect output #1978

Description

@driesrobeyns

I have created a metaobject with a "rating" field. When I iterate over the metaobject_list in my section I see the expected data. However when I try calling a math filter on rating.value, it will return 0. Calling the same math filter on scale_min/scale_max values inside the same metaobject will yield the correct values.

Here is an example of calling a round filter on rating.value in a metaobject_list for loop:

  {% assign rating = item.rating  %}
    Rating metafield: {{ rating }}<br>
    Rating value: {{ rating.value}}<br>
    Rating scale min: {{ rating.value.scale_min }}<br>
    Rating scale max: {{ rating.value.scale_max }}<br>
    Rating round: {{ rating.value | round }}<br>
    Rating scale min round: {{ rating.value.scale_min | round }}<br>
    Rating scale max round: {{ rating.value.scale_max | round }}<br>
Output:
Rating metafield: {"scale_min":"1.0","scale_max":"5.0","value":"4.5"} // As expected
Rating value: 4.5 // As expected
Rating scale min: 1.0 // As expected
Rating scale max: 5.0 // As expected
Rating round: 0 **Wrong! Should be 5**
Rating scale min round: 1 // As expected
Rating scale max round: 5 // As expected

Steps to recreate:

  1. Create a metaobject with a rating field
  2. Create entry for said object
  3. Read object in liquid and try using math filter on rating.value

Using {{ rating.value | plus: 0 | round }} to force a conversion to interger results in the same incorrect output.

It is strange that scale_min/max results in the correct value but value does not, give the all have the same type in the metafield.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions