1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file was created by developers working at BitBag |
5
|
|
|
* Do you need more information about us and what we do? Visit our https://bitbag.io website! |
6
|
|
|
* We are hiring developers from all over the world. Join us and start your new, exciting adventure and become part of us: https://bitbag.io/career |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
declare(strict_types=1); |
10
|
|
|
|
11
|
|
|
namespace BitBag\SyliusElasticsearchPlugin\Finder; |
12
|
|
|
|
13
|
|
|
use BitBag\SyliusElasticsearchPlugin\Controller\RequestDataHandler\PaginationDataHandlerInterface; |
14
|
|
|
use BitBag\SyliusElasticsearchPlugin\Controller\RequestDataHandler\SortDataHandlerInterface; |
15
|
|
|
use BitBag\SyliusElasticsearchPlugin\QueryBuilder\QueryBuilderInterface; |
16
|
|
|
use Elastica\Query; |
17
|
|
|
use FOS\ElasticaBundle\Finder\PaginatedFinderInterface; |
18
|
|
|
use Pagerfanta\Pagerfanta; |
19
|
|
|
|
20
|
|
|
final class ShopProductsFinder implements ShopProductsFinderInterface |
21
|
|
|
{ |
22
|
|
|
/** @var QueryBuilderInterface */ |
23
|
|
|
private $shopProductsQueryBuilder; |
24
|
|
|
|
25
|
|
|
/** @var PaginatedFinderInterface */ |
26
|
|
|
private $productFinder; |
27
|
|
|
|
28
|
|
|
public function __construct( |
29
|
|
|
QueryBuilderInterface $shopProductsQueryBuilder, |
30
|
|
|
PaginatedFinderInterface $productFinder |
31
|
|
|
) { |
32
|
|
|
$this->shopProductsQueryBuilder = $shopProductsQueryBuilder; |
33
|
|
|
$this->productFinder = $productFinder; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
public function find(array $data): Pagerfanta |
37
|
|
|
{ |
38
|
|
|
$boolQuery = $this->shopProductsQueryBuilder->buildQuery($data); |
39
|
|
|
|
40
|
|
|
$query = new Query($boolQuery); |
41
|
|
|
$query->addSort($data[SortDataHandlerInterface::SORT_INDEX]); |
42
|
|
|
|
43
|
|
|
$products = $this->productFinder->findPaginated($query); |
44
|
|
|
$products->setMaxPerPage($data[PaginationDataHandlerInterface::LIMIT_INDEX]); |
45
|
|
|
$products->setCurrentPage($data[PaginationDataHandlerInterface::PAGE_INDEX]); |
46
|
|
|
|
47
|
|
|
return $products; |
48
|
|
|
} |
49
|
|
|
} |
50
|
|
|
|