Product Filters
- Kofod95
- Senior Contributor
- Posts: 748
- Joined: Sat Feb 06, 2021 7:38 pm
- Phoenix Version: 1.0.8.20
- Has thanked: 99 times
- Been thanked: 179 times
Product Filters
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
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
You do not have the required permissions to view the files attached to this post.
I'm not smart, but sometimes even a blind chicken can find a corn.
Here are a lot of corns: Phoenix user guide
Here are a lot of corns: Phoenix user guide
Tags:
-
ecartz
- Core Team
- Posts: 3084
- Joined: Tue Nov 05, 2019 6:02 pm
- Phoenix Version:
- Has thanked: 4 times
- Been thanked: 208 times
Re: Product Filters
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,could be without any change in functionality.
could be
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);Code: Select all
if(!empty($group_by)) $GLOBALS['filter_listing'] .= ' GROUP BY p.products_id';Code: Select all
$active_filters = [];
$applied_filters = $_GET['f'];
foreach($applied_filters as $k => $v){
if($v != '') array_push($active_filters, $k);
}Code: Select all
$active_filters = array_keys(array_filter($_GET['f']));- Kofod95
- Senior Contributor
- Posts: 748
- Joined: Sat Feb 06, 2021 7:38 pm
- Phoenix Version: 1.0.8.20
- Has thanked: 99 times
- Been thanked: 179 times
Re: Product Filters
Awesome, @ecartz, thank you!
I will apply your suggestions and re-upload.
//Daniel
I will apply your suggestions and re-upload.
//Daniel
I'm not smart, but sometimes even a blind chicken can find a corn.
Here are a lot of corns: Phoenix user guide
Here are a lot of corns: Phoenix user guide
- Kofod95
- Senior Contributor
- Posts: 748
- Joined: Sat Feb 06, 2021 7:38 pm
- Phoenix Version: 1.0.8.20
- Has thanked: 99 times
- Been thanked: 179 times
Re: Product Filters
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
I'm not smart, but sometimes even a blind chicken can find a corn.
Here are a lot of corns: Phoenix user guide
Here are a lot of corns: Phoenix user guide
-
Omar_one
- Senior Contributor
- Posts: 679
- Joined: Fri Oct 25, 2019 5:06 pm
- Phoenix Version: v1.0.8.16
- Has thanked: 100 times
- Been thanked: 56 times
Re: Product Filters
@ecartz @Kofod95
I just applied the changes
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
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
I just applied the changes
there is extra ")"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');
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);
}Thank you
Omar
-
ecartz
- Core Team
- Posts: 3084
- Joined: Tue Nov 05, 2019 6:02 pm
- Phoenix Version:
- Has thanked: 4 times
- Been thanked: 208 times
Re: Product Filters
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.
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.
-
Omar_one
- Senior Contributor
- Posts: 679
- Joined: Fri Oct 25, 2019 5:06 pm
- Phoenix Version: v1.0.8.16
- Has thanked: 100 times
- Been thanked: 56 times
-
Omar_one
- Senior Contributor
- Posts: 679
- Joined: Fri Oct 25, 2019 5:06 pm
- Phoenix Version: v1.0.8.16
- Has thanked: 100 times
- Been thanked: 56 times
Re: Product Filters
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
- Kofod95
- Senior Contributor
- Posts: 748
- Joined: Sat Feb 06, 2021 7:38 pm
- Phoenix Version: 1.0.8.20
- Has thanked: 99 times
- Been thanked: 179 times
Re: Product Filters
Sorry for being slow to react here!
I found a couple of bugs as well, so a revised version will come, though it may take a while.
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
This works fine as long as there are no "range"-filters - I guess I could target them afterwards.ecartz wrote: ↑Mon Jan 02, 2023 11:55 pmCode: Select all
$active_filters = array_keys(array_filter($_GET['f']));
I found a couple of bugs as well, so a revised version will come, though it may take a while.
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
I'm not smart, but sometimes even a blind chicken can find a corn.
Here are a lot of corns: Phoenix user guide
Here are a lot of corns: Phoenix user guide