There is an issue with filtering by price on views.

Use case :
You want to create a view which filters orders where order total price is greater then (or less then or similar) some amount.

Providing patch that fixes this issue.

Also screenshots of the issue with and without patch

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

xSDx created an issue. See original summary.

xSDx’s picture

Issue summary: View changes
Lendude’s picture

FileSize
3.66 KB

This is the underlying issue here, #2509986: EntityViewsData is broken for fields with 'numeric' columns, such as decimal fields (DecimalItem), Price uses a decimal field which Views currently handles wrong.

The Field API price fields work fine, it's just base fields that have a problem. So any entity that has a price base field needs to update its views data.

Here is a little something I tried. But really, this needs to be fixed upstream (which is now on my todo list).

drugan’s picture

FileSize
426 bytes

The #3 works great but would it be more appropriate for a temporary solution just to alter views data.

...keeping in mind that #2509986: EntityViewsData is broken for fields with 'numeric' columns, such as decimal fields (DecimalItem) will be fixed some day in any case.

Leagnus’s picture

#4 works fine on 8.5.x-dev

bojanz’s picture

We need #3 because it fixes all price fields on all entity types.
#4 covers only a single price field on variations.

I'd argue that "Drupal\commerce_price\PriceBaseFieldViewsData" is a bit odd though, I'd introduce a CommerceViewsData class instead, for this and other future workarounds.

s_leu’s picture

#3 works for me for the timebeing, not sure whether it's maybe only until #2509986: EntityViewsData is broken for fields with 'numeric' columns, such as decimal fields (DecimalItem) is fixed though.

bojanz’s picture

Title: Commerce Price Views Filter issue » Views filters are broken for price fields ("number" column)
Status: Needs review » Needs work

Need to address #6, and to sync the signature of processViewsDataForCommercePrice() with Drupal 8.5.0

bojanz’s picture

Assigned: Unassigned » bojanz

  • bojanz committed ec32a7b on 8.x-2.x authored by Lendude
    Issue #2882374 by xSDx, Lendude, drugan, bojanz: Views filters are...
bojanz’s picture

Status: Needs work » Fixed

Done. Made all entity types use the new CommerceEntityViewsData cause I'm sure we'll be adding other workarounds there as well.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.