inventory icon indicating copy to clipboard operation
inventory copied to clipboard

In-Store Pickup Offline Store Search Doesn't Match UK Postcodes

Open craig-bartlett opened this issue 4 years ago • 1 comments

Preconditions (*)

  1. Magento 2.4.*
  2. Enable MSI
  3. Enable In-Store Pickup
  4. Offline distance algorithm enabled
  5. Generated UK postcodes with bin/magento inventory-geonames:import GB
  6. Multiple sources enabled for in-store pickup

Steps to reproduce (*)

  1. Add a product to the basket
  2. Go to checkout and select the in-store pickup delivery method
  3. Use the Select Store button to search with a postcode, such as one belonging to a pickup source

Expected result (*)

  1. A returned list of sources in distance order, relative to the given postcode

Actual result (*)

  1. No results are found so the entire list is returned

Unless I'm missing something I believe this is caused due to the way the search input text is validated and how it is used to search the inventory_geonames table. The inventory_geonames table stores the first section of the postcode:

Screenshot 2021-04-28 at 10 15 48

However to be recognised as a postcode and not fall back to searching for cities, it needs to match one of the postcode formats for the given country (GB in this case) provided in zip_codes.xml in the validator. In this case, the following:

Screenshot 2021-04-28 at 10 48 25

These all require the full postcode such as "DA18 4AA". This is an issue because when the table is searched in GetGeoNamesDataByAddress it checks for equality, with the where clause being created as such:

Screenshot 2021-04-28 at 10 59 53

Therefore there are no results and it moves to the next search (cities). The issue is compounded by the fact that the validator only recognises it as a postcode if the user enters the full postcode, so a partial search isn't possible.

I created a patch for my own team to use but I don't think it's the best solution. It just alters the query to search for the first section of the postcode (e.g. DA18). Perhaps it would make more sense to have this logic in the Address model?

If it's helpful for anyone else, my patch is here: https://github.com/magento/inventory/compare/1.2-develop...craig-bartlett:format-postcode-for-geoname-searching.diff

craig-bartlett avatar Apr 29 '21 10:04 craig-bartlett

Hi @craig-bartlett. Thank you for your report. To help us process this issue please make sure that you provided sufficient information.

Please, add a comment to assign the issue: @magento I am working on this


m2-assistant[bot] avatar Apr 29 '21 10:04 m2-assistant[bot]