Esempio n. 1
0
 /**
  * Retrieve tax classes which match a specific criteria.
  *
  * @param \Magento\Framework\Service\V1\Data\SearchCriteria $searchCriteria
  * @return \Magento\Tax\Service\V1\Data\TaxClassSearchResults containing Data\TaxClass
  * @throws \Magento\Framework\Exception\InputException
  */
 public function searchTaxClass(\Magento\Framework\Service\V1\Data\SearchCriteria $searchCriteria)
 {
     $this->searchResultsBuilder->setSearchCriteria($searchCriteria);
     /** @var TaxClassCollection $collection */
     $collection = $this->taxClassCollectionFactory->create();
     /** TODO: This method duplicates functionality of search methods in other services and should be refactored. */
     foreach ($searchCriteria->getFilterGroups() as $group) {
         $this->addFilterGroupToCollection($group, $collection);
     }
     $this->searchResultsBuilder->setTotalCount($collection->getSize());
     $sortOrders = $searchCriteria->getSortOrders();
     if ($sortOrders) {
         foreach ($searchCriteria->getSortOrders() as $field => $direction) {
             $collection->addOrder($field, $direction == SearchCriteria::SORT_ASC ? 'ASC' : 'DESC');
         }
     }
     $collection->setCurPage($searchCriteria->getCurrentPage());
     $collection->setPageSize($searchCriteria->getPageSize());
     $taxClasses = [];
     /** @var \Magento\Tax\Model\ClassModel $taxClassModel */
     foreach ($collection->getItems() as $taxClassModel) {
         $taxClasses[] = $this->converter->createTaxClassData($taxClassModel);
     }
     $this->searchResultsBuilder->setItems($taxClasses);
     return $this->searchResultsBuilder->create();
 }