コード例 #1
0
ファイル: Preprocessor.php プロジェクト: nja78/magento2
 /**
  * @param FilterInterface $filter
  * @param bool $isNegation
  * @param string $query
  * @param QueryContainer $queryContainer
  * @return string
  */
 private function processQueryWithField(FilterInterface $filter, $isNegation, $query, QueryContainer $queryContainer)
 {
     $currentStoreId = $this->scopeResolver->getScope()->getId();
     $attribute = $this->config->getAttribute(\Magento\Catalog\Model\Product::ENTITY, $filter->getField());
     $select = $this->getConnection()->select();
     $table = $attribute->getBackendTable();
     if ($filter->getField() == 'price') {
         $query = str_replace('price', 'min_price', $query);
         $select->from(['main_table' => $this->resource->getTableName('catalog_product_index_price')], 'entity_id')->where($query);
     } elseif ($filter->getField() == 'category_ids') {
         return 'category_index.category_id = ' . $filter->getValue();
     } else {
         if ($attribute->isStatic()) {
             $select->from(['main_table' => $table], 'entity_id')->where($query);
         } else {
             if ($filter->getType() == FilterInterface::TYPE_TERM) {
                 if (is_array($filter->getValue())) {
                     $value = sprintf('%s IN (%s)', $isNegation ? 'NOT' : '', implode(',', $filter->getValue()));
                 } else {
                     $value = ($isNegation ? '!' : '') . '= ' . $filter->getValue();
                 }
                 $filterQuery = sprintf('cpie.store_id = %d AND cpie.attribute_id = %d AND cpie.value %s', $this->scopeResolver->getScope()->getId(), $attribute->getId(), $value);
                 $queryContainer->addFilter($filterQuery);
                 return '';
             }
             $ifNullCondition = $this->getConnection()->getIfNullSql('current_store.value', 'main_table.value');
             $select->from(['main_table' => $table], 'entity_id')->joinLeft(['current_store' => $table], 'current_store.attribute_id = main_table.attribute_id AND current_store.store_id = ' . $currentStoreId, null)->columns([$filter->getField() => $ifNullCondition])->where('main_table.attribute_id = ?', $attribute->getAttributeId())->where('main_table.store_id = ?', \Magento\Store\Model\Store::DEFAULT_STORE_ID)->having($query);
         }
     }
     return 'search_index.entity_id IN (
         select entity_id from  ' . $this->conditionManager->wrapBrackets($select) . ' as filter
         )';
 }
コード例 #2
0
 /**
  * @param FilterInterface $filter
  * @param bool $isNegation
  * @param string $query
  * @return string
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 private function processQueryWithField(FilterInterface $filter, $isNegation, $query)
 {
     $currentStoreId = $this->scopeResolver->getScope()->getId();
     $attribute = $this->config->getAttribute(\Magento\Catalog\Model\Product::ENTITY, $filter->getField());
     $select = $this->getSelect();
     $table = $attribute->getBackendTable();
     if ($filter->getField() == 'price') {
         $query = str_replace('price', 'min_price', $query);
         $select->from(['main_table' => $this->resource->getTableName('catalog_product_index_price')], 'entity_id')->where($query);
     } elseif ($filter->getField() == 'category_ids') {
         return 'category_index.category_id = ' . $filter->getValue();
     } else {
         if ($attribute->isStatic()) {
             $select->from(['main_table' => $table], 'entity_id')->where($query);
         } else {
             if ($filter->getType() == FilterInterface::TYPE_TERM) {
                 $field = $filter->getField();
                 $mapper = function ($value) use($field, $isNegation) {
                     return ($isNegation ? '-' : '') . $this->attributePrefix . $field . '_' . $value;
                 };
                 if (is_array($filter->getValue())) {
                     $value = implode(' ', array_map($mapper, $filter->getValue()));
                 } else {
                     $value = $mapper($filter->getValue());
                 }
                 return 'MATCH (data_index) AGAINST (' . $this->getConnection()->quote($value) . ' IN BOOLEAN MODE)';
             }
             $ifNullCondition = $this->getConnection()->getIfNullSql('current_store.value', 'main_table.value');
             $select->from(['main_table' => $table], 'entity_id')->joinLeft(['current_store' => $table], 'current_store.attribute_id = main_table.attribute_id AND current_store.store_id = ' . $currentStoreId, null)->columns([$filter->getField() => $ifNullCondition])->where('main_table.attribute_id = ?', $attribute->getAttributeId())->where('main_table.store_id = ?', \Magento\Store\Model\Store::DEFAULT_STORE_ID)->having($query);
         }
     }
     return 'search_index.product_id IN (
         select entity_id from  ' . $this->conditionManager->wrapBrackets($select) . ' as filter
         )';
 }
コード例 #3
0
ファイル: Term.php プロジェクト: pavelnovitsky/magento2
 /**
  * {@inheritdoc}
  */
 public function buildFilter(\Magento\Framework\Search\Request\FilterInterface $filter)
 {
     $adapter = $this->resource->getConnection(Resource::DEFAULT_READ_RESOURCE);
     /** @var \Magento\Framework\Search\Request\Filter\Term $filter */
     $condition = sprintf('%s = %s', $filter->getField(), $adapter->quote($filter->getValue()));
     return $condition;
 }
