Skip to content

Commit c5e4f55

Browse files
committed
MAGETWO-44118: Doesn't found bundle product
- Fixed static tests
1 parent a153705 commit c5e4f55

File tree

1 file changed

+58
-32
lines changed

1 file changed

+58
-32
lines changed

app/code/Magento/CatalogSearch/Model/Adapter/Mysql/Filter/Preprocessor.php

Lines changed: 58 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
namespace Magento\CatalogSearch\Model\Adapter\Mysql\Filter;
77

88
use Magento\Catalog\Model\Product;
9+
use Magento\Catalog\Model\ResourceModel\Eav\Attribute;
910
use Magento\CatalogSearch\Model\Search\TableMapper;
1011
use Magento\Eav\Model\Config;
1112
use Magento\Framework\App\ResourceConnection;
@@ -97,7 +98,7 @@ public function process(FilterInterface $filter, $isNegation, $query)
9798
*/
9899
private function processQueryWithField(FilterInterface $filter, $isNegation, $query)
99100
{
100-
/** @var \Magento\Catalog\Model\ResourceModel\Eav\Attribute $attribute */
101+
/** @var Attribute $attribute */
101102
$attribute = $this->config->getAttribute(Product::ENTITY, $filter->getField());
102103
if ($filter->getField() === 'price') {
103104
$resultQuery = str_replace(
@@ -118,40 +119,12 @@ private function processQueryWithField(FilterInterface $filter, $isNegation, $qu
118119
$filter->getType() === FilterInterface::TYPE_TERM &&
119120
in_array($attribute->getFrontendInput(), ['select', 'multiselect'], true)
120121
) {
121-
$alias = $this->tableMapper->getMappingAlias($filter);
122-
if (is_array($filter->getValue())) {
123-
$value = sprintf(
124-
'%s IN (%s)',
125-
($isNegation ? 'NOT' : ''),
126-
implode(',', $filter->getValue())
127-
);
128-
} else {
129-
$value = ($isNegation ? '!' : '') . '= ' . $filter->getValue();
130-
}
131-
$resultQuery = sprintf(
132-
'%1$s.value %2$s',
133-
$alias,
134-
$value
135-
);
136-
} elseif(
122+
$resultQuery = $this->processTermSelect($filter, $isNegation);
123+
} elseif (
137124
$filter->getType() === FilterInterface::TYPE_RANGE &&
138125
in_array($attribute->getBackendType(), ['decimal', 'int'], true)
139126
) {
140-
$tableSuffix = $attribute->getBackendType() === 'decimal' ? '_decimal' : '';
141-
$table = $this->resource->getTableName("catalog_product_index_eav{$tableSuffix}");
142-
$select = $this->connection->select();
143-
144-
$currentStoreId = $this->scopeResolver->getScope()->getId();
145-
146-
$select->from(['main_table' => $table], 'entity_id')
147-
->columns([$filter->getField() => 'main_table.value'])
148-
->where('main_table.attribute_id = ?', $attribute->getAttributeId())
149-
->where('main_table.store_id = ?', $currentStoreId)
150-
->having($query);
151-
152-
$resultQuery = 'search_index.entity_id IN (
153-
select entity_id from ' . $this->conditionManager->wrapBrackets($select) . ' as filter
154-
)';
127+
$resultQuery = $this->processRangeNumeric($filter, $query, $attribute);
155128
} else {
156129
$table = $attribute->getBackendTable();
157130
$select = $this->connection->select();
@@ -181,4 +154,57 @@ private function processQueryWithField(FilterInterface $filter, $isNegation, $qu
181154

182155
return $resultQuery;
183156
}
157+
158+
/**
159+
* @param FilterInterface $filter
160+
* @param string $query
161+
* @param Attribute $attribute
162+
* @return string
163+
*/
164+
private function processRangeNumeric(FilterInterface $filter, $query, $attribute)
165+
{
166+
$tableSuffix = $attribute->getBackendType() === 'decimal' ? '_decimal' : '';
167+
$table = $this->resource->getTableName("catalog_product_index_eav{$tableSuffix}");
168+
$select = $this->connection->select();
169+
170+
$currentStoreId = $this->scopeResolver->getScope()->getId();
171+
172+
$select->from(['main_table' => $table], 'entity_id')
173+
->columns([$filter->getField() => 'main_table.value'])
174+
->where('main_table.attribute_id = ?', $attribute->getAttributeId())
175+
->where('main_table.store_id = ?', $currentStoreId)
176+
->having($query);
177+
178+
$resultQuery = 'search_index.entity_id IN (
179+
select entity_id from ' . $this->conditionManager->wrapBrackets($select) . ' as filter
180+
)';
181+
182+
return $resultQuery;
183+
}
184+
185+
/**
186+
* @param FilterInterface $filter
187+
* @param bool $isNegation
188+
* @return string
189+
*/
190+
private function processTermSelect(FilterInterface $filter, $isNegation)
191+
{
192+
$alias = $this->tableMapper->getMappingAlias($filter);
193+
if (is_array($filter->getValue())) {
194+
$value = sprintf(
195+
'%s IN (%s)',
196+
($isNegation ? 'NOT' : ''),
197+
implode(',', $filter->getValue())
198+
);
199+
} else {
200+
$value = ($isNegation ? '!' : '') . '= ' . $filter->getValue();
201+
}
202+
$resultQuery = sprintf(
203+
'%1$s.value %2$s',
204+
$alias,
205+
$value
206+
);
207+
208+
return $resultQuery;
209+
}
184210
}

0 commit comments

Comments
 (0)