H,
I am trying to modify the price display such that if the price is 0, it will display FREE instead of the value. I have tried this in category.tpl
<?php if ($display_price) { ?>
<?php ?>
<?php if (!$products[$j]['special']) {
$pricee = $products[$j]['price']; if(strcmp($pricee, "0.00€" ) == 0) {echo "succ";}
?>
But it doesn't seem to work and print nothing. I did a gettype check and it returned string so i am doing a string comparison.
Please help.
I know php and you should know that the function strcmp has a better chance and provide more details about the string comparison such if strings matched, greater than or less than. I tried it first before using strcmp. It seems like the price is something else, the trouble is echoing it prints the price+currency and comparing to that doesn't work.
Thanks anyway
Thanks anyway
hawkagent's method won't work because price is a string with the currency symbol on it.
STN, your sample code is missing the closing } so it's probably worth checking your real code for little errors like that. If not, there are tons of ways to do this. I'd consider using if/then shorthand and going with something like:
EDIT: The old code broke on some prices. This is a better solution:
STN, your sample code is missing the closing } so it's probably worth checking your real code for little errors like that. If not, there are tons of ways to do this. I'd consider using if/then shorthand and going with something like:
EDIT: The old code broke on some prices. This is a better solution:
Code: Select all
echo ((preg_replace('/[^0-9\.]/', '', $products[$j]['price']) == '0.00') ? 'Free' : $products[$j]['price']);
Last edited by rph on Mon Oct 24, 2011 1:26 am, edited 4 times in total.
-Ryan
Thanks for the reply rph, it works for dollars and euro currency. However, with pound sterling, i couldn't get it to work (i just couldn't think how). Instead i have used this code and it works perfect for values even as low as 0.10. Here's the code
Anyone feel free to use and abuse.
[RESOLVED]
Code: Select all
<?php if (!$products[$j]['special']) {
?>
<span style="color: #900; font-weight: bold;"><?php
$pricee =substr($products[$j]['price'], 0, 5); $poss = strpos($pricee, '0.0');
if (($poss === 0) || ($poss === 1) || ($poss === 2) ) { echo 'FREE'; }
else { echo $products[$j]['price']; }?></span>
<?php } else { ?>
[RESOLVED]
Boy, you're really taking the long way around there.
The old code I posted broke in some places so I updated it. At any rate, this is really the sort of thing that should be done on the controller level before the values get formatted.
The old code I posted broke in some places so I updated it. At any rate, this is really the sort of thing that should be done on the controller level before the values get formatted.
-Ryan
hey, i am not claiming its the best solution. I am a pretty bad coder as in writing efficient code but i get the job done somehow hehe.
I will use your code since its just one line. Thanks
I will use your code since its just one line. Thanks
I'm not criticizing. Shorter code is usually just easier to work with and faster to execute. I think the real issue is low cost items (< 0.10€) would be listed as free but then the code I originally posted was badly bugged for right-side currency symbols and would have resulted in anything ending in 0.00 (e.g. 10.00€) being marked as free.
-Ryan
Yeah, that won't matter though as there are not going to be any items < 0.10€, they would rather be free if priced so low.
Hey,
I have somewhat of a similar query, if I have a special price applied to a product, it displays 2 separate prices:
ie:
Main Price: €150
Special Price: <del>€150</del> €75
my problem is that if a special price is applied to a product, I need it to overwrite the "Main Price".
my current php is as follows:
<div class="right">
<div id="price-bg">
<?php echo $text_price; ?><br />
<?php echo $price; ?>
</div>
i'm guessing there needs to be an else function in there somewhere, but for the life of me, cannot get right!
<div id="price-bg">
<?php echo $text_price; ?><br />
<?php echo $price; ?>
<?php if (!$special) { ?>
<!--<?php echo $price; ?>-->
<?php } else { ?>
<span class="price-new"><?php echo $special; ?></span>
<?php } ?>
however the above shows both prices in the Main Price section, I only need it to show the Special Price if a special price applies, and not remove or hide the price of products that do not have a special price applied! I hope all this made sense!
Cheers for looking!
RT
I have somewhat of a similar query, if I have a special price applied to a product, it displays 2 separate prices:
ie:
Main Price: €150
Special Price: <del>€150</del> €75
my problem is that if a special price is applied to a product, I need it to overwrite the "Main Price".
my current php is as follows:
<div class="right">
<div id="price-bg">
<?php echo $text_price; ?><br />
<?php echo $price; ?>
</div>
i'm guessing there needs to be an else function in there somewhere, but for the life of me, cannot get right!
<div id="price-bg">
<?php echo $text_price; ?><br />
<?php echo $price; ?>
<?php if (!$special) { ?>
<!--<?php echo $price; ?>-->
<?php } else { ?>
<span class="price-new"><?php echo $special; ?></span>
<?php } ?>
however the above shows both prices in the Main Price section, I only need it to show the Special Price if a special price applies, and not remove or hide the price of products that do not have a special price applied! I hope all this made sense!
Cheers for looking!
RT
Code: Select all
not to worry got it sorted, just needed a bit of common sense in relation to the coding, this is what i used.
in catalog/view/theme/Your Theme/template/product/product.tpl
find line 26:
<?php echo $text_price; ?><br />
<?php echo $price; ?>
replace with:
<?php echo $text_price; ?><br />
<?php if (!$special) { ?>
<?php echo $price; ?>
<?php } else { ?>
<span class="price-new"><?php echo $special; ?></span>
<?php } ?>
works a treat.
in catalog/view/theme/Your Theme/template/product/product.tpl
find line 26:
<?php echo $text_price; ?><br />
<?php echo $price; ?>
replace with:
<?php echo $text_price; ?><br />
<?php if (!$special) { ?>
<?php echo $price; ?>
<?php } else { ?>
<span class="price-new"><?php echo $special; ?></span>
<?php } ?>
works a treat.
Who is online
Users browsing this forum: No registered users and 97 guests