-
Notifications
You must be signed in to change notification settings - Fork 9.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Question] How to get the currency code and symbol of an AbstractPrice? #941
Comments
hey @Vinai, sure generally we agree :) Changes required:
Is this sound like a good high level plan? |
Good plan :) But your reply brings up another question, if you don't mind me asking. Generally I thin it might be problematic to expose methods that are not part of the interface. |
Good question. |
Related ticket has been added to the backlog (MAGETWO-32756). |
Thanks! |
I want currency Symbol using currency code in magento 2. so any one help me? |
During website implementations I often had to access currency information like the currency symbol of a price (e.g. for custom API resources, or when rendering a price on a graphical banner).
For that purpose the currency information for a given AbstractPrice instance should be made accessable for the current locale.
Currently this information is hidden 4 levels away:
Pricing\Price\AbstractPrice
has a privateMagento\Directory\Model\PriceCurrency
PriceCurrency
gives access toMagento\Directory\Model\Currency
via the publicgetCurrency()
Currency
has a privateMagento\Framework\Locale\Currency
Locale\Currency
uses aCurrencyFactory
to instantiate aMagento\Framework\Currency
which is exposed viagetCurrency()
but requires a currency code as an argument.Magento\Framework\Currency
finally extendsZend_Currency
and thus implementsgetSymbol()
Is there already a good way to access that information, for example in a price template?
If not, I think the cleanest way to access the data would be via getter methods on the
AbstractPrice
instances.Ideally a method
getCurrencySymbol
would be added to theMagento\Framework\Pricing\Price\PriceInterface
and implemented inAbstractPrice
.Would that be something you generally agree with?
The text was updated successfully, but these errors were encountered: