inventory
inventory copied to clipboard
In-Store Pickup Offline Store Search Doesn't Match UK Postcodes
Preconditions (*)
- Magento 2.4.*
- Enable MSI
- Enable In-Store Pickup
- Offline distance algorithm enabled
- Generated UK postcodes with bin/magento inventory-geonames:import GB
- Multiple sources enabled for in-store pickup
Steps to reproduce (*)
- Add a product to the basket
- Go to checkout and select the in-store pickup delivery method
- Use the Select Store button to search with a postcode, such as one belonging to a pickup source
Expected result (*)
- A returned list of sources in distance order, relative to the given postcode
Actual result (*)
- 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:
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:
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:
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
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
- Join Magento Community Engineering Slack and ask your questions in #github channel.