Пример #1
0
 /**
  * {@inheritdoc}
  */
 public function searchTaxRules(SearchCriteria $searchCriteria)
 {
     $this->taxRuleSearchResultsBuilder->setSearchCriteria($searchCriteria);
     $collection = $this->taxRuleModelFactory->create()->getCollection();
     //Add filters from root filter group to the collection
     foreach ($searchCriteria->getFilterGroups() as $group) {
         $this->addFilterGroupToCollection($group, $collection);
     }
     $this->taxRuleSearchResultsBuilder->setTotalCount($collection->getSize());
     $sortOrders = $searchCriteria->getSortOrders();
     if ($sortOrders) {
         foreach ($sortOrders as $field => $direction) {
             $field = $this->translateField($field);
             $collection->addOrder($field, $direction == SearchCriteria::SORT_ASC ? 'ASC' : 'DESC');
         }
     }
     $collection->setCurPage($searchCriteria->getCurrentPage());
     $collection->setPageSize($searchCriteria->getPageSize());
     $taxRules = [];
     /** @var TaxRuleModel $taxRuleModel */
     foreach ($collection as $taxRuleModel) {
         $taxRule = $this->converter->createTaxRuleDataObjectFromModel($taxRuleModel);
         $taxRules[] = $taxRule;
     }
     $this->taxRuleSearchResultsBuilder->setItems($taxRules);
     return $this->taxRuleSearchResultsBuilder->create();
 }
Пример #2
0
 /**
  * @param array $dataArray
  * @return TaxRuleSearchResults
  */
 protected function generateDataObjectWithSetters($dataArray)
 {
     $this->builder->populateWithArray([]);
     if (array_key_exists(TaxRuleSearchResults::KEY_ITEMS, $dataArray)) {
         $items = [];
         foreach ($dataArray[TaxRuleSearchResults::KEY_ITEMS] as $itemArray) {
             $items[] = $this->taxRuleBuilder->populateWithArray($itemArray)->create();
         }
         $this->builder->setItems($items);
     }
     if (array_key_exists(TaxRuleSearchResults::KEY_TOTAL_COUNT, $dataArray)) {
         $this->builder->setTotalCount($dataArray[TaxRuleSearchResults::KEY_TOTAL_COUNT]);
     }
     if (array_key_exists(TaxRuleSearchResults::KEY_SEARCH_CRITERIA, $dataArray)) {
         $this->builder->setSearchCriteria($this->searchCriteriaBuilder->populateWithArray($dataArray[TaxRuleSearchResults::KEY_SEARCH_CRITERIA])->create());
     }
     return $this->builder->create();
 }
Пример #3
0
 /**
  * {@inheritdoc}
  */
 public function searchTaxRules(SearchCriteria $searchCriteria)
 {
     $this->taxRuleSearchResultsBuilder->setSearchCriteria($searchCriteria);
     $collection = $this->taxRuleModelFactory->create()->getCollection();
     $fields = [];
     //Add filters from root filter group to the collection
     foreach ($searchCriteria->getFilterGroups() as $group) {
         $this->addFilterGroupToCollection($group, $collection);
         foreach ($group->getFilters() as $filter) {
             $fields[] = $this->translateField($filter->getField());
         }
     }
     if ($fields) {
         if (in_array('cd.customer_tax_class_id', $fields) || in_array('cd.product_tax_class_id', $fields)) {
             $collection->joinCalculationData('cd');
         }
     }
     $this->taxRuleSearchResultsBuilder->setTotalCount($collection->getSize());
     $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());
     $taxRules = [];
     /** @var TaxRuleModel $taxRuleModel */
     foreach ($collection as $taxRuleModel) {
         $taxRule = $this->converter->createTaxRuleDataObjectFromModel($taxRuleModel);
         $taxRules[] = $taxRule;
     }
     $this->taxRuleSearchResultsBuilder->setItems($taxRules);
     return $this->taxRuleSearchResultsBuilder->create();
 }