7
7
8
8
namespace Magento \CatalogSearch \Model \Layer \Filter ;
9
9
10
+ use Magento \Catalog \Model \Layer ;
10
11
use Magento \Catalog \Model \Layer \Filter \AbstractFilter ;
12
+ use Magento \Catalog \Model \Layer \Filter \Item \DataBuilder ;
13
+ use Magento \Catalog \Model \Layer \Filter \ItemFactory ;
14
+ use Magento \Catalog \Model \ResourceModel \Layer \Filter \Decimal as ResourceDecimal ;
15
+ use Magento \Catalog \Model \ResourceModel \Layer \Filter \DecimalFactory ;
16
+ use Magento \CatalogSearch \Model \ResourceModel \Fulltext \Collection as ProductCollection ;
17
+ use Magento \Framework \App \RequestInterface ;
18
+ use Magento \Framework \Phrase ;
19
+ use Magento \Framework \Pricing \PriceCurrencyInterface ;
20
+ use Magento \Store \Model \StoreManagerInterface ;
11
21
12
22
/**
13
23
* Layer decimal filter
14
24
*/
15
25
class Decimal extends AbstractFilter
16
26
{
17
27
/**
18
- * @var \Magento\Framework\Pricing\ PriceCurrencyInterface
28
+ * @var PriceCurrencyInterface
19
29
*/
20
30
private $ priceCurrency ;
21
31
22
32
/**
23
- * @var \Magento\Catalog\Model\ResourceModel\Layer\Filter\Decimal
33
+ * @var ResourceDecimal
24
34
*/
25
35
private $ resource ;
26
36
27
37
/**
28
- * @param \Magento\Catalog\Model\Layer\Filter\ ItemFactory $filterItemFactory
29
- * @param \Magento\Store\Model\ StoreManagerInterface $storeManager
30
- * @param \Magento\Catalog\Model\ Layer $layer
31
- * @param \Magento\Catalog\Model\Layer\Filter\Item\ DataBuilder $itemDataBuilder
32
- * @param \Magento\Catalog\Model\ResourceModel\Layer\Filter\ DecimalFactory $filterDecimalFactory
33
- * @param \Magento\Framework\Pricing\ PriceCurrencyInterface $priceCurrency
38
+ * @param ItemFactory $filterItemFactory
39
+ * @param StoreManagerInterface $storeManager
40
+ * @param Layer $layer
41
+ * @param DataBuilder $itemDataBuilder
42
+ * @param DecimalFactory $filterDecimalFactory
43
+ * @param PriceCurrencyInterface $priceCurrency
34
44
* @param array $data
35
45
*/
36
46
public function __construct (
37
- \ Magento \ Catalog \ Model \ Layer \ Filter \ ItemFactory $ filterItemFactory ,
38
- \ Magento \ Store \ Model \ StoreManagerInterface $ storeManager ,
39
- \ Magento \ Catalog \ Model \ Layer $ layer ,
40
- \ Magento \ Catalog \ Model \ Layer \ Filter \ Item \ DataBuilder $ itemDataBuilder ,
41
- \ Magento \ Catalog \ Model \ ResourceModel \ Layer \ Filter \ DecimalFactory $ filterDecimalFactory ,
42
- \ Magento \ Framework \ Pricing \ PriceCurrencyInterface $ priceCurrency ,
47
+ ItemFactory $ filterItemFactory ,
48
+ StoreManagerInterface $ storeManager ,
49
+ Layer $ layer ,
50
+ DataBuilder $ itemDataBuilder ,
51
+ DecimalFactory $ filterDecimalFactory ,
52
+ PriceCurrencyInterface $ priceCurrency ,
43
53
array $ data = []
44
54
) {
45
55
parent ::__construct (
@@ -56,11 +66,10 @@ public function __construct(
56
66
/**
57
67
* Apply price range filter
58
68
*
59
- * @param \Magento\Framework\App\ RequestInterface $request
69
+ * @param RequestInterface $request
60
70
* @return $this
61
- * @throws \Magento\Framework\Exception\LocalizedException
62
71
*/
63
- public function apply (\ Magento \ Framework \ App \ RequestInterface $ request )
72
+ public function apply (RequestInterface $ request )
64
73
{
65
74
/**
66
75
* Filter must be string: $fromPrice-$toPrice
@@ -71,6 +80,8 @@ public function apply(\Magento\Framework\App\RequestInterface $request)
71
80
}
72
81
73
82
list ($ from , $ to ) = explode ('- ' , $ filter );
83
+ $ from = (float )$ from ;
84
+ $ to = (float )$ to ;
74
85
75
86
$ this ->getLayer ()
76
87
->getProductCollection ()
@@ -90,14 +101,12 @@ public function apply(\Magento\Framework\App\RequestInterface $request)
90
101
* Get data array for building attribute filter items
91
102
*
92
103
* @return array
93
- * @throws \Magento\Framework\Exception\LocalizedException
94
- * @SuppressWarnings(PHPMD.NPathComplexity)
95
104
*/
96
105
protected function _getItemsData ()
97
106
{
98
107
$ attribute = $ this ->getAttributeModel ();
99
108
100
- /** @var \Magento\CatalogSearch\Model\ResourceModel\Fulltext\Collection $productCollection */
109
+ /** @var ProductCollection $productCollection */
101
110
$ productCollection = $ this ->getLayer ()->getProductCollection ();
102
111
$ productSize = $ productCollection ->getSize ();
103
112
$ facets = $ productCollection ->getFacetedData ($ attribute ->getAttributeCode ());
@@ -123,7 +132,7 @@ protected function _getItemsData()
123
132
'value ' => $ value ,
124
133
'count ' => $ count ,
125
134
'from ' => $ from ,
126
- 'to ' => $ to
135
+ 'to ' => $ to,
127
136
];
128
137
}
129
138
@@ -135,7 +144,7 @@ protected function _getItemsData()
135
144
*
136
145
* @param float|string $fromPrice
137
146
* @param float|string $toPrice
138
- * @return \Magento\Framework\ Phrase
147
+ * @return Phrase
139
148
*/
140
149
protected function renderRangeLabel ($ fromPrice , $ toPrice )
141
150
{
@@ -146,6 +155,7 @@ protected function renderRangeLabel($fromPrice, $toPrice)
146
155
if ($ fromPrice != $ toPrice ) {
147
156
$ toPrice -= .01 ;
148
157
}
158
+
149
159
return __ ('%1 - %2 ' , $ formattedFromPrice , $ this ->priceCurrency ->format ($ toPrice ));
150
160
}
151
161
}
0 commit comments