Using address zone as a view filter

Created on 14 March 2023, over 1 year ago
Updated 18 March 2023, over 1 year ago

Problem/Motivation

For a project of mine, I'd like to filter some stores by an area of activity inside a view.
So I used this module "address zone" that perfectly fit my needs with its postal code regexes.
Now I still need a view filter that filter addresses by zone of activity, I was about to happily implement it (and share my result here), except I see now that "address zone" regex are stored in a serialized column making it impossible (to my eyes) to be used in a where condition in a views query.
Is this Hopeless, and should I use a custom field, or is there a Drupal way that I don't see ?

✨ Feature request
Status

Active

Version

1.0

Component

Code

Created by

πŸ‡«πŸ‡·France Thony

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @Thony
  • πŸ‡ΊπŸ‡ΈUnited States lisastreeter

    @Thorny - I'm using a Zone field for customer "tax exemption documents" so that I can match them up with customer shipping addresses. For the vast majority, admins are just entering one or more US states for the Zone value.

    I was just asked to add "State" as a Views filter for the tax-exemption listing and found this issue when I went searching for a solution.

    Creating a proper views filter for a zone also seems extremely difficult (or impossible) to me. So...I've been considering a workaround that I'll describe here in case you could do something similar for your "postal code" filter needs.

    * Add a multiple value text field for "States" to tax exemption document entities. (do not display on entity form/display)
    * On entity save/update, extract the "administrative area" for each zone territory and save it to the States field.
    * Add Views filter for that States field. Admin users will simply type the 2-character state abbreviation. (All exemptions are U.S.)

    If you only have "included postal codes", perhaps you could do the same, parsing the values into a multi-value text field on entity save. And then use the "Regular expression" operator for the Views filter.

    Then again, perhaps creating a custom field as you suggest would be a better/cleaner solution.

Production build 0.69.0 2024