Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Dynamic.php
Go to the documentation of this file.
1 <?php
7 
13 use Magento\Framework\Search\Request\BucketInterface as RequestBucketInterface;
14 
16 {
20  private $algorithmRepository;
21 
25  private $entityStorageFactory;
26 
31  public function __construct(Repository $algorithmRepository, EntityStorageFactory $entityStorageFactory)
32  {
33  $this->algorithmRepository = $algorithmRepository;
34  $this->entityStorageFactory = $entityStorageFactory;
35  }
36 
40  public function build(
41  RequestBucketInterface $bucket,
42  array $dimensions,
43  array $queryResult,
44  DataProviderInterface $dataProvider
45  ) {
47  $algorithm = $this->algorithmRepository->get($bucket->getMethod(), ['dataProvider' => $dataProvider]);
48  $data = $algorithm->getItems($bucket, $dimensions, $this->getEntityStorage($queryResult));
49  $resultData = $this->prepareData($data);
50 
51  return $resultData;
52  }
53 
60  private function getEntityStorage(array $queryResult)
61  {
62  $ids = [];
63  foreach ($queryResult['hits']['hits'] as $document) {
64  $ids[] = $document['_id'];
65  }
66 
67  return $this->entityStorageFactory->create($ids);
68  }
69 
76  private function prepareData($data)
77  {
78  $resultData = [];
79  foreach ($data as $value) {
80  $from = is_numeric($value['from']) ? $value['from'] : '*';
81  $to = is_numeric($value['to']) ? $value['to'] : '*';
82  unset($value['from'], $value['to']);
83 
84  $rangeName = "{$from}_{$to}";
85  $resultData[$rangeName] = array_merge(['value' => $rangeName], $value);
86  }
87 
88  return $resultData;
89  }
90 }
$value
Definition: gender.phtml:16
__construct(Repository $algorithmRepository, EntityStorageFactory $entityStorageFactory)
Definition: Dynamic.php:31
build(RequestBucketInterface $bucket, array $dimensions, array $queryResult, DataProviderInterface $dataProvider)