Created
January 17, 2022 10:10
-
-
Save vasilii-b/1a3482752bf6295a60cae45b68f1a29c to your computer and use it in GitHub Desktop.
Magento 2 View Model helpers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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