/** * Retrieve all customer tax classes as an options array. * * @param bool $withEmpty * @return array */ public function getAllOptions($withEmpty = false) { if (!$this->_options) { $filter = $this->filterBuilder->setField(TaxClass::KEY_TYPE)->setValue(\Magento\Tax\Service\V1\TaxClassServiceInterface::TYPE_CUSTOMER)->create(); $searchCriteria = $this->searchCriteriaBuilder->addFilter([$filter])->create(); $searchResults = $this->taxClassService->searchTaxClass($searchCriteria); foreach ($searchResults->getItems() as $taxClass) { $this->_options[] = array('value' => $taxClass->getClassId(), 'label' => $taxClass->getClassName()); } } if ($withEmpty) { return array_merge(array(array('value' => '0', 'label' => __('None'))), $this->_options); } return $this->_options; }
/** * Verifies that the tax class model exists and is a customer tax class type. * * @param int $taxClassId The id of the tax class model to check * @param CustomerGroup $group The original group parameters * @return void * @throws InputException Thrown if the tax class model is invalid */ protected function _verifyTaxClassModel($taxClassId, $group) { try { /* @var TaxClass $taxClassData */ $taxClassData = $this->_taxClassService->getTaxClass($taxClassId); } catch (NoSuchEntityException $e) { throw InputException::invalidFieldValue('taxClassId', $group->getTaxClassId()); } if ($taxClassData->getClassType() !== TaxClassServiceInterface::TYPE_CUSTOMER) { throw InputException::invalidFieldValue('taxClassId', $group->getTaxClassId()); } }