Jump to content

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


superskyman100

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

 

 

 

 

 

 

 

 

Link to comment
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?

Link to comment
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 6
  • Thanks 4
Link to comment
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

Link to comment
Share on other sites

  • 3 weeks later...
  • 1 year later...
On 2/11/2021 at 5:48 PM, sandrineparent said:

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

@antoniocici Any idea for that?

Link to comment
Share on other sites

  • 3 months later...
  • 3 weeks later...
  • 1 year later...

La solution proposée ne tient pas compte de la notion out_of_stock du produit. Il faudrait je pense :

$operationsFilter = [];
$operationsFilter[] = [
	['quantity', [0], '<='],
	['out_of_stock', !$this->psOrderOutOfStock ? [0, 2] : [0], '='],
];                
$operationsFilter[] = [
	['quantity', [0], '>'],
];
$this->getSearchAdapter()->addOperationsFilter(
	self::STOCK_MANAGEMENT_FILTER,
	$operationsFilter
);		

et pour la partie block, il suffit de faire la même chose dans src/Filters/Block.php [591] et ensuite de vider le cache du module.

Link to comment
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...