taxRateRepository = $rateService; $this->rateConverter = $rateConverter; } /** * {@inheritdoc} */ public function loadData($printQuery = false, $logQuery = false) { if (!$this->isLoaded()) { $searchCriteria = $this->getSearchCriteria(); $searchResults = $this->taxRateRepository->getList($searchCriteria); $this->_totalRecords = $searchResults->getTotalCount(); foreach ($searchResults->getItems() as $taxRate) { $this->_addItem($this->createTaxRateCollectionItem($taxRate)); } $this->_setIsLoaded(); } return $this; } /** * Creates a collection item that represents a tax rate for the tax rates grid. * * @param TaxRate $taxRate Input data for creating the item. * @return \Magento\Framework\DataObject Collection item that represents a tax rate */ protected function createTaxRateCollectionItem(TaxRate $taxRate) { $collectionItem = new \Magento\Framework\DataObject(); $collectionItem->setTaxCalculationRateId($taxRate->getId()); $collectionItem->setCode($taxRate->getCode()); $collectionItem->setTaxCountryId($taxRate->getTaxCountryId()); $collectionItem->setTaxRegionId($taxRate->getTaxRegionId()); $collectionItem->setRegionName($taxRate->getRegionName()); $collectionItem->setTaxPostcode($taxRate->getTaxPostcode()); $collectionItem->setRate($taxRate->getRate()); $collectionItem->setTitles($this->rateConverter->createTitleArrayFromServiceObject($taxRate)); if ($taxRate->getZipTo() != null && $taxRate->getZipFrom() != null) { /* must be a "1" for existing code (e.g. JavaScript) to work */ $collectionItem->setZipIsRange("1"); $collectionItem->setZipFrom($taxRate->getZipFrom()); $collectionItem->setZipTo($taxRate->getZipTo()); } else { $collectionItem->setZipIsRange(null); $collectionItem->setZipFrom(null); $collectionItem->setZipTo(null); } return $collectionItem; } }