searchCriteriaBuilder = $searchCriteriaBuilder; $this->ratesProvider = $ratesProvider; } /** * Get rates page via AJAX * * @return Json * @throws \InvalidArgumentException */ public function execute() { $ratesPage = (int) $this->getRequest()->getParam('p'); $ratesFilter = trim($this->getRequest()->getParam('s')); try { if (!empty($ratesFilter)) { $this->searchCriteriaBuilder->addFilter( Rate::KEY_CODE, '%'.$ratesFilter.'%', 'like' ); } $searchCriteria = $this->searchCriteriaBuilder ->setPageSize($this->ratesProvider->getPageSize()) ->setCurrentPage($ratesPage) ->create(); $options = $this->ratesProvider->toOptionArray($searchCriteria); $response = [ 'success' => true, 'errorMessage' => '', 'result'=> $options, ]; } catch (\Exception $e) { $response = [ 'success' => false, 'errorMessage' => __('An error occurred while loading tax rates.') ]; } /** @var Json $resultJson */ $resultJson = $this->resultFactory->create(ResultFactory::TYPE_JSON); $resultJson->setData($response); return $resultJson; } }