Adding resources' item sets to facets in Advanced Search

Hi !

I need an item set name facet so that I can show items belonging to that item set in advanced search.

When I create an item, I link an item set to it in the “item sets” tab. The problem is that when using that method, I can’t find the item set in the item’s properties.

My other problem is that I can’t find how to show item set names in the facet. All I could find in the facet list in the search manager configuration is “item_set_id = Item set = Select”, which only shows the item set’s ID.

How can I replace those IDs with their corresponding item set name ?

Thank you :slight_smile:

I found a solution :
In my_theme/view/search/facet-select.phtml, which I got from the advanced search module, I choose which item sets to show with respect to their resource template. So, supposing I only want to show item sets which use my_template :

$all_templates = $this->api()->search('resource_templates', array())->getContent();

$my_template_id = 0;
foreach($all_templates as $current_template){
    if ( $current_template->label() == "my_template" ){
        $my_template_id = $current_template->id();
        break;
    }
}

Then, since I use a “item_set_id” facet to show my item set :

<?php if( $name == "item_set_id" ) : ?>
    <?php foreach ($facetValues as $facetValue): ?>
        <?php 
        //Return template id from current item set
        $facet_item_set = $this->api()->read('item_sets', intval($facetValue['value']))->getContent();
        $item_set_template_id = $facet_item_set->resourceTemplate()->id();
        // If the current item set doesn't use the "my_template" resource template, we skip it.
        if( $item_set_template_id != $my_template_id ) { continue; } 
        
        // We show the title of the item_set instead of its ID ?>
        <option value="<?= $escapeAttr($facetValue['value']) ?>"<?= $isFacetModeDirect ? ' data-url="' . $escapeAttr($facetValue['url']) . '"' : '' ?><?= $facetValue['active'] ? ' selected="selected"' : '' ?>>
            <?= $escape($facet_item_set->displayTitle()) ?><?php if ($displayCount): ?> (<span class="count"><?= $facetValue['count'] ?>)<?php endif; ?>
        </option>
    <?php endforeach; ?>
<?php else : // We switch back to the regular facet-select template ?>
    <?php foreach ($facetValues as $facetValue): ?>
    
    <option value="<?= $escapeAttr($facetValue['value']) ?>"<?= $isFacetModeDirect ? ' data-url="' . $escapeAttr($facetValue['url']) . '"' : '' ?><?= $facetValue['active'] ? ' selected="selected"' : '' ?>>
        <?= $escape($facetValue['value']) ?><?php if ($displayCount): ?> (<span class="count"><?= $facetValue['count'] ?>)<?php endif; ?>
    </option>
    <?php endforeach; ?>
<?php endif; ?>
</select>