Page 1 of 3
Product Filters
Posted: Mon Jan 02, 2023 7:44 pm
by Kofod95
I've been working on a filter that will enable the admin to configure what data they want customers to be able to filter products by. It will automatically show on any product listings that uses the templated-listing component. Also, it allows the admin to set up filters for data from the products-table (as either a range or a id-based filter), for attributes (with automatic check for QTPro) or for S04E10 - Products Specifications. All filters will show as drop-downs, except range-filters, which will show as a minimum or maximum input-field pre-filled with the min and max values in the current listing, with a button to submit.
I'm working on adding tax to the values, if a filter for price is set up, but that is currently not ready.
Also, the support for QTPro needs some optimising of the sql if there are many attributes and stock-levels, so feel free to contribute to that, if any of you have ways to optimise that!
I've included a pdf that hopefully makes it easier to understand how to set up filters, but feel free to ask.
//Daniel
Re: Product Filters
Posted: Mon Jan 02, 2023 11:55 pm
by ecartz
Does QT Pro have an index on products_stock on products_id and products_stock_quantity?
You might want to change the existing index on products_attributes.products_id to be products_id, options_values_id
As best I can see,
Code: Select all
if(!empty($group_by)) $GLOBALS['filter_listing'] .= ' GROUP BY ' . implode(', ', $group_by);
could be
Code: Select all
if(!empty($group_by)) $GLOBALS['filter_listing'] .= ' GROUP BY p.products_id';
without any change in functionality.
Code: Select all
$active_filters = [];
$applied_filters = $_GET['f'];
foreach($applied_filters as $k => $v){
if($v != '') array_push($active_filters, $k);
}
could be
Code: Select all
$active_filters = array_keys(array_filter($_GET['f']));
Re: Product Filters
Posted: Tue Jan 03, 2023 8:34 am
by Kofod95
Awesome, @ecartz, thank you!
I will apply your suggestions and re-upload.
//Daniel
Re: Product Filters
Posted: Tue Jan 03, 2023 8:38 am
by Kofod95
ecartz wrote: ↑Mon Jan 02, 2023 11:55 pm
Does QT Pro have an index on products_stock on products_id and products_stock_quantity?
I'm not sure, but I will look for it - I guess that would improve the speed quite a bit, if that's the case.
//Daniel
Re: Product Filters
Posted: Sat Jan 07, 2023 1:05 pm
by Omar_one
@ecartz @Kofod95
I just applied the changes
ecartz wrote: ↑Mon Jan 02, 2023 11:55 pm
As best I can see,
Code: Select all
could be [code] if(!empty($group_by)) $GLOBALS['filter_listing'] .= ' GROUP BY p.products_id');
there is extra ")"
the filter not picking the products just reload the page after making the changes
If I applied the 1st change after deleting the extra ")" and the 2st one changed it to this
Code: Select all
$active_filters = array_filter(array_values($_GET['f']));
$applied_filters = $_GET['f'];
foreach($applied_filters as $k => $v){
if($v != '') array_push($active_filters, $k);
}
the filter more faster, but loading the products so so slow on categories with have many attributes options, ( I am using QtPro module )
Thank you
Omar
Re: Product Filters
Posted: Sat Jan 07, 2023 5:53 pm
by ecartz
I updated both changes (in the previous post) based on that feedback.
Note that the code changes probably won't make things faster (at least not noticeably). What should make things faster is modifying/adding the indexes. However, if you really want to make that faster, you might need to build a proper search index.
Re: Product Filters
Posted: Mon Jan 09, 2023 12:54 pm
by Omar_one
ecartz wrote: ↑Sat Jan 07, 2023 5:53 pm
What should make things faster is modifying/adding the indexes. However, if you really want to make that faster, you might need to build a proper search index.
Any idea how to build a search index? On which table/tables?
Re: Product Filters
Posted: Fri Jan 13, 2023 9:10 pm
by Omar_one
ecartz wrote: ↑Sat Jan 07, 2023 5:53 pm
Note that the code changes probably won't make things faster (at least not noticeably). What should make things faster is modifying/adding the indexes. However, if you really want to make that faster, you might need to build a proper search index.
adding the index combination for products_id and products_stock_quantity to the products_stock table didn't make it faster, thanks
@raiwa for provide me with the query
I think the issue on the lines 40-45 as if I remove the checking for stock from that query the filter working perfectly and not slow at all
thank you in advance for your help
Omar
Re: Product Filters
Posted: Sat Jan 14, 2023 7:25 pm
by Kofod95
Sorry for being slow to react here!
ecartz wrote: ↑Mon Jan 02, 2023 11:55 pm
Code: Select all
$active_filters = array_keys(array_filter($_GET['f']));
This works fine as long as there are no "range"-filters - I guess I could target them afterwards.
I found a couple of bugs as well, so a revised version will come, though it may take a while.
Omar_one wrote: ↑Fri Jan 13, 2023 9:10 pm
I think the issue on the lines 40-45 as if I remove the checking for stock from that query the filter working perfectly and not slow at all
Both line 42 and line 140 would probably need optimising.
I think I'm in over my head with this issue, sorry. I'm satisfied with how it functions without QTPro, but I agree that it is to slow to be usable with. I wonder if it's worth trying some sort of " AND p.products_id IN ($options_in_stock), and set that variable in a separate query, but I thought JOIN was faster.
//Daniel
Re: Product Filters
Posted: Mon Apr 03, 2023 6:44 am
by Moxamint
Hi,
I hope this is a related question - how do I completely remove the core product filter?
Thanks, Eddy