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
*/
@@ -62,35 +70,43 @@ class TierPrice extends AbstractPrice implements TierPriceInterface, BasePricePr
62
70
*/
63
71
private $ customerGroupRetriever ;
64
72
73
+ /**
74
+ * @var ScopeConfigInterface
75
+ */
76
+ private $ scopeConfig ;
77
+
65
78
/**
66
79
* @param Product $saleableItem
67
80
* @param float $quantity
68
81
* @param CalculatorInterface $calculator
69
- * @param \Magento\Framework\Pricing\ PriceCurrencyInterface $priceCurrency
82
+ * @param PriceCurrencyInterface $priceCurrency
70
83
* @param Session $customerSession
71
84
* @param GroupManagementInterface $groupManagement
72
85
* @param CustomerGroupRetrieverInterface|null $customerGroupRetriever
86
+ * @param ScopeConfigInterface|null $scopeConfig
73
87
*/
74
88
public function __construct (
75
89
Product $ saleableItem ,
76
90
$ quantity ,
77
91
CalculatorInterface $ calculator ,
78
- \ Magento \ Framework \ Pricing \ PriceCurrencyInterface $ priceCurrency ,
92
+ PriceCurrencyInterface $ priceCurrency ,
79
93
Session $ customerSession ,
80
94
GroupManagementInterface $ groupManagement ,
81
- CustomerGroupRetrieverInterface $ customerGroupRetriever = null
95
+ CustomerGroupRetrieverInterface $ customerGroupRetriever = null ,
96
+ ?ScopeConfigInterface $ scopeConfig = null
82
97
) {
83
98
$ quantity = (float )$ quantity ? $ quantity : 1 ;
84
99
parent ::__construct ($ saleableItem , $ quantity , $ calculator , $ priceCurrency );
85
100
$ this ->customerSession = $ customerSession ;
86
101
$ this ->groupManagement = $ groupManagement ;
87
102
$ this ->customerGroupRetriever = $ customerGroupRetriever
88
- ?? \ Magento \ Framework \ App \ ObjectManager::getInstance ()->get (CustomerGroupRetrieverInterface::class);
103
+ ?? ObjectManager::getInstance ()->get (CustomerGroupRetrieverInterface::class);
89
104
if ($ saleableItem ->hasCustomerGroupId ()) {
90
105
$ this ->customerGroup = (int ) $ saleableItem ->getCustomerGroupId ();
91
106
} else {
92
107
$ this ->customerGroup = (int ) $ this ->customerGroupRetriever ->getCustomerGroupId ();
93
108
}
109
+ $ this ->scopeConfig = $ scopeConfig ?: ObjectManager::getInstance ()->get (ScopeConfigInterface::class);
94
110
}
95
111
96
112
/**
@@ -136,6 +152,8 @@ protected function isFirstPriceBetter($firstPrice, $secondPrice)
136
152
}
137
153
138
154
/**
155
+ * Returns tier price count
156
+ *
139
157
* @return int
140
158
*/
141
159
public function getTierPriceCount ()
@@ -144,6 +162,8 @@ public function getTierPriceCount()
144
162
}
145
163
146
164
/**
165
+ * Returns tier price list
166
+ *
147
167
* @return array
148
168
*/
149
169
public function getTierPriceList ()
@@ -155,15 +175,32 @@ public function getTierPriceList()
155
175
$ this ->priceList ,
156
176
function (&$ priceData ) {
157
177
/* convert string value to float */
158
- $ priceData ['price_qty ' ] = $ priceData ['price_qty ' ] * 1 ;
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 ;
182
+ }
159
183
$ priceData ['price ' ] = $ this ->applyAdjustment ($ priceData ['price ' ]);
160
184
}
161
185
);
162
186
}
187
+
163
188
return $ this ->priceList ;
164
189
}
165
190
166
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
+ *
167
204
* @param array $priceList
168
205
* @return array
169
206
*/
@@ -204,6 +241,8 @@ protected function filterTierPrices(array $priceList)
204
241
}
205
242
206
243
/**
244
+ * Returns base price
245
+ *
207
246
* @return float
208
247
*/
209
248
protected function getBasePrice ()
@@ -213,25 +252,22 @@ protected function getBasePrice()
213
252
}
214
253
215
254
/**
216
- * Calculates savings percentage according to the given tier price amount
217
- * and related product price amount.
255
+ * Calculates savings percentage according to the given tier price amount and related product price amount.
218
256
*
219
257
* @param AmountInterface $amount
220
- *
221
258
* @return float
222
259
*/
223
260
public function getSavePercent (AmountInterface $ amount )
224
261
{
225
- $ productPriceAmount = $ this ->priceInfo ->getPrice (
226
- FinalPrice::PRICE_CODE
227
- )->getAmount ();
262
+ $ productPriceAmount = $ this ->priceInfo ->getPrice (FinalPrice::PRICE_CODE )
263
+ ->getAmount ();
228
264
229
- return round (
230
- 100 - ((100 / $ productPriceAmount ->getValue ()) * $ amount ->getValue ())
231
- );
265
+ return round (100 - ((100 / $ productPriceAmount ->getValue ()) * $ amount ->getValue ()));
232
266
}
233
267
234
268
/**
269
+ * Apply adjustment to price
270
+ *
235
271
* @param float|string $price
236
272
* @return \Magento\Framework\Pricing\Amount\AmountInterface
237
273
*/
@@ -314,6 +350,8 @@ protected function getStoredTierPrices()
314
350
}
315
351
316
352
/**
353
+ * Return is percentage discount
354
+ *
317
355
* @return bool
318
356
*/
319
357
public function isPercentageDiscount ()
0 commit comments