コード例 #1
0
 /**
  * @inheritdoc
  */
 protected function _renderFiltersBefore()
 {
     $this->getSearchCriteriaBuilder();
     $this->getFilterBuilder();
     $this->getSearch();
     if ($this->queryText) {
         $this->filterBuilder->setField('search_term');
         $this->filterBuilder->setValue($this->queryText);
         $this->searchCriteriaBuilder->addFilter($this->filterBuilder->create());
     }
     $priceRangeCalculation = $this->_scopeConfig->getValue(\Magento\Catalog\Model\Layer\Filter\Dynamic\AlgorithmFactory::XML_PATH_RANGE_CALCULATION, \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
     if ($priceRangeCalculation) {
         $this->filterBuilder->setField('price_dynamic_algorithm');
         $this->filterBuilder->setValue($priceRangeCalculation);
         $this->searchCriteriaBuilder->addFilter($this->filterBuilder->create());
     }
     $searchCriteria = $this->searchCriteriaBuilder->create();
     $searchCriteria->setRequestName($this->searchRequestName);
     $this->searchResult = $this->search->search($searchCriteria);
     $temporaryStorage = $this->temporaryStorageFactory->create();
     $table = $temporaryStorage->storeApiDocuments($this->searchResult->getItems());
     $this->getSelect()->joinInner(['search_result' => $table->getName()], 'e.entity_id = search_result.' . TemporaryStorage::FIELD_ENTITY_ID, []);
     $this->_totalRecords = $this->searchResult->getTotalCount();
     if ($this->order && 'relevance' === $this->order['field']) {
         $this->getSelect()->order('search_result.' . TemporaryStorage::FIELD_SCORE . ' ' . $this->order['dir']);
     }
     return parent::_renderFiltersBefore();
 }
コード例 #2
0
 /**
  * Add attributes that have a range (from,to) to the SearchCriteriaBuilder.
  *
  * @param string $attributeCode
  * @param array|string $attributeValue
  * @return void
  */
 private function addRangeAttributeToSearch($attributeCode, $attributeValue)
 {
     if (isset($attributeValue['from']) && '' !== $attributeValue['from']) {
         $this->filterBuilder->setField("{$attributeCode}.from")->setValue($attributeValue['from']);
         $this->searchCriteriaBuilder->addFilter($this->filterBuilder->create());
     }
     if (isset($attributeValue['to']) && '' !== $attributeValue['to']) {
         $this->filterBuilder->setField("{$attributeCode}.to")->setValue($attributeValue['to']);
         $this->searchCriteriaBuilder->addFilter($this->filterBuilder->create());
     }
 }
コード例 #3
0
 /**
  * Creates a filter DTO for given field/condition
  *
  * @param string $field Field for new filter
  * @param string|array $condition Condition for new filter.
  * @return Filter
  */
 protected function createFilterData($field, $condition)
 {
     $this->filterBuilder->setField($field);
     if (is_array($condition)) {
         $this->filterBuilder->setValue(reset($condition));
         $this->filterBuilder->setConditionType(key($condition));
     } else {
         // not an array, just use eq as condition type and given value
         $this->filterBuilder->setConditionType('eq');
         $this->filterBuilder->setValue($condition);
     }
     return $this->filterBuilder->create();
 }
コード例 #4
0
 /**
  * Apply selection by Excluded Included to Search Result
  *
  * @throws LocalizedException
  * @return void
  */
 public function applySelectionOnTargetProvider()
 {
     $selected = $this->request->getParam(static::SELECTED_PARAM);
     $excluded = $this->request->getParam(static::EXCLUDED_PARAM);
     if ('false' === $excluded) {
         return;
     }
     $component = $this->getComponent();
     $this->prepareComponent($component);
     $dataProvider = $component->getContext()->getDataProvider();
     try {
         if (is_array($excluded) && !empty($excluded)) {
             $this->filterBuilder->setConditionType('nin')->setField($dataProvider->getPrimaryFieldName())->setValue($excluded);
             $dataProvider->addFilter($this->filterBuilder->create());
         } elseif (is_array($selected) && !empty($selected)) {
             $this->filterBuilder->setConditionType('in')->setField($dataProvider->getPrimaryFieldName())->setValue($selected);
             $dataProvider->addFilter($this->filterBuilder->create());
         }
     } catch (\Exception $e) {
         throw new LocalizedException(__($e->getMessage()));
     }
 }
コード例 #5
0
ファイル: Collection.php プロジェクト: rafaelstz/magento2
 /**
  * @inheritdoc
  */
 protected function _renderFiltersBefore()
 {
     $this->getSearchCriteriaBuilder();
     $this->getFilterBuilder();
     $this->getSearch();
     if ($this->queryText) {
         $this->filterBuilder->setField('search_term');
         $this->filterBuilder->setValue($this->queryText);
         $this->searchCriteriaBuilder->addFilter($this->filterBuilder->create());
     }
     $priceRangeCalculation = $this->_scopeConfig->getValue(\Magento\Catalog\Model\Layer\Filter\Dynamic\AlgorithmFactory::XML_PATH_RANGE_CALCULATION, \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
     if ($priceRangeCalculation) {
         $this->filterBuilder->setField('price_dynamic_algorithm');
         $this->filterBuilder->setValue($priceRangeCalculation);
         $this->searchCriteriaBuilder->addFilter($this->filterBuilder->create());
     }
     $searchCriteria = $this->searchCriteriaBuilder->create();
     $searchCriteria->setRequestName($this->searchRequestName);
     try {
         $this->searchResult = $this->getSearch()->search($searchCriteria);
     } catch (EmptyRequestDataException $e) {
         /** @var \Magento\Framework\Api\Search\SearchResultInterface $searchResult */
         $this->searchResult = $this->searchResultFactory->create()->setItems([]);
     } catch (NonExistingRequestNameException $e) {
         $this->_logger->error($e->getMessage());
         throw new LocalizedException(__('Sorry, something went wrong. You can find out more in the error log.'));
     }
     $temporaryStorage = $this->temporaryStorageFactory->create();
     $table = $temporaryStorage->storeApiDocuments($this->searchResult->getItems());
     $this->getSelect()->joinInner(['search_result' => $table->getName()], 'e.entity_id = search_result.' . TemporaryStorage::FIELD_ENTITY_ID, []);
     $this->_totalRecords = $this->searchResult->getTotalCount();
     if ($this->order && 'relevance' === $this->order['field']) {
         $this->getSelect()->order('search_result.' . TemporaryStorage::FIELD_SCORE . ' ' . $this->order['dir']);
     }
     return parent::_renderFiltersBefore();
 }