Skip to content

Commit 83b100d

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

File tree

4 files changed

+37
-22
lines changed

4 files changed

+37
-22
lines changed

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,15 @@ public function getDataSet(
9292
if (!$store instanceof \Magento\Store\Model\Store) {
9393
throw new \RuntimeException('Illegal scope resolved');
9494
}
95+
96+
$currencyRate = $store->getCurrentCurrencyRate() ? : 1;
9597
$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+
];
96102
$select->from(['main_table' => $table], null)
97-
->columns([BucketInterface::FIELD_VALUE => 'main_table.min_price'])
103+
->columns($columns)
98104
->where('main_table.customer_group_id = ?', $this->customerSession->getCustomerGroupId())
99105
->where('main_table.website_id = ?', $store->getWebsiteId());
100106
} else {

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -132,14 +132,15 @@ public function getAggregation(
132132
\Magento\Framework\Search\Dynamic\EntityStorage $entityStorage
133133
) {
134134
$select = $this->dataProvider->getDataSet($bucket, $dimensions, $entityStorage->getSource());
135-
$column = $select->getPart(Select::COLUMNS)[0];
135+
list ($valueColumn, $currencyRateColumn) = $select->getPart(Select::COLUMNS);
136136
$select->reset(Select::COLUMNS);
137-
$rangeExpr = new \Zend_Db_Expr(
138-
$this->connection->getIfNullSql(
139-
$this->connection->quoteInto('FLOOR(' . $column[1] . ' / ? ) + 1', $range),
140-
1
141-
)
142-
);
137+
$rangeExpr = new \Zend_Db_Expr($this->connection->getIfNullSql(
138+
$this->connection->quoteInto(
139+
'FLOOR(' . $valueColumn[1] . ' * ' . (string) $currencyRateColumn[1] . ' / ? ) + 1',
140+
$range
141+
),
142+
1
143+
));
143144

144145
$select
145146
->columns(['range' => $rangeExpr])

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,8 +262,8 @@ private function prepareData($key, $count)
262262
$to = $this->getTo($to);
263263
}
264264
$label = $this->_renderRangeLabel(
265-
empty($from) ? 0 : $from * $this->getCurrencyRate(),
266-
empty($to) ? $to : $to * $this->getCurrencyRate()
265+
empty($from) ? 0 : $from,
266+
empty($to) ? $to : $to
267267
);
268268
$value = $from . '-' . $to . $this->dataProvider->getAdditionalRequestData();
269269

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

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

266-
$this->getSearchCriteriaBuilder();
267-
$this->getFilterBuilder();
268266
if (!is_array($condition) || !in_array(key($condition), ['from', 'to'])) {
269-
$this->filterBuilder->setField($field);
270-
$this->filterBuilder->setValue($condition);
271-
$this->searchCriteriaBuilder->addFilter($this->filterBuilder->create());
267+
$this->addFilterToSearchCriteria($field, $condition);
272268
} else {
269+
if ('price' === $field) {
270+
$coef = $this->_storeManager->getStore()->getCurrentCurrencyRate() ? : 1;
271+
}
272+
273273
if (!empty($condition['from'])) {
274-
$this->filterBuilder->setField("{$field}.from");
275-
$this->filterBuilder->setValue($condition['from']);
276-
$this->searchCriteriaBuilder->addFilter($this->filterBuilder->create());
274+
$this->addFilterToSearchCriteria("{$field}.from", $condition['from'] / $coef);
277275
}
278276
if (!empty($condition['to'])) {
279-
$this->filterBuilder->setField("{$field}.to");
280-
$this->filterBuilder->setValue($condition['to']);
281-
$this->searchCriteriaBuilder->addFilter($this->filterBuilder->create());
277+
$this->addFilterToSearchCriteria("{$field}.to", $condition['to'] / $coef);
282278
}
283279
}
284280
return $this;
285281
}
286282

283+
/**
284+
* @param string $field
285+
* @param mixed $value
286+
*/
287+
private function addFilterToSearchCriteria($field, $value)
288+
{
289+
$this->getFilterBuilder()->setField($field);
290+
$this->getFilterBuilder()->setValue($value);
291+
$this->getSearchCriteriaBuilder()->addFilter($this->filterBuilder->create());
292+
}
293+
287294
/**
288295
* Add search query filter
289296
*
@@ -349,7 +356,8 @@ protected function _renderFiltersBefore()
349356
if ($this->order && 'relevance' === $this->order['field']) {
350357
$this->getSelect()->order('search_result.'. TemporaryStorage::FIELD_SCORE . ' ' . $this->order['dir']);
351358
}
352-
return parent::_renderFiltersBefore();
359+
360+
parent::_renderFiltersBefore();
353361
}
354362

355363
/**

0 commit comments

Comments
 (0)