Skip to content

Commit

Permalink
Add sort order to facet attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
RBech committed Nov 15, 2018
1 parent 7d466c2 commit 2e6307b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
19 changes: 12 additions & 7 deletions Block/Result.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,22 @@ public function getSpanAttributes()
];

if ($this->_scopeConfig->isSetFlag(Config::XML_PATH_FACETED_SEARCH_ENABLED)) {
if ($attributes = $this->_scopeConfig->getValue(Config::XML_PATH_FACETED_SEARCH_ATTRIBUTES)) {
$spanAttributes['data-facets-target'] = "#clerk-search-filters";
$spanAttributes['data-facets-attributes'] = '["' . str_replace(',', '","', $attributes) . '"]';
$spanAttributes['data-facets-target'] = "#clerk-search-filters";

if ($titles = $this->_scopeConfig->getValue(Config::XML_PATH_FACETED_SEARCH_TITLES)) {
$titles = json_decode($titles, true);

// sort alphabetically by name
uasort($titles, function($a, $b) {
return $a['sort_order'] > $b['sort_order'];
});

$spanAttributes['data-facets-titles'] = json_encode(array_filter(array_combine(array_keys($titles), array_column($titles, 'label'))));
$spanAttributes['data-facets-attributes'] = json_encode(array_keys($titles));

if ($multiselectAttributes = $this->_scopeConfig->getValue(Config::XML_PATH_FACETED_SEARCH_MULTISELECT_ATTRIBUTES)) {
$spanAttributes['data-facets-multiselect-attributes'] = '["' . str_replace(',', '","', $multiselectAttributes) . '"]';
}

if ($titles = $this->_scopeConfig->getValue(Config::XML_PATH_FACETED_SEARCH_TITLES)) {
$spanAttributes['data-facets-titles'] = $titles;
}
}
}

Expand Down
6 changes: 5 additions & 1 deletion view/adminhtml/templates/facettitles.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ $values = json_decode($element->getValue(), true);
<tr>
<th class="col-store-view"><?php echo __('Default'); ?></th>
<th class="col-store-view"><?php echo $block->getScopeLabel(); ?></th>
<th class="col-store-view"><?php echo __('Sort Order'); ?></th>
</tr>
</thead>
<tbody>
Expand All @@ -20,7 +21,10 @@ $values = json_decode($element->getValue(), true);
<input class="input-text" id="_orig" value="<?php echo $attribute; ?>" type="text" readonly>
</td>
<td class="col-store-view">
<input class="input-text" id="" name="<?php echo $element->getName(); ?>[<?php echo $attribute; ?>]" value="<?php echo $value; ?>" type="text">
<input class="input-text" id="" name="<?php echo $element->getName(); ?>[<?php echo $attribute; ?>][label]" value="<?php echo $value['label']; ?>" type="text">
</td>
<td class="col-store-view">
<input class="input-text" id="" name="<?php echo $element->getName(); ?>[<?php echo $attribute; ?>][sort_order]" value="<?php echo $value['sort_order']; ?>" type="text">
</td>
</tr>
<?php endforeach; ?>
Expand Down

0 comments on commit 2e6307b

Please sign in to comment.