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

Information on a particular "assign" example

 
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
maofree
Smarty Rookie


Joined: 28 Sep 2016
Posts: 5

PostPosted: Wed Sep 28, 2016 11:40 am    Post subject: Information on a particular "assign" example Reply with quote

Hi
on Prestashop cms in product.tpl there is a line
<span id="our_price_display" class="price" itemprop="price">{convertPrice price=$productPrice|floatval}</span>

the micordata value need an attribute "content" with the price with a comma and without the currency sign.

my solution is this and works

{assign var='maoProductPrice' value=Tools::ps_round(Tools::convertPrice($productPrice, $currency), $priceDisplayPrecision)}
<span id="our_price_display" class="price" itemprop="price" content="{$maoProductPrice|replace:'.':','}">{convertPrice price=$productPrice|floatval}</span>

I'm here to ask if there is a mode to assign {convertPrice price=$productPrice|floatval} to a variable to increase the performance of that page. in this mode I can remove from that variable the point replacing it with a comma

I want a solution like this but it is not correct
{assign var='maoProductPrice' value=(convertPrice price=$productPrice|floatval)}
because I get this error
Fatal error: Uncaught --> Smarty Compiler: Syntax error in template
Unexpected " price="

convertPrice is a Prestashop's method used sometimes in that file

is there a solution?

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


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Wed Sep 28, 2016 11:47 am    Post subject: Reply with quote

http://php.net/number_format
But a better solution would be to fix your misbehaving plugin to accept international number formats.
Back to top
View user's profile Send private message
maofree
Smarty Rookie


Joined: 28 Sep 2016
Posts: 5

PostPosted: Wed Sep 28, 2016 12:01 pm    Post subject: Reply with quote

{convertPrice price=$productPrice|floatval}
return a value like 33,45 €

I need only to remove the euro sign and the white space
I can edit only the tpl file not the php file of Prestashop's core
I can use the replace mode but from $price and not from the result of convertPrice
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Wed Sep 28, 2016 1:19 pm    Post subject: Reply with quote

maofree wrote:
{convertPrice price=$productPrice|floatval}
return a value like 33,45 €

I don't care what it returns. It's not relevant to your question.
Quote:
I need only to remove the euro sign and the white space
I can edit only the tpl file not the php file of Prestashop's core
I can use the replace mode but from $price and not from the result of convertPrice

Use number_format. In template. Yes.
{$productPrice|number_format:2:',':''}

*sigh*
Back to top
View user's profile Send private message
maofree
Smarty Rookie


Joined: 28 Sep 2016
Posts: 5

PostPosted: Wed Sep 28, 2016 1:36 pm    Post subject: Reply with quote

Hi
thanks for your help

number_format is nice but doesn't answer to my question.
I'm going to explain it in a different mode

I need to get 2 values 1 is with the currency sign and 1 is without
So I like to use only 1 formula to return the float value.

The problem is done from that {convertPrice price=$productPrice|floatval}
because I need that method to convert the price following the selected currency (it returns also the currency sign).

so I use this line to get that converted price without currency sign

{assign var='maoProductPrice' value=Tools::convertPrice($productPrice, $currency)}

{$maoProductPrice|number_format:$priceDisplayPrecision:',':''}

Tools::convertPrice returns a converted price without sign

This solution works but I use two times that function convertPrice
I need only to know if it is possible to assign to a variable this value

{convertPrice price=$productPrice|floatval}

I know how to assign a value like $productPrice

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


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Wed Sep 28, 2016 1:39 pm    Post subject: Reply with quote

maofree wrote:
I need to get 2 values
So I like to use only 1 formula

Read it again. And again. And again. Until you understand how ridiculous it sounds.
Back to top
View user's profile Send private message
maofree
Smarty Rookie


Joined: 28 Sep 2016
Posts: 5

PostPosted: Wed Sep 28, 2016 2:01 pm    Post subject: Reply with quote

for me not
if the price is the same like 33,55
I can use one formula to get it but for the current sign I need to use {convertPrice price=$productPrice|floatval}

However forget my example

the question is
is it possible to assign to a variable the value returned from {convertPrice price=$productPrice} ?

not from $productPrice because it can be different if the currency is not the default
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Wed Sep 28, 2016 6:02 pm    Post subject: Reply with quote

I noticed. But for anyone with understanding of basic algoritmization principles, that's a good joke. Or bad pun. But never an actual problem.
For some reason, you think that you need to do something, while in reality, you do not need that. But you cling to your stupid idea instead of leaving it behind.
Back to top
View user's profile Send private message
maofree
Smarty Rookie


Joined: 28 Sep 2016
Posts: 5

PostPosted: Wed Sep 28, 2016 6:14 pm    Post subject: Reply with quote

I know that there are other solutions to get what I need, but before to do that I would like to remove a doubt about the association because I don't know everything about smarty, so I did not believe that asking trivial things could create problems. I'm looking for an answer like yes or not, nothing else
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Thu Sep 29, 2016 12:47 am    Post subject: Reply with quote

"Did you stop beating your wife every morning?"
Answer "Yes" or "No", either will be wrong.
Same with your question. There's no yes or no answer, only "your question is wrong".
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