コード例 #4
0
 protected function processFilter(RequestFilterInterface $filter, DataObject $params, $conditionType)
 {
     if ($filter->getType() == RequestFilterInterface::TYPE_TERM) {
         $filters = $params->hasFilters() ? $params->getFilters() : [];
         $filters[$filter->getField()] = $filter->getValue();
         $params->setFilters($filters);
     }
     /* ignore otherwise */
 }
コード例 #5
0
 /**
  * @param FilterInterface $filter
  * @param bool $isNegation
  * @param string $query
  * @return string
  */
 private function processQueryWithField(FilterInterface $filter, $isNegation, $query)
 {
     /** @var Attribute $attribute */
     $attribute = $this->config->getAttribute(Product::ENTITY, $filter->getField());
     if ($filter->getField() === 'price') {
         $resultQuery = str_replace($this->connection->quoteIdentifier('price'), $this->connection->quoteIdentifier('price_index.min_price'), $query);
     } elseif ($filter->getField() === 'category_ids') {
         return 'category_ids_index.category_id = ' . $filter->getValue();
     } elseif ($attribute->isStatic()) {
         $alias = $this->tableMapper->getMappingAlias($filter);
         $resultQuery = str_replace($this->connection->quoteIdentifier($attribute->getAttributeCode()), $this->connection->quoteIdentifier($alias . '.' . $attribute->getAttributeCode()), $query);
     } elseif ($filter->getType() === FilterInterface::TYPE_TERM && in_array($attribute->getFrontendInput(), ['select', 'multiselect'], true)) {
         $resultQuery = $this->processTermSelect($filter, $isNegation);
     } elseif ($filter->getType() === FilterInterface::TYPE_RANGE && in_array($attribute->getBackendType(), ['decimal', 'int'], true)) {
         $resultQuery = $this->processRangeNumeric($filter, $query, $attribute);
     } else {
         $table = $attribute->getBackendTable();
         $select = $this->connection->select();
         $ifNullCondition = $this->connection->getIfNullSql('current_store.value', 'main_table.value');
         $currentStoreId = $this->scopeResolver->getScope()->getId();
         $select->from(['main_table' => $table], 'entity_id')->joinLeft(['current_store' => $table], 'current_store.attribute_id = main_table.attribute_id AND current_store.store_id = ' . $currentStoreId, null)->columns([$filter->getField() => $ifNullCondition])->where('main_table.attribute_id = ?', $attribute->getAttributeId())->where('main_table.store_id = ?', Store::DEFAULT_STORE_ID)->having($query);
         $resultQuery = 'search_index.entity_id IN (
             select entity_id from  ' . $this->conditionManager->wrapBrackets($select) . ' as filter
         )';
     }
     return $resultQuery;
 }
コード例 #6
0
ファイル: Term.php プロジェクト: kidaa30/magento2-platformsh
 /**
  * {@inheritdoc}
  */
 public function buildFilter(RequestFilterInterface $filter, $isNegation)
 {
     /** @var \Magento\Framework\Search\Request\Filter\Term $filter */
     return $this->conditionManager->generateCondition($filter->getField(), $this->getConditionOperator($filter->getValue(), $isNegation), $filter->getValue());
 }
コード例 #7
0
 /**
  * {@inheritdoc}
  */
 public function buildFilter(\Magento\Framework\Search\Request\FilterInterface $filter, $isNegation)
 {
     /** @var \Magento\Framework\Search\Request\Filter\Wildcard $filter */
     $searchValue = '%' . $filter->getValue() . '%';
     return $this->conditionManager->generateCondition($filter->getField(), $isNegation ? self::CONDITION_NOT_LIKE : self::CONDITION_LIKE, $searchValue);
 }