Skip to content

Commit

Permalink
Pass taxon to sort helper (#5)
Browse files Browse the repository at this point in the history
* Fix README

* Pass taxon to sort helper method

---------

Co-authored-by: Lorenzo Ruozzi <[email protected]>
  • Loading branch information
LucaGallinari and lruozzi9 authored Jul 4, 2024
1 parent 9e257ad commit 06be08a
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
6. Make your ProductAttribute and ProductOption entities implements the FilterableInterface. You can implement it by using our ready DoctrineORMFilterableTrait. For example:
```php
use Webgriffe\SyliusElasticsearchPlugin\Doctrine\ORM\FilterableTrait;use Webgriffe\SyliusElasticsearchPlugin\Model\FilterableInterface;
use Webgriffe\SyliusElasticsearchPlugin\Doctrine\ORM\FilterableTrait;use Webgriffe\SyliusElasticsearchPlugin\Model\FilterableInterface;

class ProductAttribute implements FilterableInterface
{
Expand Down
2 changes: 1 addition & 1 deletion src/Controller/ProductController.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public function __invoke(Request $request, string $slug): Response

/** @var array<string, string> $sorting */
$sorting = $request->query->all('sorting');
$sorting = $this->sortHelper->retrieveTaxonSorting($sorting);
$sorting = $this->sortHelper->retrieveTaxonSorting($taxon, $sorting);
$size = $request->query->getInt('limit', $this->taxonDefaultPageLimit);
$page = $request->query->getInt('page', 1);

Expand Down
4 changes: 3 additions & 1 deletion src/Helper/SortHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@

namespace Webgriffe\SyliusElasticsearchPlugin\Helper;

use Sylius\Component\Core\Model\TaxonInterface;

final class SortHelper implements SortHelperInterface
{
public function retrieveSearchSorting(array $sortingQueryParams = []): array
{
return $sortingQueryParams; // If empty it will sort by _score desc as default
}

public function retrieveTaxonSorting(array $sortingQueryParams = []): array
public function retrieveTaxonSorting(TaxonInterface $taxon, array $sortingQueryParams = []): array
{
if ($sortingQueryParams === []) {
return ['position' => 'asc'];
Expand Down
4 changes: 3 additions & 1 deletion src/Helper/SortHelperInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace Webgriffe\SyliusElasticsearchPlugin\Helper;

use Sylius\Component\Core\Model\TaxonInterface;

interface SortHelperInterface
{
/**
Expand All @@ -18,5 +20,5 @@ public function retrieveSearchSorting(array $sortingQueryParams = []): array;
*
* @return array<string, string>
*/
public function retrieveTaxonSorting(array $sortingQueryParams = []): array;
public function retrieveTaxonSorting(TaxonInterface $taxon, array $sortingQueryParams = []): array;
}

0 comments on commit 06be08a

Please sign in to comment.