Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Price division and a IF

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
B120
Smarty n00b


Joined: 24 Oct 2014
Posts: 2

PostPosted: Fri Oct 24, 2014 9:19 pm    Post subject: Price division and a IF Reply with quote

Hi,

I have this function that divides the price by 12:

Code:
{convertPrice price=$product.price/12}


But i need to add rule:
- If the price is less then 100 the dividing the value must be 6

I still very noob on this, please can someone teach me to add the rule to this function?

Thanks!

Best Regards,
Bruno
Back to top
View user's profile Send private message
B120
Smarty n00b


Joined: 24 Oct 2014
Posts: 2

PostPosted: Fri Oct 24, 2014 9:56 pm    Post subject: Reply with quote

I find it:

Code:
{if $productPrice >= 100}
{convertPrice price=$productPrice/12}
{else}
{convertPrice price=$productPrice/6}
{/if}   


This is the best approach? Can anyone share a definite way?

Best Regards
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Fri Nov 21, 2014 12:17 am    Post subject: Reply with quote

You should define all conversion logic inside your custom function.
Back to top
View user's profile Send private message
n0xor
Smarty Rookie


Joined: 04 Dec 2014
Posts: 6

PostPosted: Thu Dec 04, 2014 5:46 pm    Post subject: Reply with quote

Code:

{convertPrice price=$productPrice/(($productPrice<100)?6:12)}

Not tested but this provides much more readability
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP