Page 1 of 1
Simple PHP Help
Posted: Sun Jan 29, 2012 4:18 am
by markisonfire
This should be a pretty simple help request, I just can't seem to get it working. Basically, I want to lay an image over another image when $price is greater than a certain value. Here is my code:
Code: Select all
<?php if($price >= 150) { ?><div style="position: relative;"> <?php } ?>
and then, later...
Code: Select all
<?php if($price >= 150) {
?><img style="position: absolute; top: 0; right: 0; width: 340px; height: 340px;" src="/image/freeshippingoverlay.png" /></div><?php
} ?>
Now, I'm pretty sure the PHP syntax is correct, so what's the deal with $price? What's the correct way to handle this? I want it so that if the price of the product is greater than $150, it will show this code.
All help is greatly appreciated!
Thanks

Re: Simple PHP Help
Posted: Sun Jan 29, 2012 4:36 am
by victorj
You also need to adapt it to the apropriate tpl files to show it.
Very interesting are you sharing ?
Re: Simple PHP Help
Posted: Sun Jan 29, 2012 4:50 am
by markisonfire
victorj wrote:You also need to adapt it to the apropriate tpl files to show it.
Very interesting are you sharing ?
Well, actually, that's in the tpl file. I will definitely share once I get it working. I suppose I should place part of this in the controller file and then call it as a variable. I'll try that and see what happens.
Re: Simple PHP Help
Posted: Sun Jan 29, 2012 5:21 am
by victorj
i know that for the product page there are 3 files working togeter
catalog/controler/product/product.php
catalog/model/catalog/product.php
catalog/view/yourtheme/template/product/product.tpl
when adding functionality all 3 files are involved
thwe php goes into the php files and they command the template file
Re: Simple PHP Help
Posted: Sun Jan 29, 2012 6:04 am
by Qphoria
markisonfire wrote:This should be a pretty simple help request, I just can't seem to get it working. Basically, I want to lay an image over another image when $price is greater than a certain value. Here is my code:
Code: Select all
<?php if($price >= 150) { ?><div style="position: relative;"> <?php } ?>
"$price" is a formated string value, not a number
Try ($product_info['price'] > 150) as that is the unformatted price
Re: Simple PHP Help
Posted: Sun Jan 29, 2012 6:18 am
by markisonfire
Qphoria wrote:markisonfire wrote:This should be a pretty simple help request, I just can't seem to get it working. Basically, I want to lay an image over another image when $price is greater than a certain value. Here is my code:
Code: Select all
<?php if($price >= 150) { ?><div style="position: relative;"> <?php } ?>
"$price" is a formated string value, not a number
Try ($product_info['price'] > 150) as that is the unformatted price
That's the stuff, right there. A question about MVC for you, then, Mr. Q. Should this be in the controller file? What would the best practice be for something like this? Should I place this in the controller and then call it with a variable in the view tpl file?
[edit] And while we're at it, what would I call if I wanted to have this happen in, say, featured_content.tpl? $product_info['price'] returns a nasty little error. [/edit]
The code you posted works, by the way. I assumed that $price wasn't a numerical value, I just wasn't too sure what to do. Thanks!