Search SKU database field
Search SKU database field
What's the best way to have the search included a custom database field such as SKU?
-
BrockleyJohn
- Certified Developer
- Posts: 173
- Joined: Mon Mar 01, 2021 5:37 pm
- Phoenix Version:
- : Buy Me A Beverage
- Has thanked: 2 times
- Been thanked: 30 times
Re: Search SKU database field
The query is built in the product_searcher class.
There is a hook that could be used to manipulate the query that's built but I have not found a way to get into the middle of building the LIKEs for the WHERE clause so it's not viable to use that for extra fields that need comparing to potentially multiple keywords.
I have done this before by copying the product_searcher class into the system override folder and editing the copy e.g.
There is a hook that could be used to manipulate the query that's built but I have not found a way to get into the middle of building the LIKEs for the WHERE clause so it's not viable to use that for extra fields that need comparing to potentially multiple keywords.
I have done this before by copying the product_searcher class into the system override folder and editing the copy e.g.
Code: Select all
$custom['where'] .= "(pd.products_name LIKE '%" . $keyword . "%' OR p.products_model LIKE '%" . $keyword . "%' OR m.manufacturers_name LIKE '%" . $keyword . "%'";
// extra search fields
$custom['where'] .= " OR p.products_manufacturer_model LIKE '%" . $keyword . "%'";
$custom['where'] .= " OR p.products_gtin LIKE '%" . $keyword . "%'";
$custom['where'] .= " OR pd.products_name_short LIKE '%" . $keyword . "%'";
Re: Search SKU database field
Thanks John! Works great on my test server on version v1.1.0.5, but I need to update the production site from v1.0.9.5. Are you planning to update the add-on CE Phoenix Upgrader Utility: app.php/addons/free_addon/ce_phoenix_upgrader_utility
- burt
- Core Team
- Posts: 4546
- Joined: Tue Oct 29, 2019 9:37 am
- Phoenix Version: v1.1.0.8
- : Buy Me A Beverage
- Has thanked: 252 times
- Been thanked: 412 times
Re: Search SKU database field
Another option which you might not have thought of (or indeed you may have thought of and not gone ahead) is to uprate the search box with typeahead "instant search". It would be very simple to plug any custom product field into it.
viewtopic.php?t=2850
This is the Lite Version so you can try to see if it might be suitable.
viewtopic.php?t=2850
This is the Lite Version so you can try to see if it might be suitable.
I am not here to build for you.
I am here to build with you. Let's help each other.
I am here to build with you. Let's help each other.
-
ecartz
- Core Team
- Posts: 3084
- Joined: Tue Nov 05, 2019 6:02 pm
- Phoenix Version:
- Has thanked: 4 times
- Been thanked: 208 times
Re: Search SKU database field
Just replace the hook listener: https://github.com/CE-PhoenixCart/Phoen ... .sql#L1311BrockleyJohn wrote: ↑Tue Sep 30, 2025 6:40 am There is a hook that could be used to manipulate the query that's built but I have not found a way to get into the middle of building the LIKEs for the WHERE clause so it's not viable to use that for extra fields that need comparing to potentially multiple keywords.
I have done this before by copying the product_searcher class into the system override folder
-
azpro
- Contributor
- Posts: 177
- Joined: Fri Nov 06, 2020 8:25 am
- Phoenix Version: v1.1.0.6
- Has thanked: 30 times
- Been thanked: 34 times
Re: Search SKU database field
@ecartz
Matt,
https://github.com/CE-PhoenixCart/Phoen ... er.php#L31
Copy the file includes/system/versioned/1.01.00.00/product_searcher.php to override? And adapt to your needs?
Or ?? Make a new hook ??
I feel dumb
Matt,
Can you elaborate on that?Just replace the hook listener
https://github.com/CE-PhoenixCart/Phoen ... er.php#L31
Copy the file includes/system/versioned/1.01.00.00/product_searcher.php to override? And adapt to your needs?
Or ?? Make a new hook ??
I feel dumb
-
ecartz
- Core Team
- Posts: 3084
- Joined: Tue Nov 05, 2019 6:02 pm
- Phoenix Version:
- Has thanked: 4 times
- Been thanked: 208 times
Re: Search SKU database field
Copy the function wherever you want (such that it gets loaded). Edit the hook (in the database) to point to your new function. Or delete the database entry and add a file with a hook listener.