Skip to content

Commit

Permalink
Add "allow_empty" option to price formatter.
Browse files Browse the repository at this point in the history
  • Loading branch information
Igor Nikolaev committed Apr 13, 2021
1 parent ca830cd commit d03c4eb
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,5 @@
7.4.2: Extension configurator: allow multiple configs for same extension.

7.4.5: Pass prise as pluralization parameter.

7.4.7: Add "allow_empty" option to price formatter.
3 changes: 3 additions & 0 deletions Price/PriceFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ public function __construct(ServiceProviderInterface $twigProvider)
*/
public function format($price, array $options = []): string
{
if (!isset($options['allow_empty'])) {
$options['allow_empty'] = false;
}
if (!isset($options['format'])) {
$options['format'] = 'default';
}
Expand Down
2 changes: 1 addition & 1 deletion Resources/views/price.html.twig
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% if price > 0 %}
{% if price > 0 or options.allow_empty %}
{{ ('price.value.' ~ options.format)|trans({'%price%': price|number_format(0, null, options.thousands_separator), '%count%': price|number_format(0, '', '')})|raw }}
{% else %}
{{ ('price.empty.' ~ options.empty_format)|trans|raw }}
Expand Down

0 comments on commit d03c4eb

Please sign in to comment.