99use Magento \Catalog \Model \Product ;
1010use Magento \Customer \Api \GroupManagementInterface ;
1111use Magento \Customer \Model \Session ;
12+ use Magento \Framework \App \Config \ScopeConfigInterface ;
13+ use Magento \Framework \App \ObjectManager ;
1214use Magento \Framework \Pricing \Adjustment \CalculatorInterface ;
1315use Magento \Framework \Pricing \Amount \AmountInterface ;
1416use Magento \Framework \Pricing \Price \AbstractPrice ;
1517use Magento \Framework \Pricing \Price \BasePriceProviderInterface ;
18+ use Magento \Framework \Pricing \PriceCurrencyInterface ;
1619use Magento \Framework \Pricing \PriceInfoInterface ;
1720use Magento \Customer \Model \Group \RetrieverInterface as CustomerGroupRetrieverInterface ;
21+ use Magento \Tax \Model \Config ;
1822
1923/**
2024 * @api
2125 * @since 100.0.2
26+ * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
27+ * @SuppressWarnings(PHPMD.CookieAndSessionMisuse)
2228 */
2329class TierPrice extends AbstractPrice implements TierPriceInterface, BasePriceProviderInterface
2430{
31+ private const XML_PATH_TAX_DISPLAY_TYPE = 'tax/display/type ' ;
32+
2533 /**
2634 * Price type tier
2735 */
@@ -62,35 +70,43 @@ class TierPrice extends AbstractPrice implements TierPriceInterface, BasePricePr
6270 */
6371 private $ customerGroupRetriever ;
6472
73+ /**
74+ * @var ScopeConfigInterface
75+ */
76+ private $ scopeConfig ;
77+
6578 /**
6679 * @param Product $saleableItem
6780 * @param float $quantity
6881 * @param CalculatorInterface $calculator
69- * @param \Magento\Framework\Pricing\ PriceCurrencyInterface $priceCurrency
82+ * @param PriceCurrencyInterface $priceCurrency
7083 * @param Session $customerSession
7184 * @param GroupManagementInterface $groupManagement
7285 * @param CustomerGroupRetrieverInterface|null $customerGroupRetriever
86+ * @param ScopeConfigInterface|null $scopeConfig
7387 */
7488 public function __construct (
7589 Product $ saleableItem ,
7690 $ quantity ,
7791 CalculatorInterface $ calculator ,
78- \ Magento \ Framework \ Pricing \ PriceCurrencyInterface $ priceCurrency ,
92+ PriceCurrencyInterface $ priceCurrency ,
7993 Session $ customerSession ,
8094 GroupManagementInterface $ groupManagement ,
81- CustomerGroupRetrieverInterface $ customerGroupRetriever = null
95+ CustomerGroupRetrieverInterface $ customerGroupRetriever = null ,
96+ ?ScopeConfigInterface $ scopeConfig = null
8297 ) {
8398 $ quantity = (float )$ quantity ? $ quantity : 1 ;
8499 parent ::__construct ($ saleableItem , $ quantity , $ calculator , $ priceCurrency );
85100 $ this ->customerSession = $ customerSession ;
86101 $ this ->groupManagement = $ groupManagement ;
87102 $ this ->customerGroupRetriever = $ customerGroupRetriever
88- ?? \ Magento \ Framework \ App \ ObjectManager::getInstance ()->get (CustomerGroupRetrieverInterface::class);
103+ ?? ObjectManager::getInstance ()->get (CustomerGroupRetrieverInterface::class);
89104 if ($ saleableItem ->hasCustomerGroupId ()) {
90105 $ this ->customerGroup = (int ) $ saleableItem ->getCustomerGroupId ();
91106 } else {
92107 $ this ->customerGroup = (int ) $ this ->customerGroupRetriever ->getCustomerGroupId ();
93108 }
109+ $ this ->scopeConfig = $ scopeConfig ?: ObjectManager::getInstance ()->get (ScopeConfigInterface::class);
94110 }
95111
96112 /**
@@ -136,6 +152,8 @@ protected function isFirstPriceBetter($firstPrice, $secondPrice)
136152 }
137153
138154 /**
155+ * Returns tier price count
156+ *
139157 * @return int
140158 */
141159 public function getTierPriceCount ()
@@ -144,6 +162,8 @@ public function getTierPriceCount()
144162 }
145163
146164 /**
165+ * Returns tier price list
166+ *
147167 * @return array
148168 */
149169 public function getTierPriceList ()
@@ -155,15 +175,32 @@ public function getTierPriceList()
155175 $ this ->priceList ,
156176 function (&$ priceData ) {
157177 /* 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+ }
159183 $ priceData ['price ' ] = $ this ->applyAdjustment ($ priceData ['price ' ]);
160184 }
161185 );
162186 }
187+
163188 return $ this ->priceList ;
164189 }
165190
166191 /**
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+ *
167204 * @param array $priceList
168205 * @return array
169206 */
@@ -204,6 +241,8 @@ protected function filterTierPrices(array $priceList)
204241 }
205242
206243 /**
244+ * Returns base price
245+ *
207246 * @return float
208247 */
209248 protected function getBasePrice ()
@@ -213,25 +252,22 @@ protected function getBasePrice()
213252 }
214253
215254 /**
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.
218256 *
219257 * @param AmountInterface $amount
220- *
221258 * @return float
222259 */
223260 public function getSavePercent (AmountInterface $ amount )
224261 {
225- $ productPriceAmount = $ this ->priceInfo ->getPrice (
226- FinalPrice::PRICE_CODE
227- )->getAmount ();
262+ $ productPriceAmount = $ this ->priceInfo ->getPrice (FinalPrice::PRICE_CODE )
263+ ->getAmount ();
228264
229- return round (
230- 100 - ((100 / $ productPriceAmount ->getValue ()) * $ amount ->getValue ())
231- );
265+ return round (100 - ((100 / $ productPriceAmount ->getValue ()) * $ amount ->getValue ()));
232266 }
233267
234268 /**
269+ * Apply adjustment to price
270+ *
235271 * @param float|string $price
236272 * @return \Magento\Framework\Pricing\Amount\AmountInterface
237273 */
@@ -314,6 +350,8 @@ protected function getStoredTierPrices()
314350 }
315351
316352 /**
353+ * Return is percentage discount
354+ *
317355 * @return bool
318356 */
319357 public function isPercentageDiscount ()
0 commit comments