Skip to content

Commit f96b8a1

Browse files
Merge remote-tracking branch 'origin/MAGETWO-63175-Layered-Navigation' into Okapis-PR-8-15
2 parents 213fb0e + e54a4ad commit f96b8a1

File tree

3 files changed

+43
-18
lines changed
  • app/code/Magento/CatalogSearch
  • dev/tests/integration/testsuite/Magento/CatalogSearch/Model/Layer/Filter

3 files changed

+43
-18
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,9 @@ public function getCurrencyRate()
175175
*/
176176
protected function _renderRangeLabel($fromPrice, $toPrice)
177177
{
178+
$fromPrice = empty($fromPrice) ? 0 : $fromPrice * $this->getCurrencyRate();
179+
$toPrice = empty($toPrice) ? $toPrice : $toPrice * $this->getCurrencyRate();
180+
178181
$formattedFromPrice = $this->priceCurrency->format($fromPrice);
179182
if ($toPrice === '') {
180183
return __('%1 and above', $formattedFromPrice);
@@ -261,10 +264,7 @@ private function prepareData($key, $count)
261264
if ($to == '*') {
262265
$to = $this->getTo($to);
263266
}
264-
$label = $this->_renderRangeLabel(
265-
empty($from) ? 0 : $from * $this->getCurrencyRate(),
266-
empty($to) ? $to : $to * $this->getCurrencyRate()
267-
);
267+
$label = $this->_renderRangeLabel($from, $to);
268268
$value = $from . '-' . $to . $this->dataProvider->getAdditionalRequestData();
269269

270270
$data = [

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ function ($field) use ($requestVar, $priceId) {
225225
->with('price')
226226
->will($this->returnSelf());
227227

228+
$this->target->setCurrencyRate(1);
228229
$this->target->apply($this->request);
229230
}
230231

dev/tests/integration/testsuite/Magento/CatalogSearch/Model/Layer/Filter/PriceTest.php

Lines changed: 38 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
*/
66
namespace Magento\CatalogSearch\Model\Layer\Filter;
77

8+
use Magento\TestFramework\Helper\Bootstrap;
9+
810
/**
911
* Test class for \Magento\CatalogSearch\Model\Layer\Filter\Price.
1012
*
@@ -19,26 +21,31 @@ class PriceTest extends \PHPUnit\Framework\TestCase
1921
*/
2022
protected $_model;
2123

24+
/**
25+
* @var \Magento\Framework\ObjectManagerInterface
26+
*/
27+
private $objectManager;
28+
2229
protected function setUp()
2330
{
24-
$category = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
31+
$this->objectManager = Bootstrap::getObjectManager();
32+
$category = $this->objectManager->create(
2533
\Magento\Catalog\Model\Category::class
2634
);
2735
$category->load(4);
28-
$layer = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
29-
->get(\Magento\Catalog\Model\Layer\Category::class);
36+
$layer = $this->objectManager->get(\Magento\Catalog\Model\Layer\Category::class);
3037
$layer->setCurrentCategory($category);
31-
$this->_model = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
32-
->create(\Magento\CatalogSearch\Model\Layer\Filter\Price::class, ['layer' => $layer]);
38+
$this->_model = $this->objectManager->create(
39+
\Magento\CatalogSearch\Model\Layer\Filter\Price::class,
40+
['layer' => $layer]
41+
);
3342
}
3443

3544
public function testApplyNothing()
3645
{
3746
$this->assertEmpty($this->_model->getData('price_range'));
38-
/** @var $objectManager \Magento\TestFramework\ObjectManager */
39-
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
4047
/** @var $request \Magento\TestFramework\Request */
41-
$request = $objectManager->get(\Magento\TestFramework\Request::class);
48+
$request = $this->objectManager->get(\Magento\TestFramework\Request::class);
4249
$this->_model->apply($request);
4350

4451
$this->assertEmpty($this->_model->getData('price_range'));
@@ -47,10 +54,8 @@ public function testApplyNothing()
4754
public function testApplyInvalid()
4855
{
4956
$this->assertEmpty($this->_model->getData('price_range'));
50-
/** @var $objectManager \Magento\TestFramework\ObjectManager */
51-
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
5257
/** @var $request \Magento\TestFramework\Request */
53-
$request = $objectManager->get(\Magento\TestFramework\Request::class);
58+
$request = $this->objectManager->get(\Magento\TestFramework\Request::class);
5459
$request->setParam('price', 'non-numeric');
5560
$this->_model->apply($request);
5661

@@ -62,12 +67,31 @@ public function testApplyInvalid()
6267
*/
6368
public function testApplyManual()
6469
{
65-
/** @var $objectManager \Magento\TestFramework\ObjectManager */
66-
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
6770
/** @var $request \Magento\TestFramework\Request */
68-
$request = $objectManager->get(\Magento\TestFramework\Request::class);
71+
$request = $this->objectManager->get(\Magento\TestFramework\Request::class);
72+
$request->setParam('price', '10-20');
73+
$this->_model->apply($request);
74+
}
75+
76+
/**
77+
* Make sure that currency rate is used to calculate label for applied price filter
78+
*/
79+
public function testApplyWithCustomCurrencyRate()
80+
{
81+
/** @var $request \Magento\TestFramework\Request */
82+
$request = $this->objectManager->get(\Magento\TestFramework\Request::class);
83+
6984
$request->setParam('price', '10-20');
85+
$this->_model->setCurrencyRate(10);
86+
7087
$this->_model->apply($request);
88+
89+
$filters = $this->_model->getLayer()->getState()->getFilters();
90+
$this->assertArrayHasKey(0, $filters);
91+
$this->assertEquals(
92+
'<span class="price">$100.00</span> - <span class="price">$199.99</span>',
93+
(string)$filters[0]->getLabel()
94+
);
7195
}
7296

7397
public function testGetSetCustomerGroupId()

0 commit comments

Comments
 (0)