Page 1 of 1

Search SKU database field

Posted: Tue Sep 30, 2025 1:36 am
by cwh2000
What's the best way to have the search included a custom database field such as SKU?

Re: Search SKU database field

Posted: Tue Sep 30, 2025 6:40 am
by BrockleyJohn
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.

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

Posted: Tue Sep 30, 2025 10:32 am
by cwh2000
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

Re: Search SKU database field

Posted: Tue Sep 30, 2025 1:36 pm
by burt
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.

Re: Search SKU database field

Posted: Tue Sep 30, 2025 2:25 pm
by ecartz
BrockleyJohn 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
Just replace the hook listener: https://github.com/CE-PhoenixCart/Phoen ... .sql#L1311

Re: Search SKU database field

Posted: Tue Sep 30, 2025 2:39 pm
by azpro
@ecartz
Matt,
Just replace the hook listener
Can you elaborate on that?

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 :D

Re: Search SKU database field

Posted: Tue Sep 30, 2025 3:17 pm
by ecartz
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.

Re: Search SKU database field

Posted: Tue Sep 30, 2025 4:29 pm
by azpro
Or delete the database entry and add a file with a hook listener
Seems to me the most logical sollution!

Tnx!