Jump to content

Bug : faceted search doesn't filter products with attributes stock = 0


Recommended Posts

Hi,

I already searched around this forum + google but i have no solution.

- Presta 1.7.6.4 

- Faceted search 3.5.0

 

Problem : faceted search doesn't filter attribute stock = 0

- have XXL size for product P1,P2,..., Pn

- P1 have stock = 0 for XXL size

- in catalog, if i use the filter attribute 'size XXL' the result shows P1..... while P1 doesn't have any stock in XXL.....

- the filter shouldn't show the product P1 with size XXL cause there is no stock with this attribute

 

 

Untitled-3.thumb.png.120f1aa3c9ea90ee8c7c814e5c56107e.pngUntitled-2.thumb.png.ba171bd62b373e2e8e08375f12062f92.pngUntitled-1.thumb.png.cc68609ed885e1e0c11a11e0a9aaf193.png

Any fix ?

Thanks

 

 

 

 

 

 

 

 

Share this post


Link to post
Share on other sites
  • 1 month later...

Never-ending "filters" story. This is not solved since I can remember. I did solve it through some forum answers for 1.5 and 1.6 but I can't get it to work for 1.7

Most people ended up buying an expensive module. What was your solution?

Share this post


Link to post
Share on other sites
  • 7 months later...

After reading a lot of forum topics and GitHub Issues marked as "solved", but solved only for older versions of Prestashop and, mainly, for older versions of the Faceted Search Module, I've found a solution, that works well form me.

Since all the queries have been replaced by calls to Search Adapter Objects, I've modified the file:

/modules/ps_facetedsearch/src/Product/Search.php

at line 147, modifying the source code from this:
 

                case 'id_attribute_group':
                    $operationsFilter = [];
                    foreach ($filterValues as $attributeId => $filterValue) {
                        $this->getSearchAdapter()->addOperationsFilter(
                            'with_attributes_' . $attributeId,
                            [[['id_attribute', $filterValue]]]
                        );
                    }
                    break;

to this:

                case 'id_attribute_group':
                    $operationsFilter = [];
                    foreach ($filterValues as $attributeId => $filterValue) {
                        $this->getSearchAdapter()->addOperationsFilter(
                            'with_attributes_' . $attributeId,
                            [[['id_attribute', $filterValue]]]
                        );
                    }
                    //modded by Antonio to hide Out of Stock combinations
                    $operationsFilter = [];
                    $operationsFilter[] = [
                        ['quantity', [0], '>'],
                    ];
                    $this->getSearchAdapter()->addOperationsFilter(
                        self::STOCK_MANAGEMENT_FILTER,
                        $operationsFilter
                        );
                    break;

and finally it works!

Edited by antoniocici (see edit history)
  • Like 4

Share this post


Link to post
Share on other sites
On 1/18/2021 at 12:28 PM, antoniocici said:

After reading a lot of forum topics and GitHub Issues marked as "solved", but solved only for older versions of Prestashop and, mainly, for older versions of the Faceted Search Module, I've found a solution, that works well form me.

Since all the queries have been replaced by calls to Search Adapter Objects, I've modified the file:

/modules/ps_facetedsearch/src/Product/Search.php

at line 147, modifying the source code from this:
 


                case 'id_attribute_group':
                    $operationsFilter = [];
                    foreach ($filterValues as $attributeId => $filterValue) {
                        $this->getSearchAdapter()->addOperationsFilter(
                            'with_attributes_' . $attributeId,
                            [[['id_attribute', $filterValue]]]
                        );
                    }
                    break;

to this:


                case 'id_attribute_group':
                    $operationsFilter = [];
                    foreach ($filterValues as $attributeId => $filterValue) {
                        $this->getSearchAdapter()->addOperationsFilter(
                            'with_attributes_' . $attributeId,
                            [[['id_attribute', $filterValue]]]
                        );
                    }
                    //modded by Antonio to hide Out of Stock combinations
                    $operationsFilter = [];
                    $operationsFilter[] = [
                        ['quantity', [0], '>'],
                    ];
                    $this->getSearchAdapter()->addOperationsFilter(
                        self::STOCK_MANAGEMENT_FILTER,
                        $operationsFilter
                        );
                    break;

and finally it works!

Great!!!!

 

Many thanks

 

Angela

Share this post


Link to post
Share on other sites
  • 3 weeks later...

Hi,

It's worked for the product lists.
But not in the number of available products.

For example, in the filter, I have Size 39 (5).
And below, I have 4 products because really I have 4 products available in this size.

An idea to change that? I mean to have 39 (4)...

Thanks 
Sandrine

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More