ruleService = $ruleService; } /** * {@inheritdoc} */ public function loadData($printQuery = false, $logQuery = false) { if (!$this->isLoaded()) { $searchCriteria = $this->getSearchCriteria(); $searchResults = $this->ruleService->getList($searchCriteria); $this->_totalRecords = $searchResults->getTotalCount(); foreach ($searchResults->getItems() as $taxRule) { $this->_addItem($this->createTaxRuleCollectionItem($taxRule)); } $this->_setIsLoaded(); } return $this; } /** * Creates a collection item that represents a tax rule for the tax rules grid. * * @param TaxRuleInterface $taxRule Input data for creating the item. * @return \Magento\Framework\DataObject Collection item that represents a tax rule */ protected function createTaxRuleCollectionItem(TaxRuleInterface $taxRule) { $collectionItem = new \Magento\Framework\DataObject(); $collectionItem->setTaxCalculationRuleId($taxRule->getId()); $collectionItem->setCode($taxRule->getCode()); /* should cast to string so that some optional fields won't be null on the collection grid pages */ $collectionItem->setPriority((string)$taxRule->getPriority()); $collectionItem->setPosition((string)$taxRule->getPosition()); $collectionItem->setCalculateSubtotal($taxRule->getCalculateSubtotal() ? '1' : '0'); $collectionItem->setCustomerTaxClasses($taxRule->getCustomerTaxClassIds()); $collectionItem->setProductTaxClasses($taxRule->getProductTaxClassIds()); $collectionItem->setTaxRatesCodes($taxRule->getTaxRatesCodes()); $collectionItem->setTaxRates($taxRule->getTaxRateIds()); return $collectionItem; } }