Getting the Proper PHP to work HELP!

I’m sure this is a simple one for you all, but since I am so new to PHP I have to at least ask.

I am trying to setup a condition where if an attribute = ‘YES’ then show an image. The attribute name is quickships and it needs to be saying ‘YES’ in order for it to show the image, if it says anything else, I just want it to do nothing.

This is what I have so far.

<?php if($_product->getQuickship == 1) { echo “YES”;} ?>
<img src=“/images/quickshipcorner.png” alt=“This item Ships within 1-3 Days!”>

** One thing to note, If I put in the <?php endif; ?> to close the statement, it kills my site.

Can someone help me out with this? Thanks in advance.


if($attribute == 'yes'){

echo'<img src="">';
}else{
//do nothing
}

Basically it should be
<?php if($_product->getQuickship == 1) { ?>
YES
<img src=“/images/quickshipcorner.png” alt=“This item Ships within 1-3 Days!”>
<?php } ?>
because curly brackets encloses statement

Bascially I tried it both of these ways…and neither is working, so not sure if its my code or if it is not recognizing the getQuickship attribute as saying YES. Is there a way to test this?

<?php if($_product->getQuickship == 1) { 
echo '<img src="/skin/frontend/default/maintheme/images/quickships-large.png" alt="This item Ships within 1-3 Days!" style="position:absolute; top:-350; right:0; z-index:0; border: 0;">';
}else{ } ?>  

and tried…

<?php if($_product->getQuickship == 1) { ?>
<img src="/skin/frontend/default/maintheme/images/quickships-large.png" alt="This item Ships within 1-3 Days!" style="position:absolute; top:-350; right:0; z-index:0; border: 0;">
<?php } ?>

<?php var_dimp($_product) ?>
will print out whole $_product object
as well as var_dimp($_product->getQuickship) will test getQuickship property

I tried this and it killed the site. This is a Magento cart and tends to be a pain in the butt with certain things. I just think maybe that attribute is not coming back as YES and the conditions arent working.

Would you happen to know what else I can try to get this thing working? Getting very frustrated over something that should be so easy to do.

<?php var_dimp($_product) ?>
<?php var_dimp($_product->getQuickship) ?>

getQuickship sounds like a method to me…

try:-


var_dump($_product->getQuickship());

:slight_smile:

it’s a typo. var_dump

Do you see any error messages then your site gets “killed”?

Okay, getting somewhere now…This command var_dump($_product->getQuickship()); returned a NULL. So that means it for whatever reason is not seeing the attribute quickship.

I noticed I left out a ‘s’ on quickships…so now it is returning
String(1) “1”

So now by using this information how would I make this image show if this condition is meet? I tried both ways and still the image is not showing, although now I think it recognizes it.

I’m a little confused, so I’m going to assume getQuickship() is a method a returns the string ‘1’.


<?php if('1' === $_product->getQuickship()): ?>
    <img src="" alt="" />
<?php endif; ?>

In fact, take your pick. :wink:


<?php if('1' === $_product->getQuickships()): ?>
    <img src="" alt="" />
<?php endif; ?>


<?php if('1' === $_product->getQuickship): ?>
    <img src="" alt="" />
<?php endif; ?>


<?php if('1' === $_product->getQuickships): ?>
    <img src="" alt="" />
<?php endif; ?>

Thanks Guys!!! You all are the bomb. I thought I would never get this thing working, but seems as if I’m on my way now! Thanks again!