Example #1
0
 /**
  * @inheritdoc
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 protected function _renderFiltersBefore()
 {
     if ($this->filters) {
         $this->requestBuilder->bindDimension('scope', $this->getStoreId());
         $this->requestBuilder->setRequestName('advanced_search_container');
         foreach ($this->filters as $attributes) {
             foreach ($attributes as $attributeCode => $attributeValue) {
                 if (is_numeric($attributeCode)) {
                     $attributeCode = $this->_eavConfig->getAttribute(Product::ENTITY, $attributeCode)->getAttributeCode();
                 }
                 if (isset($attributeValue['from']) || isset($attributeValue['to'])) {
                     if (isset($attributeValue['from']) && '' !== $attributeValue['from']) {
                         $this->requestBuilder->bind("{$attributeCode}.from", $attributeValue['from']);
                     }
                     if (isset($attributeValue['to']) && '' !== $attributeValue['to']) {
                         $this->requestBuilder->bind("{$attributeCode}.to", $attributeValue['to']);
                     }
                 } elseif (!is_array($attributeValue)) {
                     $this->requestBuilder->bind($attributeCode, $attributeValue);
                 } elseif (isset($attributeValue['like'])) {
                     $this->requestBuilder->bind($attributeCode, trim($attributeValue['like'], '%'));
                 } elseif (isset($attributeValue['in'])) {
                     $this->requestBuilder->bind($attributeCode, $attributeValue['in']);
                 } elseif (isset($attributeValue['in_set'])) {
                     $this->requestBuilder->bind($attributeCode, $attributeValue['in_set']);
                 }
             }
         }
         $queryRequest = $this->requestBuilder->create();
         $queryResponse = $this->searchEngine->search($queryRequest);
         $ids = [0];
         /** @var \Magento\Framework\Search\Document $document */
         foreach ($queryResponse as $document) {
             $ids[] = $document->getId();
         }
         $this->addIdFilter($ids);
     }
     return parent::_renderFiltersBefore();
 }
Example #2
0
 /**
  * @inheritdoc
  */
 protected function _renderFiltersBefore()
 {
     $this->requestBuilder->bindDimension('scope', $this->getStoreId());
     if ($this->queryText) {
         $this->requestBuilder->bind('search_term', $this->queryText);
     }
     $priceRangeCalculation = $this->_scopeConfig->getValue(\Magento\Catalog\Model\Layer\Filter\Dynamic\AlgorithmFactory::XML_PATH_RANGE_CALCULATION, \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
     if ($priceRangeCalculation) {
         $this->requestBuilder->bind('price_dynamic_algorithm', $priceRangeCalculation);
     }
     $this->requestBuilder->setRequestName('quick_search_container');
     $queryRequest = $this->requestBuilder->create();
     $this->queryResponse = $this->searchEngine->search($queryRequest);
     $ids = [0];
     /** @var \Magento\Framework\Search\Document $document */
     foreach ($this->queryResponse as $document) {
         $ids[] = $document->getId();
     }
     parent::addFieldToFilter('entity_id', ['in' => $ids]);
     $this->_totalRecords = count($ids) - 1;
     if ($this->order && $this->order['field'] == 'relevance') {
         $this->getSelect()->order(new \Zend_Db_Expr($this->_conn->quoteInto('FIELD(e.entity_id, ?) ' . $this->order['dir'], $ids)));
     }
     return parent::_renderFiltersBefore();
 }
Example #3
0
 /**
  * @inheritdoc
  */
 protected function _renderFiltersBefore()
 {
     if ($this->filters) {
         $this->requestBuilder->bindDimension('scope', $this->getStoreId());
         $this->requestBuilder->setRequestName('advanced_search_container');
         foreach ($this->filters as $attributes) {
             foreach ($attributes as $attributeCode => $attributeValue) {
                 $attributeCode = $this->getAttributeCode($attributeCode);
                 $this->requestBuilder->bindRequestValue($attributeCode, $attributeValue);
             }
         }
         $queryRequest = $this->requestBuilder->create();
         $queryResponse = $this->searchEngine->search($queryRequest);
         $ids = $this->getResponseIds($queryResponse);
         $this->addIdFilter($ids);
     }
     return parent::_renderFiltersBefore();
 }