Skip to content

Commit 9a8e1ee

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

File tree

5 files changed

+58
-63
lines changed

5 files changed

+58
-63
lines changed

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,9 @@ 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;
97-
$valueExpr = new \Zend_Db_Expr('main_table.min_price * ' . $currencyRate);
9895
$table = $this->resource->getTableName('catalog_product_index_price');
99-
$select->from(['main_table' => $table], [BucketInterface::FIELD_VALUE => $valueExpr])
96+
$select->from(['main_table' => $table], null)
97+
->columns([BucketInterface::FIELD_VALUE => 'main_table.min_price'])
10098
->where('main_table.customer_group_id = ?', $this->customerSession->getCustomerGroupId())
10199
->where('main_table.website_id = ?', $store->getWebsiteId());
102100
} else {
@@ -117,7 +115,7 @@ public function getDataSet(
117115
->where('stock_index.stock_status = ?', Stock::STOCK_IN_STOCK)
118116
->group(['main_table.entity_id', 'main_table.value']);
119117
$parentSelect = $this->getSelect();
120-
$parentSelect->from(['main_table' => $subSelect], [BucketInterface::FIELD_VALUE => 'main_table.value']);
118+
$parentSelect->from(['main_table' => $subSelect], ['main_table.value']);
121119
$select = $parentSelect;
122120
}
123121

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,12 +132,11 @@ public function getAggregation(
132132
\Magento\Framework\Search\Dynamic\EntityStorage $entityStorage
133133
) {
134134
$select = $this->dataProvider->getDataSet($bucket, $dimensions, $entityStorage->getSource());
135-
$columns = array_column($select->getPart(Select::COLUMNS), 1, 2);
136-
$valueColumn = (string) $columns[BucketInterface::FIELD_VALUE];
135+
$column = $select->getPart(Select::COLUMNS)[0];
137136
$select->reset(Select::COLUMNS);
138137
$rangeExpr = new \Zend_Db_Expr(
139138
$this->connection->getIfNullSql(
140-
$this->connection->quoteInto('FLOOR(' . $valueColumn . ' / ? ) + 1', $range),
139+
$this->connection->quoteInto('FLOOR(' . $column[1] . ' / ? ) + 1', $range),
141140
1
142141
)
143142
);

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

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

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

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);
138+
$this->getLayer()->getProductCollection()->addFieldToFilter(
139+
'price',
140+
['from' => $from, 'to' => empty($to) || $from == $to ? $to : $to - self::PRICE_DELTA]
141+
);
144142

145143
$this->getLayer()->getState()->addFilter(
146144
$this->_createItem($this->_renderRangeLabel(empty($from) ? 0 : $from, $to), $filter)
@@ -158,7 +156,8 @@ public function getCurrencyRate()
158156
{
159157
$rate = $this->_getData('currency_rate');
160158
if ($rate === null) {
161-
$rate = $this->_storeManager->getStore()->getCurrentCurrencyRate();
159+
$rate = $this->_storeManager->getStore($this->getStoreId())
160+
->getCurrentCurrencyRate();
162161
}
163162
if (!$rate) {
164163
$rate = 1;
@@ -176,6 +175,11 @@ public function getCurrencyRate()
176175
*/
177176
protected function _renderRangeLabel($fromPrice, $toPrice)
178177
{
178+
$fromPrice *= $this->getCurrencyRate();
179+
if ($toPrice) {
180+
$toPrice *= $this->getCurrencyRate();
181+
}
182+
179183
$formattedFromPrice = $this->priceCurrency->format($fromPrice);
180184
if ($toPrice === '') {
181185
return __('%1 and above', $formattedFromPrice);

app/code/Magento/CatalogSearch/Test/Unit/Model/Layer/Filter/PriceTest.php

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,16 @@
1111

1212
/**
1313
* Test for \Magento\CatalogSearch\Model\Layer\Filter\Price
14+
* @SuppressWarnings(PHPMD.UnusedPrivateField)
1415
*/
1516
class PriceTest extends \PHPUnit_Framework_TestCase
1617
{
18+
private $itemDataBuilder;
19+
1720
/**
18-
* @var \Magento\Catalog\Model\Layer\Filter\Item\DataBuilder|MockObject
21+
* @var \Magento\Catalog\Model\Price|MockObject
1922
*/
20-
private $itemDataBuilder;
23+
private $price;
2124

2225
/**
2326
* @var \Magento\CatalogSearch\Model\ResourceModel\Fulltext\Collection|MockObject
@@ -51,49 +54,63 @@ class PriceTest extends \PHPUnit_Framework_TestCase
5154
protected function setUp()
5255
{
5356
$this->request = $this->getMockBuilder('\Magento\Framework\App\RequestInterface')
57+
->disableOriginalConstructor()
58+
->setMethods(['getParam'])
5459
->getMockForAbstractClass();
5560

5661
$dataProviderFactory = $this->getMockBuilder('\Magento\Catalog\Model\Layer\Filter\DataProvider\PriceFactory')
5762
->disableOriginalConstructor()
5863
->setMethods(['create'])
5964
->getMock();
65+
6066
$this->dataProvider = $this->getMockBuilder('\Magento\Catalog\Model\Layer\Filter\DataProvider\Price')
6167
->disableOriginalConstructor()
6268
->setMethods(['setPriceId', 'getPrice'])
6369
->getMock();
70+
6471
$dataProviderFactory->expects($this->once())
6572
->method('create')
6673
->will($this->returnValue($this->dataProvider));
6774

6875
$this->layer = $this->getMockBuilder('\Magento\Catalog\Model\Layer')
6976
->disableOriginalConstructor()
77+
->setMethods(['getState', 'getProductCollection'])
7078
->getMock();
7179

7280
$this->state = $this->getMockBuilder('\Magento\Catalog\Model\Layer\State')
7381
->disableOriginalConstructor()
82+
->setMethods(['addFilter'])
7483
->getMock();
7584
$this->layer->expects($this->any())
7685
->method('getState')
7786
->will($this->returnValue($this->state));
7887

79-
$this->fulltextCollection = $this->getMockBuilder(
88+
$this->fulltextCollection = $this->fulltextCollection = $this->getMockBuilder(
8089
'\Magento\CatalogSearch\Model\ResourceModel\Fulltext\Collection'
81-
)->disableOriginalConstructor()
90+
)
91+
->disableOriginalConstructor()
92+
->setMethods(['addFieldToFilter', 'getFacetedData'])
8293
->getMock();
94+
8395
$this->layer->expects($this->any())
8496
->method('getProductCollection')
8597
->will($this->returnValue($this->fulltextCollection));
8698

8799
$this->itemDataBuilder = $this->getMockBuilder('\Magento\Catalog\Model\Layer\Filter\Item\DataBuilder')
88100
->disableOriginalConstructor()
101+
->setMethods(['addItemData', 'build'])
89102
->getMock();
90103

91-
$this->filterItemFactory = $this->getMockBuilder('\Magento\Catalog\Model\Layer\Filter\ItemFactory')
104+
$this->filterItemFactory = $this->getMockBuilder(
105+
'\Magento\Catalog\Model\Layer\Filter\ItemFactory'
106+
)
92107
->disableOriginalConstructor()
93108
->setMethods(['create'])
94109
->getMock();
95110

96-
$filterItem = $this->getMockBuilder('\Magento\Catalog\Model\Layer\Filter\Item')
111+
$filterItem = $this->getMockBuilder(
112+
'\Magento\Catalog\Model\Layer\Filter\Item'
113+
)
97114
->disableOriginalConstructor()
98115
->setMethods(['setFilter', 'setLabel', 'setValue', 'setCount'])
99116
->getMock();
@@ -106,23 +123,12 @@ protected function setUp()
106123

107124
$escaper = $this->getMockBuilder('\Magento\Framework\Escaper')
108125
->disableOriginalConstructor()
126+
->setMethods(['escapeHtml'])
109127
->getMock();
110128
$escaper->expects($this->any())
111129
->method('escapeHtml')
112130
->will($this->returnArgument(0));
113131

114-
$storeMock = $this->getMockBuilder(\Magento\Store\Api\Data\StoreInterface::class)
115-
->setMethods(['getCurrentCurrencyRate'])
116-
->getMockForAbstractClass();
117-
$storeMock->expects($this->any())
118-
->method('getCurrentCurrencyRate')
119-
->willReturn(1);
120-
$storeManagerMock = $this->getMockBuilder(\Magento\Store\Model\StoreManagerInterface::class)
121-
->getMockForAbstractClass();
122-
$storeManagerMock->expects($this->any())
123-
->method('getStore')
124-
->willReturn($storeMock);
125-
126132
$this->attribute = $this->getMockBuilder('\Magento\Eav\Model\Entity\Attribute')
127133
->disableOriginalConstructor()
128134
->setMethods(['getAttributeCode', 'getFrontend', 'getIsFilterable'])
@@ -136,14 +142,14 @@ protected function setUp()
136142
'itemDataBuilder' => $this->itemDataBuilder,
137143
'filterItemFactory' => $this->filterItemFactory,
138144
'escaper' => $escaper,
139-
'storeManager' => $storeManagerMock,
140145
]
141146
);
142147
}
143148

144149
/**
145150
* @param $requestValue
146151
* @param $idValue
152+
* @param $isIdUsed
147153
* @dataProvider applyWithEmptyRequestDataProvider
148154
*/
149155
public function testApplyWithEmptyRequest($requestValue, $idValue)

lib/internal/Magento/Framework/Search/Adapter/Mysql/Aggregation/Interval.php

Lines changed: 17 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ class Interval implements IntervalInterface
1414
* Minimal possible value
1515
*/
1616
const DELTA = 0.005;
17-
1817
/**
1918
* @var Select
2019
*/
@@ -37,36 +36,24 @@ private function getValueFiled()
3736
{
3837
$field = $this->select->getPart(Select::COLUMNS)[0];
3938

40-
return (string) $field[1];
41-
}
42-
43-
/**
44-
* Get value alias
45-
*
46-
* @return string
47-
*/
48-
private function getValueAlias()
49-
{
50-
$field = $this->select->getPart(Select::COLUMNS)[0];
51-
52-
return $field[2];
39+
return $field[1];
5340
}
5441

5542
/**
5643
* {@inheritdoc}
44+
* @SuppressWarnings(PHPMD.UnusedLocalVariable)
5745
*/
5846
public function load($limit, $offset = null, $lower = null, $upper = null)
5947
{
6048
$select = clone $this->select;
61-
$valueFiled = $this->getValueFiled();
62-
$valueAlias = $this->getValueAlias();
49+
$value = $this->getValueFiled();
6350
if ($lower !== null) {
64-
$select->where($valueFiled . ' >= ?', $lower - self::DELTA);
51+
$select->where("${value} >= ?", $lower - self::DELTA);
6552
}
6653
if ($upper !== null) {
67-
$select->where($valueFiled . ' < ?', $upper - self::DELTA);
54+
$select->where("${value} < ?", $upper - self::DELTA);
6855
}
69-
$select->order($valueAlias . ' ASC')
56+
$select->order("value ASC")
7057
->limit($limit, $offset);
7158

7259
return $this->arrayValuesToFloat(
@@ -77,15 +64,16 @@ public function load($limit, $offset = null, $lower = null, $upper = null)
7764

7865
/**
7966
* {@inheritdoc}
67+
* @SuppressWarnings(PHPMD.UnusedLocalVariable)
8068
*/
8169
public function loadPrevious($data, $index, $lower = null)
8270
{
8371
$select = clone $this->select;
84-
$valueFiled = $this->getValueFiled();
72+
$value = $this->getValueFiled();
8573
$select->columns(['count' => 'COUNT(*)'])
86-
->where($valueFiled . ' < ?', $data - self::DELTA);
74+
->where("${value} < ?", $data - self::DELTA);
8775
if ($lower !== null) {
88-
$select->where($valueFiled . ' >= ?', $lower - self::DELTA);
76+
$select->where("${value} >= ?", $lower - self::DELTA);
8977
}
9078
$offset = $this->select->getConnection()
9179
->fetchRow($select)['count'];
@@ -98,17 +86,17 @@ public function loadPrevious($data, $index, $lower = null)
9886

9987
/**
10088
* {@inheritdoc}
89+
* @SuppressWarnings(PHPMD.UnusedLocalVariable)
10190
*/
10291
public function loadNext($data, $rightIndex, $upper = null)
10392
{
10493
$select = clone $this->select;
105-
$valueFiled = $this->getValueFiled();
106-
$valueAlias = $this->getValueAlias();
94+
$value = $this->getValueFiled();
10795
$select->columns(['count' => 'COUNT(*)'])
108-
->where($valueFiled . ' > ?', $data + self::DELTA);
96+
->where("${value} > ?", $data + self::DELTA);
10997

11098
if ($upper !== null) {
111-
$select->where($valueFiled . ' < ?', $data - self::DELTA);
99+
$select->where("${value} < ? ", $data - self::DELTA);
112100
}
113101

114102
$offset = $this->select->getConnection()
@@ -119,11 +107,11 @@ public function loadNext($data, $rightIndex, $upper = null)
119107
}
120108

121109
$select = clone $this->select;
122-
$select->where($valueFiled . ' >= ?', $data - self::DELTA);
110+
$select->where("${value} >= ?", $data - self::DELTA);
123111
if ($upper !== null) {
124-
$select->where($valueFiled . ' < ?', $data - self::DELTA);
112+
$select->where("${value} < ? ", $data - self::DELTA);
125113
}
126-
$select->order($valueAlias . ' DESC')
114+
$select->order("${value} DESC")
127115
->limit($rightIndex - $offset + 1, $offset - 1);
128116

129117
return $this->arrayValuesToFloat(

0 commit comments

Comments
 (0)