Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
FormattedPriceInfoBuilder.php
Go to the documentation of this file.
1 <?php
8 
9 use Magento\Catalog\Api\Data\ProductRender\FormattedPriceInfoInterfaceFactory;
12 
17 {
21  private $priceCurrency;
22 
26  private $formattedPriceInfoFactory;
27 
33  public function __construct(
34  PriceCurrencyInterface $priceCurrency,
35  FormattedPriceInfoInterfaceFactory $formattedPriceInfoFactory
36  ) {
37  $this->priceCurrency = $priceCurrency;
38  $this->formattedPriceInfoFactory = $formattedPriceInfoFactory;
39  }
40 
53  public function build(PriceInfoInterface $priceInfo, $storeId, $currencyCode)
54  {
56  $formattedPriceInfo = $this->formattedPriceInfoFactory->create();
57 
58  foreach ($priceInfo->getData() as $key => $value) {
59  if (is_numeric($value)) {
60  $formattedValue = $this->priceCurrency
61  ->format(
62  $value,
63  true,
64  PriceCurrencyInterface::DEFAULT_PRECISION,
65  $storeId,
66  $currencyCode
67  );
68  $formattedPriceInfo->setData($key, $formattedValue);
69  }
70  }
71 
72  $priceInfo->setFormattedPrices($formattedPriceInfo);
73  }
74 }
setFormattedPrices(FormattedPriceInfoInterface $formattedPriceInfo)
$value
Definition: gender.phtml:16
__construct(PriceCurrencyInterface $priceCurrency, FormattedPriceInfoInterfaceFactory $formattedPriceInfoFactory)