Magento 2 Mageplaza LayeredNavigation filter condition AND instead of OR for multiselect
-
09-03-2021 - |
题
I am working on a site that uses Mageplaza Layered Navigation in Porto Theme.
I need to change the behavior of multiselect from OR to AND.
As an example, I create attribute color. When I search for blue and red, it should only show products that are blue AND red.
Multiselect is correctly set, the only problem is to change the code - I cannot find where should I change.
解决方案
To make multi-select with AND behaviour in Mageplaza LayeredNavigation, you will have to edit initObserve
function of app/code/Mageplaza/LayeredNavigation/view/frontend/web/js/layer.js
where you have to set the logic for allowing to select multiple links(passing multiple values in url for example: base url/category url?color=51,49 ) & then to edit collection you have to set logic in public function apply(\Magento\Framework\App\RequestInterface $request)
of
app/code/Mageplaza/LayeredNavigation/Model/Layer/Filter/Attribute.php
file for attributes, Similarly for category edit app/code/Mageplaza/LayeredNavigation/Model/Layer/Filter/Category.php
, for price
app/code/Mageplaza/LayeredNavigation/Model/Layer/Filter/Price.php
& for decimal type edit app/code/Mageplaza/LayeredNavigation/Model/Layer/Filter/Price.php/Decimal.php
其他提示
in the class Attribute when I filter:
$productCollection->addFieldToFilter($attribute->getAttributeCode(), ["finset" => $filters]);
with elasticsearch mode, I have the following error: {"type":"parsing_exception","reason":"[terms] unknown token [START_ARRAY] after [finset]","line":1,"col":228}
What could be causing the error? Thanks