We'd like to support CryptoCurrencies like Bitcoin and Ether in our Shop. However, it seems that only Currencies are working correctly that are fully supported by Symfonies Intl-Class:
"The getName method uses Symfony鈥檚 Intl class to convert currency鈥檚 code into a human friendly form."
We tried to setup these currencies via SQL:
INSERT INTO `sylius_currency`(`id`,`code`,`created_at`,`updated_at`) VALUES ( '1', 'EUR', '2018-06-26 09:48:38', '2018-06-26 09:48:38' );
INSERT INTO `sylius_currency`(`id`,`code`,`created_at`,`updated_at`) VALUES ( '2', 'BTC', '2018-06-26 09:48:38', '2018-06-26 09:48:38' )
But getName() is delivering a blank string then and it looks strange (almost unusable) in the Admin-Panel:

In order to bring the huge world of CryptoCurrencies into Sylius, what would be the best approach? I could think of adding a concrete column "name" to the sylius_currency-table to make those currencies available.
What do you guys think? I'd like to submit a PR, but want to discuss with you the best approach. Maybe something else that i am not aware of :)
Extend Symfony\Component\Form\Extension\Core\Type\CurrencyType and add the cryptocurrencies to the result.
Decorate Sylius\Bundle\CurrencyBundle\Templating\Helper\CurrencyHelper to handle cryptocurrency symbols.
Override Sylius\Component\Currency\Model\Currency::getName to handle cryptocurrency names.
Override Sylius\Bundle\MoneyBundle\Formatter\MoneyFormatter to properly format cryptocurency amounts.
See this issue: #10204
See this code: https://gist.github.com/vvasiloi/5d8d5d8c88645b5f425553a3be9929a9
Also there is Sylius\Component\Currency\Converter\CurrencyNameConverter used for Behat/specs.
Thx, @vvasiloi.
For now i've ended up with overriding currency class to an own one which overrides getName() and adds some more columns to the sylius_currency-table.
config.yml:
sylius_currency:
resources:
currency:
classes:
model: AppBundle\Entity\Currency
Why do you suggest to overwrite CurrencyType as well?
@itinance It's used do add currencies from admin panel, but you can skip it probably.
But with my approach i run into another issue:
Return value of Sylius\Bundle\CurrencyBundle\Templating\Helper\CurrencyHelper::convertCurrencyCodeToSymbol() must be of the type string, null returned
It happens when i want to edit a product. Will look at it ...
@itinance I wrote about that in my first comment.
Can i override Sylius\Bundle\CurrencyBundle\Templating\Helper\CurrencyHelper the same way as overriding entities?
No. It's a Symfony DI service. I suggest you to decorate it.
https://symfony.com/doc/current/service_container/service_decoration.html
Many thanks!
This issue has been automatically marked as stale because it has not had any recent activity. It will be closed in a week if no further activity occurs. Thank you for your contributions.
Most helpful comment
No. It's a Symfony DI service. I suggest you to decorate it.
https://symfony.com/doc/current/service_container/service_decoration.html