72 private $currencyConfig;
91 \
Magento\Framework\Locale\FormatInterface $localeFormat,
93 \
Magento\Directory\Helper\Data $directoryHelper,
95 \
Magento\Framework\Locale\CurrencyInterface $localeCurrency,
97 \
Magento\Framework\Data\Collection\AbstractDb $resourceCollection =
null,
108 $this->_localeFormat = $localeFormat;
110 $this->_directoryHelper = $directoryHelper;
111 $this->_currencyFilterFactory = $currencyFilterFactory;
112 $this->_localeCurrency = $localeCurrency;
131 return $this->
_getData(
'currency_code');
141 return $this->
_getData(
'currency_code');
189 $code = $this->getCurrencyCodeFromToCurrency($toCurrency);
206 $code = $this->getCurrencyCodeFromToCurrency($toCurrency);
225 if ($toCurrency ===
null) {
231 throw new \Exception(
__(
232 'Undefined rate from "%1-%2".',
234 $this->getCurrencyCodeFromToCurrency($toCurrency)
243 private function getCurrencyCodeFromToCurrency($toCurrency)
245 if (is_string($toCurrency)) {
247 }
elseif ($toCurrency instanceof \
Magento\Directory\Model\Currency) {
248 $code = $toCurrency->getCurrencyCode();
250 throw new InputException(
__(
'Please correct the target currency.'));
262 if (!$this->_filter) {
263 $this->_filter = $this->_currencyFilterFactory->create([
'code' => $this->
getCode()]);
297 $includeContainer =
true,
300 if (!isset(
$options[
'precision'])) {
303 if ($includeContainer) {
304 return '<span class="price">' . ($addBrackets ?
'[' :
'') . $this->
formatTxt(
307 ) . ($addBrackets ?
']' :
'') .
'</span>';
319 if (!is_numeric(
$price)) {
339 return $this->_localeCurrency->getCurrency($this->
getCode())->getSymbol();
349 return str_replace($this->trimUnicodeDirectionMark(
$number),
'%s', $formatted);
359 $allowedCurrencies = $this->currencyConfig->getConfigCurrencies(self::XML_PATH_CURRENCY_ALLOW);
360 $appBaseCurrencyCode = $this->_directoryHelper->getBaseCurrencyCode();
361 if (!in_array($appBaseCurrencyCode, $allowedCurrencies)) {
362 $allowedCurrencies[] = $appBaseCurrencyCode;
364 foreach ($this->_storeManager->getStores() as
$store) {
366 if (!in_array(
$code, $allowedCurrencies)) {
367 $allowedCurrencies[] =
$code;
371 return $allowedCurrencies;
381 return $this->currencyConfig->getConfigCurrencies(self::XML_PATH_CURRENCY_DEFAULT);
389 return $this->currencyConfig->getConfigCurrencies(self::XML_PATH_CURRENCY_BASE);
402 $currency = $currency->getCode();
426 private function trimUnicodeDirectionMark($string)
428 if (preg_match(
'/^(\x{200E}|\x{200F})/u', $string, $match)) {
429 $string = preg_replace(
'/^'.$match[1].
'/u',
'', $string);
__construct(\Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, \Magento\Framework\Locale\FormatInterface $localeFormat, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Directory\Helper\Data $directoryHelper, \Magento\Directory\Model\Currency\FilterFactory $currencyFilterFactory, \Magento\Framework\Locale\CurrencyInterface $localeCurrency, \Magento\Framework\Model\ResourceModel\AbstractResource $resource=null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection=null, array $data=[], CurrencyConfig $currencyConfig=null)
setData($key, $value=null)
const XML_PATH_CURRENCY_DEFAULT
elseif(isset( $params[ 'redirect_parent']))
format($price, $options=[], $includeContainer=true, $addBrackets=false)
getConfigDefaultCurrencies()
const XML_PATH_CURRENCY_BASE
getCurrencyRates($currency, $toCurrencies=null)
formatPrecision( $price, $precision, $options=[], $includeContainer=true, $addBrackets=false)
getConfigAllowCurrencies()
getConfigBaseCurrencies()
const XML_PATH_CURRENCY_ALLOW
formatTxt($price, $options=[])
convert($price, $toCurrency=null)