Jump to content

Negative Prices being displayed


Recommended Posts

Hi all,

Hopefully someone has encountered his before

I am using a custom product page and template, I am succesfully retrieving all the product and pricing information however have a glitch for prices of -1

Some products have recurring costs monthly or annually and others annually or triennially

Displaying all the price options on the product details page works with the biiling cycle which isnt available returing the value in the DB which is -1

The problem is that I obviously dont wnt the unsupported billing cycle and -1 value rendered on the page so used if statements in the template but whatever I do the match/doesn't match criteria doesnt appear to work

I am using the following in the PHP page to get the data 

$getproduct_price = Capsule::table('tblpricing')->where('type','product')->where('relid',$pid)->where('currency',$currencyId)->first();
$monthlyprice = formatCurrency($getproduct_price->monthly, $currencyId);
$annuallyprice = formatCurrency($getproduct_price->annually, $currencyId);
$trienniallyprice = formatCurrency($getproduct_price->triennially, $currencyId);

and the following in the template 

		{if ($monthlyprice > '0')}
			<span class="price">{$monthlyprice}</span> {$LANG.orderpaymenttermmonthly} {$LANG.truffiere.VatOnOff}<br>
		{/if}
		{if ($annuallyprice > '0')}
			<span class="price">{$annuallyprice}</span> {$LANG.orderpaymenttermannually} {$LANG.truffiere.VatOnOff}<br>
		{/if}
		{if ($trienniallyprice > '0')}
			<span class="price">{$trienniallyprice}</span> {$LANG.truffiere.orderpaymentterm.Triennially} {$LANG.truffiere.VatOnOff}<br>
		{/if}

I have tried numerous varations ie for both match or doesnt match the criteria such as

< '0'
!> '0' and 
= '-1'

 But none of them seem to work against the negative value

Any ideas or particularly soutions gratefully accepted!

Edited by MrGettingRatherFrustrated
Link to comment
Share on other sites

30 minutes ago, MrGettingRatherFrustrated said:

Any ideas or particularly solutions gratefully accepted!

if I leave the sanctity of my self-imposed mute voyeur mode for just a second, you're going to be hitting three problems.

  1. by the time $monthlyprice is accessed by the conditional code in the if statement, it's going to be have been price formatted, e.g it's not going to be -1, it's going to be £-1.00 or €-1.00 etc.
  2. if $monthlyprice is price formatted, then you should be able to do {if ($monthlyprice->toNumeric() != '-1.00')} in your conditional statement.
  3. what I would do is to only create $monthlyprice if $getproduct_price->monthly is not -1, e.g you move the conditional logic to the php and then, in the template, all you have to check is whether $monthlyprice exists and if so, output accordingly... and so on with the other two pricing options.

and with that, I return the gaffer tape over my mouth. 🤐🙂

Link to comment
Share on other sites

1 hour ago, brian! said:

if I leave the sanctity of my self-imposed mute voyeur mode for just a second, you're going to be hitting three problems.

  1. by the time $monthlyprice is accessed by the conditional code in the if statement, it's going to be have been price formatted, e.g it's not going to be -1, it's going to be £-1.00 or €-1.00 etc.
  2. if $monthlyprice is price formatted, then you should be able to do {if ($monthlyprice->toNumeric() != '-1.00')} in your conditional statement.
  3. what I would do is to only create $monthlyprice if $getproduct_price->monthly is not -1, e.g you move the conditional logic to the php and then, in the template, all you have to check is whether $monthlyprice exists and if so, output accordingly... and so on with the other two pricing options.

and with that, I return the gaffer tape over my mouth. 🤐🙂

As always Brian thank you

You are quite correct and using toNumeric as you showed above gives the desired result

I have changed in the template for now to achieve the desired result but will take your advice and refine the  PHP and template

Once more - 

hats off.gif

Link to comment
Share on other sites

  • 2 weeks later...
On 14/07/2021 at 14:09, bear said:

Need to check my knots, since you were able to get your hands free....:P

the hands were not the problem... I suspect my ankles will never be the same again! 😱🔨

97OT4bd.gif

i've only come back today cos I got sent a PM that needs replying to. 🤐

while i'm here, i'll briefly reply to a few unanswered threads, but I doubt i'll login again this month.... i'm really enjoying no longer receiving/reading the threads emails (or even launching / thinking about WHMCS any more!)  and getting on with more important things. 🏖️🍦

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • 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