K
K
Ksenia Ermolaeva2015-01-27 08:02:27
PHP
Ksenia Ermolaeva, 2015-01-27 08:02:27

How to display the values ​​of a multiple field in a filter?

Good afternoon!
Can you please tell me how to display in the filter for a multiple field only those values ​​that are used in the elements, and not the entire directory?
The infoblock has a multiple property with binding to the elements of another infoblock (as I understand it, it is analogous to using reference values). When inserting a filter on a page, the field of this property displays all the available values ​​of the linked infoblock, but it is necessary that only the involved values ​​be displayed.
Thank you!

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Alexey Emelyanov, 2015-01-27
@babarun

Either put a beta version of the new smart.filter (perhaps it has already been released) with faceted search, or take one of the solutions from the marketplace.
In order not to be accused of advertising, I can send a link to the solution that I use.

K
Ksenia Ermolaeva, 2015-01-27
@box0

Alexey Emeliano, thanks for the hint about faceted search.
I went the simplest way: because such a filter is needed only in one section, then I copied the "search.filter" component and added code in the "result_modifier.php" file to exclude from the result array those values ​​of the specified property that are not used in the elements of the information block.
Infoblock code = 4, initial property code = 252. Filter by active records (ACTIVE) and by active dates (ACTIVE_DATE) is also used. To select all different values ​​of the property with code 252 (PROPERTY_252), I used grouping (the third parameter is an array of the GetList function).
$IDs = [];
$rs = CIBlockElement::GetList(array(), array("IBLOCK_ID" => 4, "ACTIVE" => "Y", "ACTIVE_DATE" => "Y", "!PROPERTY_252" => false), array( "PROPERTY_252"));
while($ar = $rs->GetNext()) {
$IDs[] = $ar['PROPERTY_252_VALUE'];
}
Then I made a check in which, using regular expressions, I removed all values ​​from the $arResult['ITEMS']['PROPERTY_252']['INPUT'] array that were not in the resulting $IDs array.
Profit!

A
Anton Piletsky, 2015-02-01
@pilezkiy

In the smart filter component (catalog.smart.filter), values ​​that should not be displayed (the selected products do not), as far as I remember, are marked with the "DISABLED" key.
That is, you do not need to make additional queries in result_modifier.php, everything has already been done for you.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question