Skip to content

Commit 357320c

Browse files
committed
MAGETWO-60246: [Backport] - [Github]Magento 2.1.1 Problem with change currency #6746 - for 2.1.x
1 parent 1f5e3f6 commit 357320c

File tree

4 files changed

+28
-42
lines changed

4 files changed

+28
-42
lines changed

app/code/Magento/CatalogSearch/Model/Adapter/Mysql/Aggregation/DataProvider.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,10 @@ public function getDataSet(
9494
}
9595

9696
$currencyRate = $store->getCurrentCurrencyRate() ? : 1;
97+
$valueExpr = new \Zend_Db_Expr('main_table.min_price * ' . $currencyRate);
9798
$table = $this->resource->getTableName('catalog_product_index_price');
98-
$columns = [
99-
BucketInterface::FIELD_VALUE => 'main_table.min_price',
100-
'currency_rate' => new \Zend_Db_Expr($currencyRate),
101-
];
10299
$select->from(['main_table' => $table], null)
103-
->columns($columns)
100+
->columns([BucketInterface::FIELD_VALUE => $valueExpr])
104101
->where('main_table.customer_group_id = ?', $this->customerSession->getCustomerGroupId())
105102
->where('main_table.website_id = ?', $store->getWebsiteId());
106103
} else {

app/code/Magento/CatalogSearch/Model/Adapter/Mysql/Dynamic/DataProvider.php

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -132,17 +132,15 @@ public function getAggregation(
132132
\Magento\Framework\Search\Dynamic\EntityStorage $entityStorage
133133
) {
134134
$select = $this->dataProvider->getDataSet($bucket, $dimensions, $entityStorage->getSource());
135-
$columns = $select->getPart(Select::COLUMNS);
136-
$valueColumn = $columns[0][1];
137-
$coefColumn = (isset($columns[1]) ? (string) $columns[1][1] : null);
135+
$columns = array_column($select->getPart(Select::COLUMNS), 1, 2);
136+
$valueColumn = (string) $columns['value'];
138137
$select->reset(Select::COLUMNS);
139-
$rangeExpr = new \Zend_Db_Expr($this->connection->getIfNullSql(
140-
$this->connection->quoteInto(
141-
'FLOOR(' . $valueColumn . ($coefColumn ? ' * ' . $coefColumn : '') . ' / ? ) + 1',
142-
$range
143-
),
144-
1
145-
));
138+
$rangeExpr = new \Zend_Db_Expr(
139+
$this->connection->getIfNullSql(
140+
$this->connection->quoteInto('FLOOR(' . $valueColumn . ' / ? ) + 1', $range),
141+
1
142+
)
143+
);
146144

147145
$select
148146
->columns(['range' => $rangeExpr])

app/code/Magento/CatalogSearch/Model/Layer/Filter/Price.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,12 @@ public function apply(\Magento\Framework\App\RequestInterface $request)
135135

136136
list($from, $to) = $filter;
137137

138-
$this->getLayer()->getProductCollection()->addFieldToFilter(
139-
'price',
140-
['from' => $from, 'to' => empty($to) || $from == $to ? $to : $to - self::PRICE_DELTA]
141-
);
138+
$currencyRate = $this->getCurrencyRate();
139+
$condition = [
140+
'from' => $from / $currencyRate,
141+
'to' => (empty($to) || $from == $to ? $to : $to - self::PRICE_DELTA) / $currencyRate
142+
];
143+
$this->getLayer()->getProductCollection()->addFieldToFilter('price', $condition);
142144

143145
$this->getLayer()->getState()->addFilter(
144146
$this->_createItem($this->_renderRangeLabel(empty($from) ? 0 : $from, $to), $filter)

app/code/Magento/CatalogSearch/Model/ResourceModel/Fulltext/Collection.php

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -263,37 +263,27 @@ public function addFieldToFilter($field, $condition = null)
263263
throw new \RuntimeException('Illegal state');
264264
}
265265

266+
$this->getSearchCriteriaBuilder();
267+
$this->getFilterBuilder();
266268
if (!is_array($condition) || !in_array(key($condition), ['from', 'to'])) {
267-
$this->addFilterToSearchCriteria($field, $condition);
269+
$this->filterBuilder->setField($field);
270+
$this->filterBuilder->setValue($condition);
271+
$this->searchCriteriaBuilder->addFilter($this->filterBuilder->create());
268272
} else {
269-
if ('price' === $field) {
270-
$coef = $this->_storeManager->getStore()->getCurrentCurrencyRate() ? : 1;
271-
}
272-
273273
if (!empty($condition['from'])) {
274-
$this->addFilterToSearchCriteria("{$field}.from", $condition['from'] / $coef);
274+
$this->filterBuilder->setField("{$field}.from");
275+
$this->filterBuilder->setValue($condition['from']);
276+
$this->searchCriteriaBuilder->addFilter($this->filterBuilder->create());
275277
}
276278
if (!empty($condition['to'])) {
277-
$this->addFilterToSearchCriteria("{$field}.to", $condition['to'] / $coef);
279+
$this->filterBuilder->setField("{$field}.to");
280+
$this->filterBuilder->setValue($condition['to']);
281+
$this->searchCriteriaBuilder->addFilter($this->filterBuilder->create());
278282
}
279283
}
280284
return $this;
281285
}
282286

283-
/**
284-
* Create and add new filter to search criteria
285-
*
286-
* @param string $field
287-
* @param mixed $value
288-
* @return void
289-
*/
290-
private function addFilterToSearchCriteria($field, $value)
291-
{
292-
$this->getFilterBuilder()->setField($field);
293-
$this->getFilterBuilder()->setValue($value);
294-
$this->getSearchCriteriaBuilder()->addFilter($this->filterBuilder->create());
295-
}
296-
297287
/**
298288
* Add search query filter
299289
*
@@ -359,8 +349,7 @@ protected function _renderFiltersBefore()
359349
if ($this->order && 'relevance' === $this->order['field']) {
360350
$this->getSelect()->order('search_result.'. TemporaryStorage::FIELD_SCORE . ' ' . $this->order['dir']);
361351
}
362-
363-
parent::_renderFiltersBefore();
352+
return parent::_renderFiltersBefore();
364353
}
365354

366355
/**

0 commit comments

Comments
 (0)