8
8
9
9
use Magento \Catalog \Pricing \Price ;
10
10
use Magento \Framework \App \ObjectManager ;
11
- use Magento \Framework \Module \Manager ;
12
- use Magento \Framework \Pricing \Render ;
13
11
use Magento \Framework \Pricing \Render \PriceBox as BasePriceBox ;
14
- use Magento \Msrp \Pricing \Price \MsrpPrice ;
15
- use Magento \Catalog \Model \Product \Pricing \Renderer \SalableResolverInterface ;
16
- use Magento \Framework \View \Element \Template \Context ;
17
12
use Magento \Framework \Pricing \SaleableInterface ;
18
13
use Magento \Framework \Pricing \Price \PriceInterface ;
19
14
use Magento \Framework \Pricing \Render \RendererPool ;
15
+ use Magento \Msrp \Pricing \Price \MsrpPrice ;
16
+ use Magento \Framework \View \Element \Template \Context ;
20
17
21
18
/**
22
- * Class for final_price rendering
19
+ * Class for final_price rendering.
23
20
*
24
21
* @method bool getUseLinkForAsLowAs()
25
22
* @method bool getDisplayMinimalPrice()
26
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
27
23
*/
28
24
class FinalPriceBox extends BasePriceBox
29
25
{
30
26
/**
31
- * @var SalableResolverInterface
27
+ * Interface resolver provided to check is product available for sale.
28
+ *
29
+ * @var \Magento\Catalog\Model\Product\Pricing\Renderer\SalableResolverInterface
32
30
*/
33
31
private $ salableResolver ;
34
32
35
- /** @var Manager */
33
+ /**
34
+ * Module statuses manager.
35
+ *
36
+ * @var \Magento\Framework\Module\Manager
37
+ */
36
38
private $ moduleManager ;
37
39
40
+ /**
41
+ * Shows minimal value of Tier Prices.
42
+ *
43
+ * @var \Magento\Catalog\Pricing\Price\MinimalPriceCalculatorInterface
44
+ */
45
+ private $ minimalPriceCalculator ;
46
+
38
47
/**
39
48
* @param Context $context
40
49
* @param SaleableInterface $saleableItem
41
50
* @param PriceInterface $price
42
51
* @param RendererPool $rendererPool
43
52
* @param array $data
44
- * @param SalableResolverInterface $salableResolver
53
+ * @param \Magento\Catalog\Model\Product\Pricing\Renderer\ SalableResolverInterface $salableResolver
45
54
*/
46
55
public function __construct (
47
56
Context $ context ,
48
57
SaleableInterface $ saleableItem ,
49
58
PriceInterface $ price ,
50
59
RendererPool $ rendererPool ,
51
60
array $ data = [],
52
- SalableResolverInterface $ salableResolver = null
61
+ \ Magento \ Catalog \ Model \ Product \ Pricing \ Renderer \ SalableResolverInterface $ salableResolver = null
53
62
) {
54
63
parent ::__construct ($ context , $ saleableItem , $ price , $ rendererPool , $ data );
55
- $ this ->salableResolver = $ salableResolver ?: \ Magento \ Framework \ App \ ObjectManager::getInstance ()
56
- ->get (SalableResolverInterface::class);
64
+ $ this ->salableResolver = $ salableResolver ?: ObjectManager::getInstance ()
65
+ ->get (\ Magento \ Catalog \ Model \ Product \ Pricing \ Renderer \ SalableResolverInterface::class);
57
66
}
58
67
59
68
/**
@@ -116,7 +125,7 @@ private function isMsrpPriceApplicable()
116
125
}
117
126
118
127
/**
119
- * Wrap with standard required container
128
+ * Wrap with standard required container.
120
129
*
121
130
* @param string $html
122
131
* @return string
@@ -130,17 +139,21 @@ protected function wrapResult($html)
130
139
}
131
140
132
141
/**
133
- * Render minimal amount
142
+ * Render minimal amount.
134
143
*
135
144
* @return string
136
145
*/
137
146
public function renderAmountMinimal ()
138
147
{
139
- /** @var \Magento\Catalog\Pricing\Price\FinalPrice $price */
140
- $ price = $ this ->getPriceType (\Magento \Catalog \Pricing \Price \FinalPrice::PRICE_CODE );
141
148
$ id = $ this ->getPriceId () ? $ this ->getPriceId () : 'product-minimal-price- ' . $ this ->getSaleableItem ()->getId ();
149
+ $ amount = $ this ->getMinimalPriceCalculator ()->getAmount ($ this ->getSaleableItem ());
150
+
151
+ if ($ amount === null ) {
152
+ return '' ;
153
+ }
154
+
142
155
return $ this ->renderAmount (
143
- $ price -> getMinimalPrice () ,
156
+ $ amount ,
144
157
[
145
158
'display_label ' => __ ('As low as ' ),
146
159
'price_id ' => $ id ,
@@ -151,7 +164,7 @@ public function renderAmountMinimal()
151
164
}
152
165
153
166
/**
154
- * Define if the special price should be shown
167
+ * Define if the special price should be shown.
155
168
*
156
169
* @return bool
157
170
*/
@@ -163,23 +176,25 @@ public function hasSpecialPrice()
163
176
}
164
177
165
178
/**
166
- * Define if the minimal price should be shown
179
+ * Define if the minimal price should be shown.
167
180
*
168
181
* @return bool
169
182
*/
170
183
public function showMinimalPrice ()
171
184
{
185
+ $ minTierPrice = $ this ->getMinimalPriceCalculator ()->getValue ($ this ->getSaleableItem ());
186
+
172
187
/** @var Price\FinalPrice $finalPrice */
173
188
$ finalPrice = $ this ->getPriceType (Price \FinalPrice::PRICE_CODE );
174
189
$ finalPriceValue = $ finalPrice ->getAmount ()->getValue ();
175
- $ minimalPriceAValue = $ finalPrice -> getMinimalPrice ()-> getValue ();
190
+
176
191
return $ this ->getDisplayMinimalPrice ()
177
- && $ minimalPriceAValue
178
- && $ minimalPriceAValue < $ finalPriceValue ;
192
+ && $ minTierPrice !== null
193
+ && $ minTierPrice < $ finalPriceValue ;
179
194
}
180
195
181
196
/**
182
- * Get Key for caching block content
197
+ * Get Key for caching block content.
183
198
*
184
199
* @return string
185
200
*/
@@ -203,19 +218,19 @@ public function getCacheKeyInfo()
203
218
204
219
/**
205
220
* @deprecated
206
- * @return Manager
221
+ * @return \Magento\Framework\Module\ Manager
207
222
*/
208
223
private function getModuleManager ()
209
224
{
210
225
if ($ this ->moduleManager === null ) {
211
- $ this ->moduleManager = ObjectManager::getInstance ()->get (Manager::class);
226
+ $ this ->moduleManager = ObjectManager::getInstance ()->get (\ Magento \ Framework \ Module \ Manager::class);
212
227
}
213
228
return $ this ->moduleManager ;
214
229
}
215
230
216
231
/**
217
- * Get flag that price rendering should be done for the list of products
218
- * By default (if flag is not set) is false
232
+ * Get flag that price rendering should be done for the list of products.
233
+ * By default (if flag is not set) is false.
219
234
*
220
235
* @return bool
221
236
*/
@@ -224,4 +239,18 @@ public function isProductList()
224
239
$ isProductList = $ this ->getData ('is_product_list ' );
225
240
return $ isProductList === true ;
226
241
}
242
+
243
+ /**
244
+ * @deprecated
245
+ * @return \Magento\Catalog\Pricing\Price\MinimalPriceCalculatorInterface
246
+ */
247
+ private function getMinimalPriceCalculator ()
248
+ {
249
+ if ($ this ->minimalPriceCalculator == null ) {
250
+ $ this ->minimalPriceCalculator = ObjectManager::getInstance ()
251
+ ->get (\Magento \Catalog \Pricing \Price \MinimalPriceCalculatorInterface::class);
252
+ }
253
+
254
+ return $ this ->minimalPriceCalculator ;
255
+ }
227
256
}
0 commit comments