Skip to content

Instantly share code, notes, and snippets.

@vasilii-b
Created January 17, 2022 10:10
Show Gist options
  • Save vasilii-b/1a3482752bf6295a60cae45b68f1a29c to your computer and use it in GitHub Desktop.
Save vasilii-b/1a3482752bf6295a60cae45b68f1a29c to your computer and use it in GitHub Desktop.
Magento 2 View Model helpers
<?php
namespace ImaginationMedia\CaspianFrontend\ViewModel;
use Magento\Framework\Pricing\PriceCurrencyInterface;
use Magento\Framework\View\Element\Block\ArgumentInterface;
/**
* Class FormatPriceViewModel
*/
class FormatPriceViewModel implements ArgumentInterface
{
private PriceCurrencyInterface $priceCurrency;
/**
* @param PriceCurrencyInterface $priceCurrency
*/
public function __construct(
PriceCurrencyInterface $priceCurrency
) {
$this->priceCurrency = $priceCurrency;
}
/**
* @param $amount
* @param bool $includeContainer
* @param int $precision
* @param $scope
* @param $currency
*
* @return string
*/
public function convertAndFormat(
$amount,
bool $includeContainer = true,
int $precision = PriceCurrencyInterface::DEFAULT_PRECISION,
$scope = null,
$currency = null
): string {
return $this->priceCurrency->convertAndFormat(
$amount,
$includeContainer,
$precision,
$scope,
$currency
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment