1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Tax\Model\Rate;
use Magento\Framework\Convert\DataObject as Converter;
use Magento\Tax\Api\TaxRateRepositoryInterface;
use Magento\Framework\Api\SearchCriteriaInterface;
use Magento\Tax\Model\Calculation\Rate;
/**
* Provides filtered tax rates models
* as options for select element.
*/
class Provider
{
/**
* @var TaxRateRepositoryInterface
*/
private $taxRateRepository;
/**
* @var Converter
*/
private $converter;
/**
* @var int
*/
private $pageSize = 100;
/**
* Initialize dependencies.
*
* @param TaxRateRepositoryInterface $taxRateRepository
* @param Converter $converter
*/
public function __construct(
TaxRateRepositoryInterface $taxRateRepository,
Converter $converter
) {
$this->taxRateRepository = $taxRateRepository;
$this->converter = $converter;
}
/**
* Retrieve all tax rates as an options array.
*
* @param SearchCriteriaInterface $searchCriteria
* @return array
*/
public function toOptionArray(SearchCriteriaInterface $searchCriteria)
{
$searchResults = $this->taxRateRepository->getList($searchCriteria);
return $this->converter->toOptionArray(
$searchResults->getItems(),
Rate::KEY_ID,
Rate::KEY_CODE
);
}
/**
* Returns predefined size of tax rates list
*
* @return int
*/
public function getPageSize()
{
return (int) $this->pageSize;
}
}