Search SKU database field

Open to all! Ask other shopowners for help.
Post Reply
cwh2000
Member
Posts: 60
Joined: Fri Jul 30, 2021 10:21 am
Phoenix Version: v1.0.9.9

Search SKU database field

Post by cwh2000 »

What's the best way to have the search included a custom database field such as SKU?


Join The Code Co-op to get access to your library in the Code Co-op Forum
BrockleyJohn
Certified Developer
Posts: 173
Joined: Mon Mar 01, 2021 5:37 pm
Phoenix Version:
Has thanked: 2 times
Been thanked: 30 times

Re: Search SKU database field

Post 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 . "%'";
cwh2000
Member
Posts: 60
Joined: Fri Jul 30, 2021 10:21 am
Phoenix Version: v1.0.9.9

Re: Search SKU database field

Post 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
User avatar
burt
Core Team
Posts: 4550
Joined: Tue Oct 29, 2019 9:37 am
Phoenix Version: v1.1.0.8
Has thanked: 252 times
Been thanked: 412 times

Re: Search SKU database field

Post 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.
I am not here to build for you.
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

Post 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
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

Post 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
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

Post 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.
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

Post by azpro »

Or delete the database entry and add a file with a hook listener
Seems to me the most logical sollution!

Tnx!


Join The Code Co-op to get access to your library in the Code Co-op Forum
Post Reply