Skip to content

Commit

Permalink
MAGETWO-60246: [Backport] - [Github]Magento 2.1.1 Problem with change…
Browse files Browse the repository at this point in the history
… currency #6746 - for 2.1.x
  • Loading branch information
dhorytskyi committed Dec 4, 2017
1 parent 1f5e3f6 commit 357320c
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,10 @@ public function getDataSet(
}

$currencyRate = $store->getCurrentCurrencyRate() ? : 1;
$valueExpr = new \Zend_Db_Expr('main_table.min_price * ' . $currencyRate);
$table = $this->resource->getTableName('catalog_product_index_price');
$columns = [
BucketInterface::FIELD_VALUE => 'main_table.min_price',
'currency_rate' => new \Zend_Db_Expr($currencyRate),
];
$select->from(['main_table' => $table], null)
->columns($columns)
->columns([BucketInterface::FIELD_VALUE => $valueExpr])
->where('main_table.customer_group_id = ?', $this->customerSession->getCustomerGroupId())
->where('main_table.website_id = ?', $store->getWebsiteId());
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,17 +132,15 @@ public function getAggregation(
\Magento\Framework\Search\Dynamic\EntityStorage $entityStorage
) {
$select = $this->dataProvider->getDataSet($bucket, $dimensions, $entityStorage->getSource());
$columns = $select->getPart(Select::COLUMNS);
$valueColumn = $columns[0][1];
$coefColumn = (isset($columns[1]) ? (string) $columns[1][1] : null);
$columns = array_column($select->getPart(Select::COLUMNS), 1, 2);
$valueColumn = (string) $columns['value'];
$select->reset(Select::COLUMNS);
$rangeExpr = new \Zend_Db_Expr($this->connection->getIfNullSql(
$this->connection->quoteInto(
'FLOOR(' . $valueColumn . ($coefColumn ? ' * ' . $coefColumn : '') . ' / ? ) + 1',
$range
),
1
));
$rangeExpr = new \Zend_Db_Expr(
$this->connection->getIfNullSql(
$this->connection->quoteInto('FLOOR(' . $valueColumn . ' / ? ) + 1', $range),
1
)
);

$select
->columns(['range' => $rangeExpr])
Expand Down
10 changes: 6 additions & 4 deletions app/code/Magento/CatalogSearch/Model/Layer/Filter/Price.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,12 @@ public function apply(\Magento\Framework\App\RequestInterface $request)

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

$this->getLayer()->getProductCollection()->addFieldToFilter(
'price',
['from' => $from, 'to' => empty($to) || $from == $to ? $to : $to - self::PRICE_DELTA]
);
$currencyRate = $this->getCurrencyRate();
$condition = [
'from' => $from / $currencyRate,
'to' => (empty($to) || $from == $to ? $to : $to - self::PRICE_DELTA) / $currencyRate
];
$this->getLayer()->getProductCollection()->addFieldToFilter('price', $condition);

$this->getLayer()->getState()->addFilter(
$this->_createItem($this->_renderRangeLabel(empty($from) ? 0 : $from, $to), $filter)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,37 +263,27 @@ public function addFieldToFilter($field, $condition = null)
throw new \RuntimeException('Illegal state');
}

$this->getSearchCriteriaBuilder();
$this->getFilterBuilder();
if (!is_array($condition) || !in_array(key($condition), ['from', 'to'])) {
$this->addFilterToSearchCriteria($field, $condition);
$this->filterBuilder->setField($field);
$this->filterBuilder->setValue($condition);
$this->searchCriteriaBuilder->addFilter($this->filterBuilder->create());
} else {
if ('price' === $field) {
$coef = $this->_storeManager->getStore()->getCurrentCurrencyRate() ? : 1;
}

if (!empty($condition['from'])) {
$this->addFilterToSearchCriteria("{$field}.from", $condition['from'] / $coef);
$this->filterBuilder->setField("{$field}.from");
$this->filterBuilder->setValue($condition['from']);
$this->searchCriteriaBuilder->addFilter($this->filterBuilder->create());
}
if (!empty($condition['to'])) {
$this->addFilterToSearchCriteria("{$field}.to", $condition['to'] / $coef);
$this->filterBuilder->setField("{$field}.to");
$this->filterBuilder->setValue($condition['to']);
$this->searchCriteriaBuilder->addFilter($this->filterBuilder->create());
}
}
return $this;
}

/**
* Create and add new filter to search criteria
*
* @param string $field
* @param mixed $value
* @return void
*/
private function addFilterToSearchCriteria($field, $value)
{
$this->getFilterBuilder()->setField($field);
$this->getFilterBuilder()->setValue($value);
$this->getSearchCriteriaBuilder()->addFilter($this->filterBuilder->create());
}

/**
* Add search query filter
*
Expand Down Expand Up @@ -359,8 +349,7 @@ protected function _renderFiltersBefore()
if ($this->order && 'relevance' === $this->order['field']) {
$this->getSelect()->order('search_result.'. TemporaryStorage::FIELD_SCORE . ' ' . $this->order['dir']);
}

parent::_renderFiltersBefore();
return parent::_renderFiltersBefore();
}

/**
Expand Down

0 comments on commit 357320c

Please sign in to comment.