9
9
use Magento \Catalog \Model \Product ;
10
10
use Magento \Customer \Api \GroupManagementInterface ;
11
11
use Magento \Customer \Model \Session ;
12
+ use Magento \Framework \App \Config \ScopeConfigInterface ;
13
+ use Magento \Framework \App \ObjectManager ;
12
14
use Magento \Framework \Pricing \Adjustment \CalculatorInterface ;
13
15
use Magento \Framework \Pricing \Amount \AmountInterface ;
14
16
use Magento \Framework \Pricing \Price \AbstractPrice ;
15
17
use Magento \Framework \Pricing \Price \BasePriceProviderInterface ;
18
+ use Magento \Framework \Pricing \PriceCurrencyInterface ;
16
19
use Magento \Framework \Pricing \PriceInfoInterface ;
17
20
use Magento \Customer \Model \Group \RetrieverInterface as CustomerGroupRetrieverInterface ;
21
+ use Magento \Tax \Model \Config ;
18
22
19
23
/**
20
24
* @api
21
25
* @since 100.0.2
26
+ * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
27
+ * @SuppressWarnings(PHPMD.CookieAndSessionMisuse)
22
28
*/
23
29
class TierPrice extends AbstractPrice implements TierPriceInterface, BasePriceProviderInterface
24
30
{
31
+ private const XML_PATH_TAX_DISPLAY_TYPE = 'tax/display/type ' ;
32
+
25
33
/**
26
34
* Price type tier
27
35
*/
@@ -61,42 +69,44 @@ class TierPrice extends AbstractPrice implements TierPriceInterface, BasePricePr
61
69
* @var CustomerGroupRetrieverInterface
62
70
*/
63
71
private $ customerGroupRetriever ;
72
+
64
73
/**
65
- * @var \Magento\Framework\App\Config\ ScopeConfigInterface
74
+ * @var ScopeConfigInterface
66
75
*/
67
76
private $ scopeConfig ;
68
77
69
78
/**
70
79
* @param Product $saleableItem
71
80
* @param float $quantity
72
81
* @param CalculatorInterface $calculator
73
- * @param \Magento\Framework\Pricing\ PriceCurrencyInterface $priceCurrency
82
+ * @param PriceCurrencyInterface $priceCurrency
74
83
* @param Session $customerSession
75
84
* @param GroupManagementInterface $groupManagement
76
85
* @param CustomerGroupRetrieverInterface|null $customerGroupRetriever
86
+ * @param ScopeConfigInterface|null $scopeConfig
77
87
*/
78
88
public function __construct (
79
89
Product $ saleableItem ,
80
90
$ quantity ,
81
91
CalculatorInterface $ calculator ,
82
- \ Magento \ Framework \ Pricing \ PriceCurrencyInterface $ priceCurrency ,
92
+ PriceCurrencyInterface $ priceCurrency ,
83
93
Session $ customerSession ,
84
94
GroupManagementInterface $ groupManagement ,
85
95
CustomerGroupRetrieverInterface $ customerGroupRetriever = null ,
86
- \ Magento \ Framework \ App \ Config \ ScopeConfigInterface $ scopeConfig
96
+ ? ScopeConfigInterface $ scopeConfig = null
87
97
) {
88
98
$ quantity = (float )$ quantity ? $ quantity : 1 ;
89
99
parent ::__construct ($ saleableItem , $ quantity , $ calculator , $ priceCurrency );
90
100
$ this ->customerSession = $ customerSession ;
91
101
$ this ->groupManagement = $ groupManagement ;
92
102
$ this ->customerGroupRetriever = $ customerGroupRetriever
93
- ?? \ Magento \ Framework \ App \ ObjectManager::getInstance ()->get (CustomerGroupRetrieverInterface::class);
103
+ ?? ObjectManager::getInstance ()->get (CustomerGroupRetrieverInterface::class);
94
104
if ($ saleableItem ->hasCustomerGroupId ()) {
95
105
$ this ->customerGroup = (int ) $ saleableItem ->getCustomerGroupId ();
96
106
} else {
97
107
$ this ->customerGroup = (int ) $ this ->customerGroupRetriever ->getCustomerGroupId ();
98
108
}
99
- $ this ->scopeConfig = $ scopeConfig ;
109
+ $ this ->scopeConfig = $ scopeConfig ?: ObjectManager:: getInstance ()-> get (ScopeConfigInterface::class) ;
100
110
}
101
111
102
112
/**
@@ -142,6 +152,8 @@ protected function isFirstPriceBetter($firstPrice, $secondPrice)
142
152
}
143
153
144
154
/**
155
+ * Returns tier price count
156
+ *
145
157
* @return int
146
158
*/
147
159
public function getTierPriceCount ()
@@ -150,6 +162,8 @@ public function getTierPriceCount()
150
162
}
151
163
152
164
/**
165
+ * Returns tier price list
166
+ *
153
167
* @return array
154
168
*/
155
169
public function getTierPriceList ()
@@ -161,18 +175,32 @@ public function getTierPriceList()
161
175
$ this ->priceList ,
162
176
function (&$ priceData ) {
163
177
/* convert string value to float */
164
- $ priceData ['price_qty ' ] = $ priceData [ ' price_qty ' ] * 1 ;
165
- $ priceData [ ' price ' ] = $ this ->applyAdjustment ( $ priceData [ ' price ' ]);
166
- if ( $ this ->scopeConfig -> getValue ( ' tax/display/type ' ) == 3 ) {
167
- $ priceData ['excl_tax_price ' ] = $ this -> applyAdjustment ( $ priceData [ ' excl_tax_price ' ], true ) ;
178
+ $ priceData ['price_qty ' ] *= 1 ;
179
+ if ( $ this ->getConfigTaxDisplayType () === Config:: DISPLAY_TYPE_BOTH ) {
180
+ $ exclTaxPrice = $ this ->calculator -> getAmount ( $ priceData [ ' price ' ], $ this -> product , true );
181
+ $ priceData ['excl_tax_price ' ] = $ exclTaxPrice ;
168
182
}
183
+ $ priceData ['price ' ] = $ this ->applyAdjustment ($ priceData ['price ' ]);
169
184
}
170
185
);
171
186
}
187
+
172
188
return $ this ->priceList ;
173
189
}
174
190
175
191
/**
192
+ * Returns config tax display type
193
+ *
194
+ * @return int
195
+ */
196
+ private function getConfigTaxDisplayType (): int
197
+ {
198
+ return (int ) $ this ->scopeConfig ->getValue (self ::XML_PATH_TAX_DISPLAY_TYPE );
199
+ }
200
+
201
+ /**
202
+ * Filters tier prices
203
+ *
176
204
* @param array $priceList
177
205
* @return array
178
206
*/
@@ -213,6 +241,8 @@ protected function filterTierPrices(array $priceList)
213
241
}
214
242
215
243
/**
244
+ * Returns base price
245
+ *
216
246
* @return float
217
247
*/
218
248
protected function getBasePrice ()
@@ -222,27 +252,24 @@ protected function getBasePrice()
222
252
}
223
253
224
254
/**
225
- * Calculates savings percentage according to the given tier price amount
226
- * and related product price amount.
255
+ * Calculates savings percentage according to the given tier price amount and related product price amount.
227
256
*
228
257
* @param AmountInterface $amount
229
- *
230
258
* @return float
231
259
*/
232
260
public function getSavePercent (AmountInterface $ amount )
233
261
{
234
- $ productPriceAmount = $ this ->priceInfo ->getPrice (
235
- FinalPrice::PRICE_CODE
236
- )->getAmount ();
262
+ $ productPriceAmount = $ this ->priceInfo ->getPrice (FinalPrice::PRICE_CODE )
263
+ ->getAmount ();
237
264
238
- return round (
239
- 100 - ((100 / $ productPriceAmount ->getValue ()) * $ amount ->getValue ())
240
- );
265
+ return round (100 - ((100 / $ productPriceAmount ->getValue ()) * $ amount ->getValue ()));
241
266
}
242
267
243
268
/**
269
+ * Apply adjustment to price
270
+ *
244
271
* @param float|string $price
245
- * @return \Magento\Framework\Pricing\Amount\ AmountInterface
272
+ * @return AmountInterface
246
273
*/
247
274
protected function applyAdjustment ($ price )
248
275
{
@@ -323,6 +350,8 @@ protected function getStoredTierPrices()
323
350
}
324
351
325
352
/**
353
+ * Return is percentage discount
354
+ *
326
355
* @return bool
327
356
*/
328
357
public function isPercentageDiscount ()
0 commit comments