Provider.php 1.6 KB

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