/**
  * Initiate tax classes.
  *
  * @return $this
  */
 protected function initTaxClasses()
 {
     if (empty($this->taxClasses)) {
         $collection = $this->collectionFactory->create();
         $collection->addFieldToFilter('class_type', ClassModel::TAX_CLASS_TYPE_PRODUCT);
         /* @var $collection \Magento\Tax\Model\ResourceModel\TaxClass\Collection */
         foreach ($collection as $taxClass) {
             $this->taxClasses[$taxClass->getClassName()] = $taxClass->getId();
         }
     }
     return $this;
 }
Example #2
0
 /**
  * {@inheritdoc}
  */
 public function getList(\Magento\Framework\Api\SearchCriteriaInterface $searchCriteria)
 {
     $searchResults = $this->searchResultsFactory->create();
     $searchResults->setSearchCriteria($searchCriteria);
     /** @var TaxClassCollection $collection */
     $collection = $this->taxClassCollectionFactory->create();
     $this->joinProcessor->process($collection);
     foreach ($searchCriteria->getFilterGroups() as $group) {
         $this->addFilterGroupToCollection($group, $collection);
     }
     $searchResults->setTotalCount($collection->getSize());
     $sortOrders = $searchCriteria->getSortOrders();
     /** @var SortOrder $sortOrder */
     if ($sortOrders) {
         foreach ($searchCriteria->getSortOrders() as $sortOrder) {
             $collection->addOrder($sortOrder->getField(), $sortOrder->getDirection() == SortOrder::SORT_ASC ? 'ASC' : 'DESC');
         }
     }
     $collection->setCurPage($searchCriteria->getCurrentPage());
     $collection->setPageSize($searchCriteria->getPageSize());
     $searchResults->setItems($collection->getItems());
     return $searchResults;
 }