From 357320cac1e8654ef6c7326abb22aed38dbd9f05 Mon Sep 17 00:00:00 2001 From: Dmytro Horytskyi Date: Mon, 4 Dec 2017 16:29:02 +0200 Subject: [PATCH] MAGETWO-60246: [Backport] - [Github]Magento 2.1.1 Problem with change currency #6746 - for 2.1.x --- .../Mysql/Aggregation/DataProvider.php | 7 ++-- .../Adapter/Mysql/Dynamic/DataProvider.php | 18 +++++----- .../Model/Layer/Filter/Price.php | 10 +++--- .../ResourceModel/Fulltext/Collection.php | 35 +++++++------------ 4 files changed, 28 insertions(+), 42 deletions(-) diff --git a/app/code/Magento/CatalogSearch/Model/Adapter/Mysql/Aggregation/DataProvider.php b/app/code/Magento/CatalogSearch/Model/Adapter/Mysql/Aggregation/DataProvider.php index 4b3fb8264562d..f371901e143e1 100644 --- a/app/code/Magento/CatalogSearch/Model/Adapter/Mysql/Aggregation/DataProvider.php +++ b/app/code/Magento/CatalogSearch/Model/Adapter/Mysql/Aggregation/DataProvider.php @@ -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 { diff --git a/app/code/Magento/CatalogSearch/Model/Adapter/Mysql/Dynamic/DataProvider.php b/app/code/Magento/CatalogSearch/Model/Adapter/Mysql/Dynamic/DataProvider.php index 9d172fe7a2576..5ece8cab5f647 100644 --- a/app/code/Magento/CatalogSearch/Model/Adapter/Mysql/Dynamic/DataProvider.php +++ b/app/code/Magento/CatalogSearch/Model/Adapter/Mysql/Dynamic/DataProvider.php @@ -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]) diff --git a/app/code/Magento/CatalogSearch/Model/Layer/Filter/Price.php b/app/code/Magento/CatalogSearch/Model/Layer/Filter/Price.php index ccc94e5a9e5ee..81a409dd269a4 100644 --- a/app/code/Magento/CatalogSearch/Model/Layer/Filter/Price.php +++ b/app/code/Magento/CatalogSearch/Model/Layer/Filter/Price.php @@ -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) diff --git a/app/code/Magento/CatalogSearch/Model/ResourceModel/Fulltext/Collection.php b/app/code/Magento/CatalogSearch/Model/ResourceModel/Fulltext/Collection.php index 1b38ed78fb640..1f7d94b9c5f39 100644 --- a/app/code/Magento/CatalogSearch/Model/ResourceModel/Fulltext/Collection.php +++ b/app/code/Magento/CatalogSearch/Model/ResourceModel/Fulltext/Collection.php @@ -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 * @@ -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(); } /**