Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Prices.php
Go to the documentation of this file.
1 <?php
7 declare(strict_types=1);
8 
10 
14 class Prices
15 {
19  private $localeFormat;
20 
25  public function __construct(\Magento\Framework\Locale\Format $localeFormat)
26  {
27  $this->localeFormat = $localeFormat;
28  }
29 
36  public function getFormattedPrices(\Magento\Framework\Pricing\PriceInfo\Base $priceInfo)
37  {
38  $regularPrice = $priceInfo->getPrice('regular_price');
39  $finalPrice = $priceInfo->getPrice('final_price');
40 
41  return [
42  'oldPrice' => [
43  'amount' => $this->localeFormat->getNumber($regularPrice->getAmount()->getValue()),
44  ],
45  'basePrice' => [
46  'amount' => $this->localeFormat->getNumber($finalPrice->getAmount()->getBaseAmount()),
47  ],
48  'finalPrice' => [
49  'amount' => $this->localeFormat->getNumber($finalPrice->getAmount()->getValue()),
50  ],
51  ];
52  }
53 }
getFormattedPrices(\Magento\Framework\Pricing\PriceInfo\Base $priceInfo)
Definition: Prices.php:36
__construct(\Magento\Framework\Locale\Format $localeFormat)
Definition: Prices.php:25