Jump to content

Price formatter breaks the page


Recommended Posts

Hello,

My goal is to render price in the following format:

5.95

NOT

$5.95

Using the source information from https://docs.whmcs.com/classes/7.1/WHMCS/View/Formatter/Price.html and https://blog.whmcs.com/132057/customise-price-formatting-with-the-price-formatter, I'm trying to remove the prefix currency sign. In other words, I just want a numeric output. So, I'm using this in viewinvoice.tpl file:

 

{$total->toNumeric()}

 

But the page just goes white when trying to load. I've enabled error log but no output shows.

Can someone shed some light over this?

Thanks in advance!

 

Edited by onliner
Link to comment
Share on other sites

Just a question regarding the prefix and suffix thing.

Is there a way to just extract, or show, the currency sign, or prefix & suffix without the numeric price itself?

Example: 

USD

NOT

15.95 USD

I know it sounds strange, but I need such output for a thing.

Any help... 

 

 

Link to comment
Share on other sites

if you want to do it using the price formatter, to get the suffix alone...

{$total|replace:$total->toPrefixed():''}

or to get the prefix...

{$total|replace:$total->toSuffixed():''}

if you're on other pages, the $currency array might be available.... and certainly if the client is logged in, you will know their currency and so you could query the db for the prefix/suffix in a hook.

Link to comment
Share on other sites

On 2018-03-10 at 12:09 PM, brian! said:

if you have to, you could always use...


{$total|replace:'$':''}

 

1) Now, I'm in trouble, because I need to replace BOTH prefix AND suffix and just to render the numeric value. Several currencies and prefixes & suffixes. The good thing is that I know what I want to replace: Prefix '$' and '€'. Suffixes 'USD' and 'EUR.

The result:

15.95

NOT

$15.95 USD

2) At one spot I just need to render suffixes, without numerical values and without the prefixes.

The result:

EUR

NOT

€15.95 EUR

Any idea? Thanks in advance.

Link to comment
Share on other sites

45 minutes ago, onliner said:

Any idea? Thanks in advance.

well using toNumeric() would be the simplest way, but if that's not working and you know what you want to replace...

{$total|replace:'$':''|replace:'€':''|replace:'USD':''|replace:'EUR':''}

 

Link to comment
Share on other sites

1 hour ago, brian! said:

well using toNumeric() would be the simplest way

That's the problem, when using

{$total|replace:$total->toNumeric():''}

then nothing happens. The price is rendered both with prefix and suffix.

Not sure why 'toNumeric' doesn't work!?

Link to comment
Share on other sites

3 hours ago, onliner said:

The price is rendered both with prefix and suffix.

Not sure why 'toNumeric' doesn't work!?

my thought is there may be a corrupt/missing file somewhere as to why this isn't working... i'm assuming that you've added a debug to viewinvoice.tpl and checked $total is a price formatted variable ? i'm sure it should be.

I seemingly don't have any invoices on my v7.1.2 dev, but the above code worked on v7.4.2 and v7.2.3 and I don't recall anything in the changelog saying price formatting was bugged in v7.1...

PAEdsjD.png

you could try manually uploading the files from the full download version of your installed release and hoping that fixes it... otherwise, wait until you next upgrade.

if you're going to do a lot of manipulating of these price formatting variables, then it's going to be easier if you can get toNumeric() working... yes you can code around without it if you have to, but would be simpler if you had it working.

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated