Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
TaxRateCollection.php
Go to the documentation of this file.
1 <?php
7 namespace Magento\Tax\Model;
8 
16 
22 {
26  protected $taxRateRepository;
27 
31  protected $rateConverter;
32 
43  public function __construct(
44  EntityFactory $entityFactory,
48  TaxRateRepositoryInterface $rateService,
49  \Magento\Tax\Model\Calculation\Rate\Converter $rateConverter
50  ) {
51  parent::__construct($entityFactory, $filterBuilder, $searchCriteriaBuilder, $sortOrderBuilder);
52  $this->taxRateRepository = $rateService;
53  $this->rateConverter = $rateConverter;
54  }
55 
59  public function loadData($printQuery = false, $logQuery = false)
60  {
61  if (!$this->isLoaded()) {
62  $searchCriteria = $this->getSearchCriteria();
63  $searchResults = $this->taxRateRepository->getList($searchCriteria);
64  $this->_totalRecords = $searchResults->getTotalCount();
65  foreach ($searchResults->getItems() as $taxRate) {
67  }
68  $this->_setIsLoaded();
69  }
70  return $this;
71  }
72 
79  protected function createTaxRateCollectionItem(TaxRate $taxRate)
80  {
81  $collectionItem = new \Magento\Framework\DataObject();
82  $collectionItem->setTaxCalculationRateId($taxRate->getId());
83  $collectionItem->setCode($taxRate->getCode());
84  $collectionItem->setTaxCountryId($taxRate->getTaxCountryId());
85  $collectionItem->setTaxRegionId($taxRate->getTaxRegionId());
86  $collectionItem->setRegionName($taxRate->getRegionName());
87  $collectionItem->setTaxPostcode($taxRate->getTaxPostcode());
88  $collectionItem->setRate($taxRate->getRate());
89  $collectionItem->setTitles($this->rateConverter->createTitleArrayFromServiceObject($taxRate));
90 
91  if ($taxRate->getZipTo() != null && $taxRate->getZipFrom() != null) {
92  /* must be a "1" for existing code (e.g. JavaScript) to work */
93  $collectionItem->setZipIsRange("1");
94  $collectionItem->setZipFrom($taxRate->getZipFrom());
95  $collectionItem->setZipTo($taxRate->getZipTo());
96  } else {
97  $collectionItem->setZipIsRange(null);
98  $collectionItem->setZipFrom(null);
99  $collectionItem->setZipTo(null);
100  }
101 
102  return $collectionItem;
103  }
104 }
loadData($printQuery=false, $logQuery=false)
$searchCriteria
__construct(EntityFactory $entityFactory, FilterBuilder $filterBuilder, SearchCriteriaBuilder $searchCriteriaBuilder, SortOrderBuilder $sortOrderBuilder, TaxRateRepositoryInterface $rateService, \Magento\Tax\Model\Calculation\Rate\Converter $rateConverter)
$taxRate
Definition: tax_rule.php:12