Esempio n. 1
0
 /**
  * Find entities by criteria
  *
  * @param \Magento\Framework\Service\V1\Data\SearchCriteria  $criteria
  * @return Transaction[]
  */
 public function find(\Magento\Framework\Service\V1\Data\SearchCriteria $criteria)
 {
     /** @var TransactionResource\Collection $collection */
     $collection = $this->transactionCollectionFactory->create();
     foreach ($criteria->getFilterGroups() as $filterGroup) {
         foreach ($filterGroup->getFilters() as $filter) {
             $condition = $filter->getConditionType() ? $filter->getConditionType() : 'eq';
             $collection->addFieldToFilter($filter->getField(), [$condition => $filter->getValue()]);
         }
     }
     $collection->setCurPage($criteria->getCurrentPage());
     $collection->setPageSize($criteria->getPageSize());
     $collection->addPaymentInformation(['method']);
     $collection->addOrderInformation(['increment_id']);
     foreach ($collection as $object) {
         $this->register($object);
     }
     $objectIds = $collection->getAllIds();
     return array_intersect_key($this->registry, array_flip($objectIds));
 }
Esempio n. 2
0
 /**
  * {@inheritdoc}
  */
 public function searchTaxRates(SearchCriteria $searchCriteria)
 {
     /** @var \Magento\Tax\Model\Resource\Calculation\Rate\Collection $collection */
     $collection = $this->rateFactory->create()->getCollection();
     $collection->joinRegionTable();
     //Add filters from root filter group to the collection
     foreach ($searchCriteria->getFilterGroups() as $group) {
         $this->addFilterGroupToCollection($group, $collection);
     }
     $sortOrders = $searchCriteria->getSortOrders();
     /** @var SortOrder $sortOrder */
     if ($sortOrders) {
         foreach ($sortOrders as $sortOrder) {
             $collection->addOrder($this->translateField($sortOrder->getField()), $sortOrder->getDirection() == SearchCriteria::SORT_ASC ? 'ASC' : 'DESC');
         }
     }
     $collection->setCurPage($searchCriteria->getCurrentPage());
     $collection->setPageSize($searchCriteria->getPageSize());
     $taxRate = [];
     /** @var \Magento\Tax\Model\Calculation\Rate $taxRateModel */
     foreach ($collection as $taxRateModel) {
         $taxRate[] = $this->converter->createTaxRateDataObjectFromModel($taxRateModel);
     }
     return $this->taxRateSearchResultsBuilder->setItems($taxRate)->setTotalCount($collection->getSize())->setSearchCriteria($searchCriteria)->create();
 }