Skip to content

Commit

Permalink
Adding fallback when default sort by is unset
Browse files Browse the repository at this point in the history
  • Loading branch information
romainruaud committed Oct 22, 2024
1 parent e80fc95 commit 9f5db3e
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/module-elasticsuite-virtual-category/Model/Preview.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class Preview extends AbstractPreview
/**
* @var string
*/
private $sortBy;
private $sortBy = null;

/**
* Constructor.
Expand Down Expand Up @@ -222,7 +222,12 @@ private function getSortBy() : string
$useConfig = $this->request->getParam('use_config', []);
$useConfig = array_key_exists('default_sort_by', $useConfig) && $useConfig['default_sort_by'] == 'true';
$defaultSortBy = $this->categoryConfig->getProductListDefaultSortBy();
$this->sortBy = $useConfig ? $defaultSortBy : $this->request->getParam('default_sort_by');
$sortBy = $this->request->getParam('default_sort_by', $defaultSortBy);
if (empty($sortBy) || ((string) $sortBy === '')) {
$sortBy = $defaultSortBy;
}

$this->sortBy = $useConfig ? $defaultSortBy : $sortBy;
}

return $this->sortBy;
Expand Down

0 comments on commit 9f5db3e

Please sign in to comment.