Get the price whiout the currency


#1

Hello,

I would try to have the product’s price but just whitout the currency.
In twig I see for exemple {{ money.calculatePrice(product|sylius_resolve_variant) }} and on the page is displayed something like $10. I would like to add another variable that contains just 10.
How can I do that please ?

Thank you so much for your help.


#2

Hey, try using: {{ sylius_convert_money(variant|sylius_calculate_price({'channel': sylius.channel}), sylius.channel.baseCurrency.code, sylius.currencyCode) }}
You might want to put it in a Twig macro.
See SyliusShopBundle:Common/Macro:money.html.twig for details.


#3

Thank you so much for this answer !

I would like add this price in this file : vendor\sylius\sylius\src\Sylius\Bundle\ShopBundle\Resources\views\Product\Show_price.html.twig

And I don’t know how can I do it.
I have understand that I can use :

{{ productVariant|sylius_calculate_price({'channel': sylius.channel}) }}

But what is the productVariant ? How can I get it ?..

Thank you guys !


#4

Oh, in this file you will get the product variant from product|sylius_resolve_variant, so the complete answer is:

{% import "@SyliusShop/Common/Macro/money.html.twig" as money %}

<span class="ui huge header" id="product-price">
    {# get the product variant #}
    {% set variant = product|sylius_resolve_variant %}

    {# get the price for current channel #}
    {% set price = variant|sylius_calculate_price({'channel': sylius.channel}) %}

    {# convert the price to current currency #}
    {% set price = price|sylius_convert_money(sylius.channel.baseCurrency.code, sylius.currencyCode) %}

    {# price with currency #}
    {{ money.format(price, sylius.currencyCode) }}

    {# price without currency #}
    {{ price / 100 }}
</span>

I broke it in multiple lines with comments, so you can understand easier what’s happening.


#5

Perfect.

I will use this to try other things I need !

Thank you so much.